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.cpy.inl 812 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535
  1. // clang-format off
  2. template<> struct EnumTrait<AdaptivePooling::Mode> {
  3. static constexpr const char *name = "AdaptivePooling.Mode";
  4. static constexpr std::underlying_type_t<AdaptivePooling::Mode> max = 3 - 1;
  5. };
  6. template<> PyTypeObject* EnumWrapper<AdaptivePooling::Mode>::type = nullptr;
  7. template<> const char*
  8. EnumWrapper<AdaptivePooling::Mode>::members[] = {"MAX", "AVERAGE", "AVERAGE_COUNT_EXCLUDE_PADDING"};
  9. template<> std::unordered_map<std::string, AdaptivePooling::Mode>
  10. EnumWrapper<AdaptivePooling::Mode>::mem2value = {{normalize_enum("MAX"), AdaptivePooling::Mode::MAX}, {normalize_enum("AVERAGE"), AdaptivePooling::Mode::AVERAGE}, {normalize_enum("AVERAGE_COUNT_EXCLUDE_PADDING"), AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING}};
  11. template<> PyObject* EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[3] = {nullptr};
  12. void _init_py_AdaptivePooling_Mode(PyTypeObject& py_type) {
  13. auto& e_type = EnumWrapper<AdaptivePooling::Mode>::type;
  14. static PyMethodDef tp_methods[] = {
  15. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<AdaptivePooling::Mode>::py_dump, METH_NOARGS, NULL},
  16. {NULL} /* Sentinel */
  17. };
  18. static PyType_Slot slots[] = {
  19. {Py_tp_repr, (void*)EnumWrapper<AdaptivePooling::Mode>::py_repr},
  20. {Py_tp_richcompare, (void*)EnumWrapper<AdaptivePooling::Mode>::tp_richcompare},
  21. {Py_tp_methods, tp_methods},
  22. {0, NULL}
  23. };
  24. static PyType_Spec spec = {
  25. // name
  26. "megengine.core._imperative_rt.ops.AdaptivePooling.Mode",
  27. // basicsize
  28. sizeof(EnumWrapper<AdaptivePooling::Mode>),
  29. // itemsize
  30. 0,
  31. // flags
  32. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  33. // slots
  34. slots
  35. };
  36. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  37. mgb_assert(
  38. e_type->tp_setattro(
  39. reinterpret_cast<PyObject*>(e_type),
  40. py::cast("__name__").release().ptr(),
  41. py::cast("Mode").release().ptr()) >= 0);
  42. mgb_assert(
  43. e_type->tp_setattro(
  44. reinterpret_cast<PyObject*>(e_type),
  45. py::cast("__module__").release().ptr(),
  46. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  47. mgb_assert(
  48. e_type->tp_setattro(
  49. reinterpret_cast<PyObject*>(e_type),
  50. py::cast("__qualname__").release().ptr(),
  51. py::cast("AdaptivePooling.Mode").release().ptr()) >= 0);
  52. {
  53. PyObject* inst = e_type->tp_alloc(e_type, 0);
  54. reinterpret_cast<EnumWrapper<AdaptivePooling::Mode>*>(inst)->value = AdaptivePooling::Mode::MAX;
  55. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  56. EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[0] = inst;
  57. }{
  58. PyObject* inst = e_type->tp_alloc(e_type, 0);
  59. reinterpret_cast<EnumWrapper<AdaptivePooling::Mode>*>(inst)->value = AdaptivePooling::Mode::AVERAGE;
  60. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  61. EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[1] = inst;
  62. }{
  63. PyObject* inst = e_type->tp_alloc(e_type, 0);
  64. reinterpret_cast<EnumWrapper<AdaptivePooling::Mode>*>(inst)->value = AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING;
  65. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE_COUNT_EXCLUDE_PADDING", inst) >= 0);
  66. EnumWrapper<AdaptivePooling::Mode>::pyobj_insts[2] = inst;
  67. }
  68. Py_INCREF(e_type);
  69. mgb_assert(PyDict_SetItemString(
  70. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  71. }
  72. template<> struct EnumTrait<AdaptivePooling::Format> {
  73. static constexpr const char *name = "AdaptivePooling.Format";
  74. static constexpr std::underlying_type_t<AdaptivePooling::Format> max = 18 - 1;
  75. };
  76. template<> PyTypeObject* EnumWrapper<AdaptivePooling::Format>::type = nullptr;
  77. template<> const char*
  78. EnumWrapper<AdaptivePooling::Format>::members[] = {"NCHW", "NHWC", "NHWCD4", "NCHW4", "NCHW8", "NCHW32", "NCHW88", "NCHW44", "NCHW44_DOT", "NCHW4_NCHW32", "NCHW32_NCHW4", "NCHW4_NCHW", "NHWC_NCHW", "NHWC_NCHW4_IC_SMALL", "NCHW_NCHW4_IC_SMALL", "CHWN4", "NCHW64", "NCHW4_NHWC"};
  79. template<> std::unordered_map<std::string, AdaptivePooling::Format>
  80. EnumWrapper<AdaptivePooling::Format>::mem2value = {{normalize_enum("NCHW"), AdaptivePooling::Format::NCHW}, {normalize_enum("NHWC"), AdaptivePooling::Format::NHWC}, {normalize_enum("NHWCD4"), AdaptivePooling::Format::NHWCD4}, {normalize_enum("NCHW4"), AdaptivePooling::Format::NCHW4}, {normalize_enum("NCHW8"), AdaptivePooling::Format::NCHW8}, {normalize_enum("NCHW32"), AdaptivePooling::Format::NCHW32}, {normalize_enum("NCHW88"), AdaptivePooling::Format::NCHW88}, {normalize_enum("NCHW44"), AdaptivePooling::Format::NCHW44}, {normalize_enum("NCHW44_DOT"), AdaptivePooling::Format::NCHW44_DOT}, {normalize_enum("NCHW4_NCHW32"), AdaptivePooling::Format::NCHW4_NCHW32}, {normalize_enum("NCHW32_NCHW4"), AdaptivePooling::Format::NCHW32_NCHW4}, {normalize_enum("NCHW4_NCHW"), AdaptivePooling::Format::NCHW4_NCHW}, {normalize_enum("NHWC_NCHW"), AdaptivePooling::Format::NHWC_NCHW}, {normalize_enum("NHWC_NCHW4_IC_SMALL"), AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL}, {normalize_enum("NCHW_NCHW4_IC_SMALL"), AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL}, {normalize_enum("CHWN4"), AdaptivePooling::Format::CHWN4}, {normalize_enum("NCHW64"), AdaptivePooling::Format::NCHW64}, {normalize_enum("NCHW4_NHWC"), AdaptivePooling::Format::NCHW4_NHWC}};
  81. template<> PyObject* EnumWrapper<AdaptivePooling::Format>::pyobj_insts[18] = {nullptr};
  82. void _init_py_AdaptivePooling_Format(PyTypeObject& py_type) {
  83. auto& e_type = EnumWrapper<AdaptivePooling::Format>::type;
  84. static PyMethodDef tp_methods[] = {
  85. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<AdaptivePooling::Format>::py_dump, METH_NOARGS, NULL},
  86. {NULL} /* Sentinel */
  87. };
  88. static PyType_Slot slots[] = {
  89. {Py_tp_repr, (void*)EnumWrapper<AdaptivePooling::Format>::py_repr},
  90. {Py_tp_richcompare, (void*)EnumWrapper<AdaptivePooling::Format>::tp_richcompare},
  91. {Py_tp_methods, tp_methods},
  92. {0, NULL}
  93. };
  94. static PyType_Spec spec = {
  95. // name
  96. "megengine.core._imperative_rt.ops.AdaptivePooling.Format",
  97. // basicsize
  98. sizeof(EnumWrapper<AdaptivePooling::Format>),
  99. // itemsize
  100. 0,
  101. // flags
  102. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  103. // slots
  104. slots
  105. };
  106. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  107. mgb_assert(
  108. e_type->tp_setattro(
  109. reinterpret_cast<PyObject*>(e_type),
  110. py::cast("__name__").release().ptr(),
  111. py::cast("Format").release().ptr()) >= 0);
  112. mgb_assert(
  113. e_type->tp_setattro(
  114. reinterpret_cast<PyObject*>(e_type),
  115. py::cast("__module__").release().ptr(),
  116. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  117. mgb_assert(
  118. e_type->tp_setattro(
  119. reinterpret_cast<PyObject*>(e_type),
  120. py::cast("__qualname__").release().ptr(),
  121. py::cast("AdaptivePooling.Format").release().ptr()) >= 0);
  122. {
  123. PyObject* inst = e_type->tp_alloc(e_type, 0);
  124. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW;
  125. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW", inst) >= 0);
  126. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[0] = inst;
  127. }{
  128. PyObject* inst = e_type->tp_alloc(e_type, 0);
  129. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWC;
  130. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC", inst) >= 0);
  131. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[1] = inst;
  132. }{
  133. PyObject* inst = e_type->tp_alloc(e_type, 0);
  134. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWCD4;
  135. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWCD4", inst) >= 0);
  136. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[2] = inst;
  137. }{
  138. PyObject* inst = e_type->tp_alloc(e_type, 0);
  139. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4;
  140. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4", inst) >= 0);
  141. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[3] = inst;
  142. }{
  143. PyObject* inst = e_type->tp_alloc(e_type, 0);
  144. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW8;
  145. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW8", inst) >= 0);
  146. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[4] = inst;
  147. }{
  148. PyObject* inst = e_type->tp_alloc(e_type, 0);
  149. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW32;
  150. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32", inst) >= 0);
  151. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[5] = inst;
  152. }{
  153. PyObject* inst = e_type->tp_alloc(e_type, 0);
  154. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW88;
  155. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88", inst) >= 0);
  156. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[6] = inst;
  157. }{
  158. PyObject* inst = e_type->tp_alloc(e_type, 0);
  159. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW44;
  160. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44", inst) >= 0);
  161. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[7] = inst;
  162. }{
  163. PyObject* inst = e_type->tp_alloc(e_type, 0);
  164. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW44_DOT;
  165. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_DOT", inst) >= 0);
  166. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[8] = inst;
  167. }{
  168. PyObject* inst = e_type->tp_alloc(e_type, 0);
  169. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4_NCHW32;
  170. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW32", inst) >= 0);
  171. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[9] = inst;
  172. }{
  173. PyObject* inst = e_type->tp_alloc(e_type, 0);
  174. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW32_NCHW4;
  175. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32_NCHW4", inst) >= 0);
  176. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[10] = inst;
  177. }{
  178. PyObject* inst = e_type->tp_alloc(e_type, 0);
  179. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4_NCHW;
  180. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW", inst) >= 0);
  181. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[11] = inst;
  182. }{
  183. PyObject* inst = e_type->tp_alloc(e_type, 0);
  184. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWC_NCHW;
  185. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW", inst) >= 0);
  186. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[12] = inst;
  187. }{
  188. PyObject* inst = e_type->tp_alloc(e_type, 0);
  189. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL;
  190. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW4_IC_SMALL", inst) >= 0);
  191. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[13] = inst;
  192. }{
  193. PyObject* inst = e_type->tp_alloc(e_type, 0);
  194. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL;
  195. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_NCHW4_IC_SMALL", inst) >= 0);
  196. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[14] = inst;
  197. }{
  198. PyObject* inst = e_type->tp_alloc(e_type, 0);
  199. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::CHWN4;
  200. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CHWN4", inst) >= 0);
  201. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[15] = inst;
  202. }{
  203. PyObject* inst = e_type->tp_alloc(e_type, 0);
  204. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW64;
  205. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW64", inst) >= 0);
  206. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[16] = inst;
  207. }{
  208. PyObject* inst = e_type->tp_alloc(e_type, 0);
  209. reinterpret_cast<EnumWrapper<AdaptivePooling::Format>*>(inst)->value = AdaptivePooling::Format::NCHW4_NHWC;
  210. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NHWC", inst) >= 0);
  211. EnumWrapper<AdaptivePooling::Format>::pyobj_insts[17] = inst;
  212. }
  213. Py_INCREF(e_type);
  214. mgb_assert(PyDict_SetItemString(
  215. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  216. }
  217. PyOpDefBegin(AdaptivePooling) // {
  218. static PyGetSetDef py_getsetters[];
  219. static PyMethodDef tp_methods[];
  220. static PyObject* getstate(PyObject* self, PyObject*) {
  221. auto& opdef = reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst();
  222. static_cast<void>(opdef);
  223. std::unordered_map<std::string, py::object> state {
  224. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  225. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  226. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)}
  227. };
  228. return py::cast(state).release().ptr();
  229. }
  230. static PyObject* setstate(PyObject* self, PyObject* args) {
  231. PyObject* dict = PyTuple_GetItem(args, 0);
  232. if (!dict) return NULL;
  233. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  234. auto& opdef = reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst();
  235. static_cast<void>(opdef);
  236. {
  237. auto&& iter = state.find("mode");
  238. if (iter != state.end()) {
  239. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  240. }
  241. }
  242. {
  243. auto&& iter = state.find("format");
  244. if (iter != state.end()) {
  245. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  246. }
  247. }
  248. {
  249. auto&& iter = state.find("shape");
  250. if (iter != state.end()) {
  251. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  252. }
  253. }
  254. Py_RETURN_NONE;
  255. }
  256. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  257. // };
  258. PyOpDefEnd(AdaptivePooling)
  259. int PyOp(AdaptivePooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  260. static const char* kwlist[] = {"mode", "format", "shape", "scope", NULL};
  261. PyObject *mode = NULL, *format = NULL, *shape = NULL, *scope = NULL;
  262. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &mode, &format, &shape, &scope))
  263. return -1;
  264. if (mode) {
  265. try {
  266. // TODO: remove this guard which is used for pybind11 implicit conversion
  267. py::detail::loader_life_support guard{};
  268. reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst().mode =
  269. py::cast<decltype(AdaptivePooling::mode)>(py::handle(mode));
  270. } CATCH_ALL(-1)
  271. }
  272. if (format) {
  273. try {
  274. // TODO: remove this guard which is used for pybind11 implicit conversion
  275. py::detail::loader_life_support guard{};
  276. reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst().format =
  277. py::cast<decltype(AdaptivePooling::format)>(py::handle(format));
  278. } CATCH_ALL(-1)
  279. }
  280. if (shape) {
  281. try {
  282. // TODO: remove this guard which is used for pybind11 implicit conversion
  283. py::detail::loader_life_support guard{};
  284. reinterpret_cast<PyOp(AdaptivePooling)*>(self)->inst().shape =
  285. py::cast<decltype(AdaptivePooling::shape)>(py::handle(shape));
  286. } CATCH_ALL(-1)
  287. }
  288. if (scope) {
  289. try {
  290. reinterpret_cast<PyOp(OpDef)*>(self)->op
  291. ->set_scope(py::cast<std::string>(py::handle(scope)));
  292. } CATCH_ALL(-1)
  293. }
  294. return 0;
  295. }
  296. PyGetSetDef PyOp(AdaptivePooling)::py_getsetters[] = {
  297. {const_cast<char*>("mode"), py_get_generic(AdaptivePooling, mode), py_set_generic(AdaptivePooling, mode), const_cast<char*>("mode"), NULL},
  298. {const_cast<char*>("format"), py_get_generic(AdaptivePooling, format), py_set_generic(AdaptivePooling, format), const_cast<char*>("format"), NULL},
  299. {const_cast<char*>("shape"), py_get_generic(AdaptivePooling, shape), py_set_generic(AdaptivePooling, shape), const_cast<char*>("shape"), NULL},
  300. {NULL} /* Sentinel */
  301. };
  302. PyMethodDef PyOp(AdaptivePooling)::tp_methods[] = {
  303. {const_cast<char*>("__getstate__"), PyOp(AdaptivePooling)::getstate, METH_NOARGS, "AdaptivePooling getstate"},
  304. {const_cast<char*>("__setstate__"), PyOp(AdaptivePooling)::setstate, METH_VARARGS, "AdaptivePooling setstate"},
  305. {NULL} /* Sentinel */
  306. };
  307. void _init_py_AdaptivePooling(py::module m) {
  308. using py_op = PyOp(AdaptivePooling);
  309. auto& py_type = PyOpType(AdaptivePooling);
  310. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  311. py_type.tp_name = "megengine.core._imperative_rt.ops.AdaptivePooling";
  312. py_type.tp_basicsize = sizeof(PyOp(AdaptivePooling));
  313. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  314. py_type.tp_doc = "AdaptivePooling";
  315. py_type.tp_base = &PyOpType(OpDef);
  316. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  317. py_type.tp_new = py_new_generic<py_op>;
  318. py_type.tp_init = py_op::py_init;
  319. py_type.tp_methods = py_op::tp_methods;
  320. py_type.tp_getset = py_op::py_getsetters;
  321. mgb_assert(PyType_Ready(&py_type) >= 0);
  322. _init_py_AdaptivePooling_Mode(py_type);
  323. _init_py_AdaptivePooling_Format(py_type);
  324. PyType_Modified(&py_type);
  325. m.add_object("AdaptivePooling", reinterpret_cast<PyObject*>(&py_type));
  326. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AdaptivePooling::typeinfo(), &py_type).second);
  327. }
  328. PyOpDefBegin(AddAxis) // {
  329. static PyGetSetDef py_getsetters[];
  330. static PyMethodDef tp_methods[];
  331. static PyObject* getstate(PyObject* self, PyObject*) {
  332. auto& opdef = reinterpret_cast<PyOp(AddAxis)*>(self)->inst();
  333. static_cast<void>(opdef);
  334. std::unordered_map<std::string, py::object> state {
  335. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  336. };
  337. return py::cast(state).release().ptr();
  338. }
  339. static PyObject* setstate(PyObject* self, PyObject* args) {
  340. PyObject* dict = PyTuple_GetItem(args, 0);
  341. if (!dict) return NULL;
  342. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  343. auto& opdef = reinterpret_cast<PyOp(AddAxis)*>(self)->inst();
  344. static_cast<void>(opdef);
  345. {
  346. auto&& iter = state.find("axis");
  347. if (iter != state.end()) {
  348. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  349. }
  350. }
  351. Py_RETURN_NONE;
  352. }
  353. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  354. // };
  355. PyOpDefEnd(AddAxis)
  356. int PyOp(AddAxis)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  357. static const char* kwlist[] = {"axis", "scope", NULL};
  358. PyObject *axis = NULL, *scope = NULL;
  359. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  360. return -1;
  361. if (axis) {
  362. try {
  363. // TODO: remove this guard which is used for pybind11 implicit conversion
  364. py::detail::loader_life_support guard{};
  365. reinterpret_cast<PyOp(AddAxis)*>(self)->inst().axis =
  366. py::cast<decltype(AddAxis::axis)>(py::handle(axis));
  367. } CATCH_ALL(-1)
  368. }
  369. if (scope) {
  370. try {
  371. reinterpret_cast<PyOp(OpDef)*>(self)->op
  372. ->set_scope(py::cast<std::string>(py::handle(scope)));
  373. } CATCH_ALL(-1)
  374. }
  375. return 0;
  376. }
  377. PyGetSetDef PyOp(AddAxis)::py_getsetters[] = {
  378. {const_cast<char*>("axis"), py_get_generic(AddAxis, axis), py_set_generic(AddAxis, axis), const_cast<char*>("axis"), NULL},
  379. {NULL} /* Sentinel */
  380. };
  381. PyMethodDef PyOp(AddAxis)::tp_methods[] = {
  382. {const_cast<char*>("__getstate__"), PyOp(AddAxis)::getstate, METH_NOARGS, "AddAxis getstate"},
  383. {const_cast<char*>("__setstate__"), PyOp(AddAxis)::setstate, METH_VARARGS, "AddAxis setstate"},
  384. {NULL} /* Sentinel */
  385. };
  386. void _init_py_AddAxis(py::module m) {
  387. using py_op = PyOp(AddAxis);
  388. auto& py_type = PyOpType(AddAxis);
  389. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  390. py_type.tp_name = "megengine.core._imperative_rt.ops.AddAxis";
  391. py_type.tp_basicsize = sizeof(PyOp(AddAxis));
  392. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  393. py_type.tp_doc = "AddAxis";
  394. py_type.tp_base = &PyOpType(OpDef);
  395. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  396. py_type.tp_new = py_new_generic<py_op>;
  397. py_type.tp_init = py_op::py_init;
  398. py_type.tp_methods = py_op::tp_methods;
  399. py_type.tp_getset = py_op::py_getsetters;
  400. mgb_assert(PyType_Ready(&py_type) >= 0);
  401. PyType_Modified(&py_type);
  402. m.add_object("AddAxis", reinterpret_cast<PyObject*>(&py_type));
  403. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AddAxis::typeinfo(), &py_type).second);
  404. }
  405. PyOpDefBegin(Argmax) // {
  406. static PyGetSetDef py_getsetters[];
  407. static PyMethodDef tp_methods[];
  408. static PyObject* getstate(PyObject* self, PyObject*) {
  409. auto& opdef = reinterpret_cast<PyOp(Argmax)*>(self)->inst();
  410. static_cast<void>(opdef);
  411. std::unordered_map<std::string, py::object> state {
  412. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  413. };
  414. return py::cast(state).release().ptr();
  415. }
  416. static PyObject* setstate(PyObject* self, PyObject* args) {
  417. PyObject* dict = PyTuple_GetItem(args, 0);
  418. if (!dict) return NULL;
  419. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  420. auto& opdef = reinterpret_cast<PyOp(Argmax)*>(self)->inst();
  421. static_cast<void>(opdef);
  422. {
  423. auto&& iter = state.find("axis");
  424. if (iter != state.end()) {
  425. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  426. }
  427. }
  428. Py_RETURN_NONE;
  429. }
  430. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  431. // };
  432. PyOpDefEnd(Argmax)
  433. int PyOp(Argmax)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  434. static const char* kwlist[] = {"axis", "scope", NULL};
  435. PyObject *axis = NULL, *scope = NULL;
  436. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  437. return -1;
  438. if (axis) {
  439. try {
  440. // TODO: remove this guard which is used for pybind11 implicit conversion
  441. py::detail::loader_life_support guard{};
  442. reinterpret_cast<PyOp(Argmax)*>(self)->inst().axis =
  443. py::cast<decltype(Argmax::axis)>(py::handle(axis));
  444. } CATCH_ALL(-1)
  445. }
  446. if (scope) {
  447. try {
  448. reinterpret_cast<PyOp(OpDef)*>(self)->op
  449. ->set_scope(py::cast<std::string>(py::handle(scope)));
  450. } CATCH_ALL(-1)
  451. }
  452. return 0;
  453. }
  454. PyGetSetDef PyOp(Argmax)::py_getsetters[] = {
  455. {const_cast<char*>("axis"), py_get_generic(Argmax, axis), py_set_generic(Argmax, axis), const_cast<char*>("axis"), NULL},
  456. {NULL} /* Sentinel */
  457. };
  458. PyMethodDef PyOp(Argmax)::tp_methods[] = {
  459. {const_cast<char*>("__getstate__"), PyOp(Argmax)::getstate, METH_NOARGS, "Argmax getstate"},
  460. {const_cast<char*>("__setstate__"), PyOp(Argmax)::setstate, METH_VARARGS, "Argmax setstate"},
  461. {NULL} /* Sentinel */
  462. };
  463. void _init_py_Argmax(py::module m) {
  464. using py_op = PyOp(Argmax);
  465. auto& py_type = PyOpType(Argmax);
  466. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  467. py_type.tp_name = "megengine.core._imperative_rt.ops.Argmax";
  468. py_type.tp_basicsize = sizeof(PyOp(Argmax));
  469. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  470. py_type.tp_doc = "Argmax";
  471. py_type.tp_base = &PyOpType(OpDef);
  472. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  473. py_type.tp_new = py_new_generic<py_op>;
  474. py_type.tp_init = py_op::py_init;
  475. py_type.tp_methods = py_op::tp_methods;
  476. py_type.tp_getset = py_op::py_getsetters;
  477. mgb_assert(PyType_Ready(&py_type) >= 0);
  478. PyType_Modified(&py_type);
  479. m.add_object("Argmax", reinterpret_cast<PyObject*>(&py_type));
  480. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argmax::typeinfo(), &py_type).second);
  481. }
  482. PyOpDefBegin(Argmin) // {
  483. static PyGetSetDef py_getsetters[];
  484. static PyMethodDef tp_methods[];
  485. static PyObject* getstate(PyObject* self, PyObject*) {
  486. auto& opdef = reinterpret_cast<PyOp(Argmin)*>(self)->inst();
  487. static_cast<void>(opdef);
  488. std::unordered_map<std::string, py::object> state {
  489. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  490. };
  491. return py::cast(state).release().ptr();
  492. }
  493. static PyObject* setstate(PyObject* self, PyObject* args) {
  494. PyObject* dict = PyTuple_GetItem(args, 0);
  495. if (!dict) return NULL;
  496. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  497. auto& opdef = reinterpret_cast<PyOp(Argmin)*>(self)->inst();
  498. static_cast<void>(opdef);
  499. {
  500. auto&& iter = state.find("axis");
  501. if (iter != state.end()) {
  502. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  503. }
  504. }
  505. Py_RETURN_NONE;
  506. }
  507. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  508. // };
  509. PyOpDefEnd(Argmin)
  510. int PyOp(Argmin)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  511. static const char* kwlist[] = {"axis", "scope", NULL};
  512. PyObject *axis = NULL, *scope = NULL;
  513. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  514. return -1;
  515. if (axis) {
  516. try {
  517. // TODO: remove this guard which is used for pybind11 implicit conversion
  518. py::detail::loader_life_support guard{};
  519. reinterpret_cast<PyOp(Argmin)*>(self)->inst().axis =
  520. py::cast<decltype(Argmin::axis)>(py::handle(axis));
  521. } CATCH_ALL(-1)
  522. }
  523. if (scope) {
  524. try {
  525. reinterpret_cast<PyOp(OpDef)*>(self)->op
  526. ->set_scope(py::cast<std::string>(py::handle(scope)));
  527. } CATCH_ALL(-1)
  528. }
  529. return 0;
  530. }
  531. PyGetSetDef PyOp(Argmin)::py_getsetters[] = {
  532. {const_cast<char*>("axis"), py_get_generic(Argmin, axis), py_set_generic(Argmin, axis), const_cast<char*>("axis"), NULL},
  533. {NULL} /* Sentinel */
  534. };
  535. PyMethodDef PyOp(Argmin)::tp_methods[] = {
  536. {const_cast<char*>("__getstate__"), PyOp(Argmin)::getstate, METH_NOARGS, "Argmin getstate"},
  537. {const_cast<char*>("__setstate__"), PyOp(Argmin)::setstate, METH_VARARGS, "Argmin setstate"},
  538. {NULL} /* Sentinel */
  539. };
  540. void _init_py_Argmin(py::module m) {
  541. using py_op = PyOp(Argmin);
  542. auto& py_type = PyOpType(Argmin);
  543. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  544. py_type.tp_name = "megengine.core._imperative_rt.ops.Argmin";
  545. py_type.tp_basicsize = sizeof(PyOp(Argmin));
  546. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  547. py_type.tp_doc = "Argmin";
  548. py_type.tp_base = &PyOpType(OpDef);
  549. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  550. py_type.tp_new = py_new_generic<py_op>;
  551. py_type.tp_init = py_op::py_init;
  552. py_type.tp_methods = py_op::tp_methods;
  553. py_type.tp_getset = py_op::py_getsetters;
  554. mgb_assert(PyType_Ready(&py_type) >= 0);
  555. PyType_Modified(&py_type);
  556. m.add_object("Argmin", reinterpret_cast<PyObject*>(&py_type));
  557. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argmin::typeinfo(), &py_type).second);
  558. }
  559. template<> struct EnumTrait<Argsort::Order> {
  560. static constexpr const char *name = "Argsort.Order";
  561. static constexpr std::underlying_type_t<Argsort::Order> max = 2 - 1;
  562. };
  563. template<> PyTypeObject* EnumWrapper<Argsort::Order>::type = nullptr;
  564. template<> const char*
  565. EnumWrapper<Argsort::Order>::members[] = {"ASCENDING", "DESCENDING"};
  566. template<> std::unordered_map<std::string, Argsort::Order>
  567. EnumWrapper<Argsort::Order>::mem2value = {{normalize_enum("ASCENDING"), Argsort::Order::ASCENDING}, {normalize_enum("DESCENDING"), Argsort::Order::DESCENDING}};
  568. template<> PyObject* EnumWrapper<Argsort::Order>::pyobj_insts[2] = {nullptr};
  569. void _init_py_Argsort_Order(PyTypeObject& py_type) {
  570. auto& e_type = EnumWrapper<Argsort::Order>::type;
  571. static PyMethodDef tp_methods[] = {
  572. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Argsort::Order>::py_dump, METH_NOARGS, NULL},
  573. {NULL} /* Sentinel */
  574. };
  575. static PyType_Slot slots[] = {
  576. {Py_tp_repr, (void*)EnumWrapper<Argsort::Order>::py_repr},
  577. {Py_tp_richcompare, (void*)EnumWrapper<Argsort::Order>::tp_richcompare},
  578. {Py_tp_methods, tp_methods},
  579. {0, NULL}
  580. };
  581. static PyType_Spec spec = {
  582. // name
  583. "megengine.core._imperative_rt.ops.Argsort.Order",
  584. // basicsize
  585. sizeof(EnumWrapper<Argsort::Order>),
  586. // itemsize
  587. 0,
  588. // flags
  589. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  590. // slots
  591. slots
  592. };
  593. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  594. mgb_assert(
  595. e_type->tp_setattro(
  596. reinterpret_cast<PyObject*>(e_type),
  597. py::cast("__name__").release().ptr(),
  598. py::cast("Order").release().ptr()) >= 0);
  599. mgb_assert(
  600. e_type->tp_setattro(
  601. reinterpret_cast<PyObject*>(e_type),
  602. py::cast("__module__").release().ptr(),
  603. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  604. mgb_assert(
  605. e_type->tp_setattro(
  606. reinterpret_cast<PyObject*>(e_type),
  607. py::cast("__qualname__").release().ptr(),
  608. py::cast("Argsort.Order").release().ptr()) >= 0);
  609. {
  610. PyObject* inst = e_type->tp_alloc(e_type, 0);
  611. reinterpret_cast<EnumWrapper<Argsort::Order>*>(inst)->value = Argsort::Order::ASCENDING;
  612. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASCENDING", inst) >= 0);
  613. EnumWrapper<Argsort::Order>::pyobj_insts[0] = inst;
  614. }{
  615. PyObject* inst = e_type->tp_alloc(e_type, 0);
  616. reinterpret_cast<EnumWrapper<Argsort::Order>*>(inst)->value = Argsort::Order::DESCENDING;
  617. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DESCENDING", inst) >= 0);
  618. EnumWrapper<Argsort::Order>::pyobj_insts[1] = inst;
  619. }
  620. Py_INCREF(e_type);
  621. mgb_assert(PyDict_SetItemString(
  622. py_type.tp_dict, "Order", reinterpret_cast<PyObject*>(e_type)) >= 0);
  623. }
  624. PyOpDefBegin(Argsort) // {
  625. static PyGetSetDef py_getsetters[];
  626. static PyMethodDef tp_methods[];
  627. static PyObject* getstate(PyObject* self, PyObject*) {
  628. auto& opdef = reinterpret_cast<PyOp(Argsort)*>(self)->inst();
  629. static_cast<void>(opdef);
  630. std::unordered_map<std::string, py::object> state {
  631. {"order", serialization<decltype(opdef.order)>::dump(opdef.order)}
  632. };
  633. return py::cast(state).release().ptr();
  634. }
  635. static PyObject* setstate(PyObject* self, PyObject* args) {
  636. PyObject* dict = PyTuple_GetItem(args, 0);
  637. if (!dict) return NULL;
  638. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  639. auto& opdef = reinterpret_cast<PyOp(Argsort)*>(self)->inst();
  640. static_cast<void>(opdef);
  641. {
  642. auto&& iter = state.find("order");
  643. if (iter != state.end()) {
  644. opdef.order = serialization<decltype(opdef.order)>::load(iter->second);
  645. }
  646. }
  647. Py_RETURN_NONE;
  648. }
  649. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  650. // };
  651. PyOpDefEnd(Argsort)
  652. int PyOp(Argsort)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  653. static const char* kwlist[] = {"order", "scope", NULL};
  654. PyObject *order = NULL, *scope = NULL;
  655. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &order, &scope))
  656. return -1;
  657. if (order) {
  658. try {
  659. // TODO: remove this guard which is used for pybind11 implicit conversion
  660. py::detail::loader_life_support guard{};
  661. reinterpret_cast<PyOp(Argsort)*>(self)->inst().order =
  662. py::cast<decltype(Argsort::order)>(py::handle(order));
  663. } CATCH_ALL(-1)
  664. }
  665. if (scope) {
  666. try {
  667. reinterpret_cast<PyOp(OpDef)*>(self)->op
  668. ->set_scope(py::cast<std::string>(py::handle(scope)));
  669. } CATCH_ALL(-1)
  670. }
  671. return 0;
  672. }
  673. PyGetSetDef PyOp(Argsort)::py_getsetters[] = {
  674. {const_cast<char*>("order"), py_get_generic(Argsort, order), py_set_generic(Argsort, order), const_cast<char*>("order"), NULL},
  675. {NULL} /* Sentinel */
  676. };
  677. PyMethodDef PyOp(Argsort)::tp_methods[] = {
  678. {const_cast<char*>("__getstate__"), PyOp(Argsort)::getstate, METH_NOARGS, "Argsort getstate"},
  679. {const_cast<char*>("__setstate__"), PyOp(Argsort)::setstate, METH_VARARGS, "Argsort setstate"},
  680. {NULL} /* Sentinel */
  681. };
  682. void _init_py_Argsort(py::module m) {
  683. using py_op = PyOp(Argsort);
  684. auto& py_type = PyOpType(Argsort);
  685. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  686. py_type.tp_name = "megengine.core._imperative_rt.ops.Argsort";
  687. py_type.tp_basicsize = sizeof(PyOp(Argsort));
  688. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  689. py_type.tp_doc = "Argsort";
  690. py_type.tp_base = &PyOpType(OpDef);
  691. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  692. py_type.tp_new = py_new_generic<py_op>;
  693. py_type.tp_init = py_op::py_init;
  694. py_type.tp_methods = py_op::tp_methods;
  695. py_type.tp_getset = py_op::py_getsetters;
  696. mgb_assert(PyType_Ready(&py_type) >= 0);
  697. _init_py_Argsort_Order(py_type);
  698. PyType_Modified(&py_type);
  699. m.add_object("Argsort", reinterpret_cast<PyObject*>(&py_type));
  700. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argsort::typeinfo(), &py_type).second);
  701. }
  702. PyOpDefBegin(AssertEqual) // {
  703. static PyGetSetDef py_getsetters[];
  704. static PyMethodDef tp_methods[];
  705. static PyObject* getstate(PyObject* self, PyObject*) {
  706. auto& opdef = reinterpret_cast<PyOp(AssertEqual)*>(self)->inst();
  707. static_cast<void>(opdef);
  708. std::unordered_map<std::string, py::object> state {
  709. {"maxerr", serialization<decltype(opdef.maxerr)>::dump(opdef.maxerr)},
  710. {"verbose", serialization<decltype(opdef.verbose)>::dump(opdef.verbose)}
  711. };
  712. return py::cast(state).release().ptr();
  713. }
  714. static PyObject* setstate(PyObject* self, PyObject* args) {
  715. PyObject* dict = PyTuple_GetItem(args, 0);
  716. if (!dict) return NULL;
  717. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  718. auto& opdef = reinterpret_cast<PyOp(AssertEqual)*>(self)->inst();
  719. static_cast<void>(opdef);
  720. {
  721. auto&& iter = state.find("maxerr");
  722. if (iter != state.end()) {
  723. opdef.maxerr = serialization<decltype(opdef.maxerr)>::load(iter->second);
  724. }
  725. }
  726. {
  727. auto&& iter = state.find("verbose");
  728. if (iter != state.end()) {
  729. opdef.verbose = serialization<decltype(opdef.verbose)>::load(iter->second);
  730. }
  731. }
  732. Py_RETURN_NONE;
  733. }
  734. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  735. // };
  736. PyOpDefEnd(AssertEqual)
  737. int PyOp(AssertEqual)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  738. static const char* kwlist[] = {"maxerr", "verbose", "scope", NULL};
  739. PyObject *maxerr = NULL, *verbose = NULL, *scope = NULL;
  740. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &maxerr, &verbose, &scope))
  741. return -1;
  742. if (maxerr) {
  743. try {
  744. // TODO: remove this guard which is used for pybind11 implicit conversion
  745. py::detail::loader_life_support guard{};
  746. reinterpret_cast<PyOp(AssertEqual)*>(self)->inst().maxerr =
  747. py::cast<decltype(AssertEqual::maxerr)>(py::handle(maxerr));
  748. } CATCH_ALL(-1)
  749. }
  750. if (verbose) {
  751. try {
  752. // TODO: remove this guard which is used for pybind11 implicit conversion
  753. py::detail::loader_life_support guard{};
  754. reinterpret_cast<PyOp(AssertEqual)*>(self)->inst().verbose =
  755. py::cast<decltype(AssertEqual::verbose)>(py::handle(verbose));
  756. } CATCH_ALL(-1)
  757. }
  758. if (scope) {
  759. try {
  760. reinterpret_cast<PyOp(OpDef)*>(self)->op
  761. ->set_scope(py::cast<std::string>(py::handle(scope)));
  762. } CATCH_ALL(-1)
  763. }
  764. return 0;
  765. }
  766. PyGetSetDef PyOp(AssertEqual)::py_getsetters[] = {
  767. {const_cast<char*>("maxerr"), py_get_generic(AssertEqual, maxerr), py_set_generic(AssertEqual, maxerr), const_cast<char*>("maxerr"), NULL},
  768. {const_cast<char*>("verbose"), py_get_generic(AssertEqual, verbose), py_set_generic(AssertEqual, verbose), const_cast<char*>("verbose"), NULL},
  769. {NULL} /* Sentinel */
  770. };
  771. PyMethodDef PyOp(AssertEqual)::tp_methods[] = {
  772. {const_cast<char*>("__getstate__"), PyOp(AssertEqual)::getstate, METH_NOARGS, "AssertEqual getstate"},
  773. {const_cast<char*>("__setstate__"), PyOp(AssertEqual)::setstate, METH_VARARGS, "AssertEqual setstate"},
  774. {NULL} /* Sentinel */
  775. };
  776. void _init_py_AssertEqual(py::module m) {
  777. using py_op = PyOp(AssertEqual);
  778. auto& py_type = PyOpType(AssertEqual);
  779. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  780. py_type.tp_name = "megengine.core._imperative_rt.ops.AssertEqual";
  781. py_type.tp_basicsize = sizeof(PyOp(AssertEqual));
  782. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  783. py_type.tp_doc = "AssertEqual";
  784. py_type.tp_base = &PyOpType(OpDef);
  785. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  786. py_type.tp_new = py_new_generic<py_op>;
  787. py_type.tp_init = py_op::py_init;
  788. py_type.tp_methods = py_op::tp_methods;
  789. py_type.tp_getset = py_op::py_getsetters;
  790. mgb_assert(PyType_Ready(&py_type) >= 0);
  791. PyType_Modified(&py_type);
  792. m.add_object("AssertEqual", reinterpret_cast<PyObject*>(&py_type));
  793. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AssertEqual::typeinfo(), &py_type).second);
  794. }
  795. PyOpDefBegin(AtlasRuntime) // {
  796. static PyGetSetDef py_getsetters[];
  797. static PyMethodDef tp_methods[];
  798. static PyObject* getstate(PyObject* self, PyObject*) {
  799. auto& opdef = reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst();
  800. static_cast<void>(opdef);
  801. std::unordered_map<std::string, py::object> state {
  802. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  803. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  804. };
  805. return py::cast(state).release().ptr();
  806. }
  807. static PyObject* setstate(PyObject* self, PyObject* args) {
  808. PyObject* dict = PyTuple_GetItem(args, 0);
  809. if (!dict) return NULL;
  810. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  811. auto& opdef = reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst();
  812. static_cast<void>(opdef);
  813. {
  814. auto&& iter = state.find("buf");
  815. if (iter != state.end()) {
  816. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  817. }
  818. }
  819. {
  820. auto&& iter = state.find("buf_size");
  821. if (iter != state.end()) {
  822. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  823. }
  824. }
  825. Py_RETURN_NONE;
  826. }
  827. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  828. // };
  829. PyOpDefEnd(AtlasRuntime)
  830. int PyOp(AtlasRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  831. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  832. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  833. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  834. return -1;
  835. if (buf) {
  836. try {
  837. // TODO: remove this guard which is used for pybind11 implicit conversion
  838. py::detail::loader_life_support guard{};
  839. reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst().buf =
  840. py::cast<decltype(AtlasRuntime::buf)>(py::handle(buf));
  841. } CATCH_ALL(-1)
  842. }
  843. if (buf_size) {
  844. try {
  845. // TODO: remove this guard which is used for pybind11 implicit conversion
  846. py::detail::loader_life_support guard{};
  847. reinterpret_cast<PyOp(AtlasRuntime)*>(self)->inst().buf_size =
  848. py::cast<decltype(AtlasRuntime::buf_size)>(py::handle(buf_size));
  849. } CATCH_ALL(-1)
  850. }
  851. if (scope) {
  852. try {
  853. reinterpret_cast<PyOp(OpDef)*>(self)->op
  854. ->set_scope(py::cast<std::string>(py::handle(scope)));
  855. } CATCH_ALL(-1)
  856. }
  857. return 0;
  858. }
  859. PyGetSetDef PyOp(AtlasRuntime)::py_getsetters[] = {
  860. {const_cast<char*>("buf"), py_get_generic(AtlasRuntime, buf), py_set_generic(AtlasRuntime, buf), const_cast<char*>("buf"), NULL},
  861. {const_cast<char*>("buf_size"), py_get_generic(AtlasRuntime, buf_size), py_set_generic(AtlasRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  862. {NULL} /* Sentinel */
  863. };
  864. PyMethodDef PyOp(AtlasRuntime)::tp_methods[] = {
  865. {const_cast<char*>("__getstate__"), PyOp(AtlasRuntime)::getstate, METH_NOARGS, "AtlasRuntime getstate"},
  866. {const_cast<char*>("__setstate__"), PyOp(AtlasRuntime)::setstate, METH_VARARGS, "AtlasRuntime setstate"},
  867. {NULL} /* Sentinel */
  868. };
  869. void _init_py_AtlasRuntime(py::module m) {
  870. using py_op = PyOp(AtlasRuntime);
  871. auto& py_type = PyOpType(AtlasRuntime);
  872. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  873. py_type.tp_name = "megengine.core._imperative_rt.ops.AtlasRuntime";
  874. py_type.tp_basicsize = sizeof(PyOp(AtlasRuntime));
  875. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  876. py_type.tp_doc = "AtlasRuntime";
  877. py_type.tp_base = &PyOpType(OpDef);
  878. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  879. py_type.tp_new = py_new_generic<py_op>;
  880. py_type.tp_init = py_op::py_init;
  881. py_type.tp_methods = py_op::tp_methods;
  882. py_type.tp_getset = py_op::py_getsetters;
  883. mgb_assert(PyType_Ready(&py_type) >= 0);
  884. PyType_Modified(&py_type);
  885. m.add_object("AtlasRuntime", reinterpret_cast<PyObject*>(&py_type));
  886. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AtlasRuntime::typeinfo(), &py_type).second);
  887. }
  888. PyOpDefBegin(Barrier) // {
  889. static PyGetSetDef py_getsetters[];
  890. static PyMethodDef tp_methods[];
  891. static PyObject* getstate(PyObject* self, PyObject*) {
  892. auto& opdef = reinterpret_cast<PyOp(Barrier)*>(self)->inst();
  893. static_cast<void>(opdef);
  894. std::unordered_map<std::string, py::object> state {
  895. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)},
  896. {"nr_outputs", serialization<decltype(opdef.nr_outputs)>::dump(opdef.nr_outputs)}
  897. };
  898. return py::cast(state).release().ptr();
  899. }
  900. static PyObject* setstate(PyObject* self, PyObject* args) {
  901. PyObject* dict = PyTuple_GetItem(args, 0);
  902. if (!dict) return NULL;
  903. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  904. auto& opdef = reinterpret_cast<PyOp(Barrier)*>(self)->inst();
  905. static_cast<void>(opdef);
  906. {
  907. auto&& iter = state.find("comp_node");
  908. if (iter != state.end()) {
  909. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  910. }
  911. }
  912. {
  913. auto&& iter = state.find("nr_outputs");
  914. if (iter != state.end()) {
  915. opdef.nr_outputs = serialization<decltype(opdef.nr_outputs)>::load(iter->second);
  916. }
  917. }
  918. Py_RETURN_NONE;
  919. }
  920. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  921. // };
  922. PyOpDefEnd(Barrier)
  923. int PyOp(Barrier)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  924. static const char* kwlist[] = {"comp_node", "nr_outputs", "scope", NULL};
  925. PyObject *comp_node = NULL, *nr_outputs = NULL, *scope = NULL;
  926. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &comp_node, &nr_outputs, &scope))
  927. return -1;
  928. if (comp_node) {
  929. try {
  930. // TODO: remove this guard which is used for pybind11 implicit conversion
  931. py::detail::loader_life_support guard{};
  932. reinterpret_cast<PyOp(Barrier)*>(self)->inst().comp_node =
  933. py::cast<decltype(Barrier::comp_node)>(py::handle(comp_node));
  934. } CATCH_ALL(-1)
  935. }
  936. if (nr_outputs) {
  937. try {
  938. // TODO: remove this guard which is used for pybind11 implicit conversion
  939. py::detail::loader_life_support guard{};
  940. reinterpret_cast<PyOp(Barrier)*>(self)->inst().nr_outputs =
  941. py::cast<decltype(Barrier::nr_outputs)>(py::handle(nr_outputs));
  942. } CATCH_ALL(-1)
  943. }
  944. if (scope) {
  945. try {
  946. reinterpret_cast<PyOp(OpDef)*>(self)->op
  947. ->set_scope(py::cast<std::string>(py::handle(scope)));
  948. } CATCH_ALL(-1)
  949. }
  950. return 0;
  951. }
  952. PyGetSetDef PyOp(Barrier)::py_getsetters[] = {
  953. {const_cast<char*>("comp_node"), py_get_generic(Barrier, comp_node), py_set_generic(Barrier, comp_node), const_cast<char*>("comp_node"), NULL},
  954. {const_cast<char*>("nr_outputs"), py_get_generic(Barrier, nr_outputs), py_set_generic(Barrier, nr_outputs), const_cast<char*>("nr_outputs"), NULL},
  955. {NULL} /* Sentinel */
  956. };
  957. PyMethodDef PyOp(Barrier)::tp_methods[] = {
  958. {const_cast<char*>("__getstate__"), PyOp(Barrier)::getstate, METH_NOARGS, "Barrier getstate"},
  959. {const_cast<char*>("__setstate__"), PyOp(Barrier)::setstate, METH_VARARGS, "Barrier setstate"},
  960. {NULL} /* Sentinel */
  961. };
  962. void _init_py_Barrier(py::module m) {
  963. using py_op = PyOp(Barrier);
  964. auto& py_type = PyOpType(Barrier);
  965. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  966. py_type.tp_name = "megengine.core._imperative_rt.ops.Barrier";
  967. py_type.tp_basicsize = sizeof(PyOp(Barrier));
  968. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  969. py_type.tp_doc = "Barrier";
  970. py_type.tp_base = &PyOpType(OpDef);
  971. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  972. py_type.tp_new = py_new_generic<py_op>;
  973. py_type.tp_init = py_op::py_init;
  974. py_type.tp_methods = py_op::tp_methods;
  975. py_type.tp_getset = py_op::py_getsetters;
  976. mgb_assert(PyType_Ready(&py_type) >= 0);
  977. PyType_Modified(&py_type);
  978. m.add_object("Barrier", reinterpret_cast<PyObject*>(&py_type));
  979. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Barrier::typeinfo(), &py_type).second);
  980. }
  981. template<> struct EnumTrait<BatchConvBias::NonlineMode> {
  982. static constexpr const char *name = "BatchConvBias.NonlineMode";
  983. static constexpr std::underlying_type_t<BatchConvBias::NonlineMode> max = 4 - 1;
  984. };
  985. template<> PyTypeObject* EnumWrapper<BatchConvBias::NonlineMode>::type = nullptr;
  986. template<> const char*
  987. EnumWrapper<BatchConvBias::NonlineMode>::members[] = {"IDENTITY", "RELU", "SIGMOID", "H_SWISH"};
  988. template<> std::unordered_map<std::string, BatchConvBias::NonlineMode>
  989. EnumWrapper<BatchConvBias::NonlineMode>::mem2value = {{normalize_enum("IDENTITY"), BatchConvBias::NonlineMode::IDENTITY}, {normalize_enum("RELU"), BatchConvBias::NonlineMode::RELU}, {normalize_enum("SIGMOID"), BatchConvBias::NonlineMode::SIGMOID}, {normalize_enum("H_SWISH"), BatchConvBias::NonlineMode::H_SWISH}};
  990. template<> PyObject* EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[4] = {nullptr};
  991. void _init_py_BatchConvBias_NonlineMode(PyTypeObject& py_type) {
  992. auto& e_type = EnumWrapper<BatchConvBias::NonlineMode>::type;
  993. static PyMethodDef tp_methods[] = {
  994. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::NonlineMode>::py_dump, METH_NOARGS, NULL},
  995. {NULL} /* Sentinel */
  996. };
  997. static PyType_Slot slots[] = {
  998. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::NonlineMode>::py_repr},
  999. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::NonlineMode>::tp_richcompare},
  1000. {Py_tp_methods, tp_methods},
  1001. {0, NULL}
  1002. };
  1003. static PyType_Spec spec = {
  1004. // name
  1005. "megengine.core._imperative_rt.ops.BatchConvBias.NonlineMode",
  1006. // basicsize
  1007. sizeof(EnumWrapper<BatchConvBias::NonlineMode>),
  1008. // itemsize
  1009. 0,
  1010. // flags
  1011. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1012. // slots
  1013. slots
  1014. };
  1015. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1016. mgb_assert(
  1017. e_type->tp_setattro(
  1018. reinterpret_cast<PyObject*>(e_type),
  1019. py::cast("__name__").release().ptr(),
  1020. py::cast("NonlineMode").release().ptr()) >= 0);
  1021. mgb_assert(
  1022. e_type->tp_setattro(
  1023. reinterpret_cast<PyObject*>(e_type),
  1024. py::cast("__module__").release().ptr(),
  1025. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1026. mgb_assert(
  1027. e_type->tp_setattro(
  1028. reinterpret_cast<PyObject*>(e_type),
  1029. py::cast("__qualname__").release().ptr(),
  1030. py::cast("BatchConvBias.NonlineMode").release().ptr()) >= 0);
  1031. {
  1032. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1033. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::IDENTITY;
  1034. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "IDENTITY", inst) >= 0);
  1035. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[0] = inst;
  1036. }{
  1037. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1038. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::RELU;
  1039. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  1040. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[1] = inst;
  1041. }{
  1042. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1043. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::SIGMOID;
  1044. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID", inst) >= 0);
  1045. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[2] = inst;
  1046. }{
  1047. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1048. reinterpret_cast<EnumWrapper<BatchConvBias::NonlineMode>*>(inst)->value = BatchConvBias::NonlineMode::H_SWISH;
  1049. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH", inst) >= 0);
  1050. EnumWrapper<BatchConvBias::NonlineMode>::pyobj_insts[3] = inst;
  1051. }
  1052. Py_INCREF(e_type);
  1053. mgb_assert(PyDict_SetItemString(
  1054. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1055. }
  1056. template<> struct EnumTrait<BatchConvBias::Mode> {
  1057. static constexpr const char *name = "BatchConvBias.Mode";
  1058. static constexpr std::underlying_type_t<BatchConvBias::Mode> max = 2 - 1;
  1059. };
  1060. template<> PyTypeObject* EnumWrapper<BatchConvBias::Mode>::type = nullptr;
  1061. template<> const char*
  1062. EnumWrapper<BatchConvBias::Mode>::members[] = {"CROSS_CORRELATION", "CONVOLUTION"};
  1063. template<> std::unordered_map<std::string, BatchConvBias::Mode>
  1064. EnumWrapper<BatchConvBias::Mode>::mem2value = {{normalize_enum("CROSS_CORRELATION"), BatchConvBias::Mode::CROSS_CORRELATION}, {normalize_enum("CONVOLUTION"), BatchConvBias::Mode::CONVOLUTION}};
  1065. template<> PyObject* EnumWrapper<BatchConvBias::Mode>::pyobj_insts[2] = {nullptr};
  1066. void _init_py_BatchConvBias_Mode(PyTypeObject& py_type) {
  1067. auto& e_type = EnumWrapper<BatchConvBias::Mode>::type;
  1068. static PyMethodDef tp_methods[] = {
  1069. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::Mode>::py_dump, METH_NOARGS, NULL},
  1070. {NULL} /* Sentinel */
  1071. };
  1072. static PyType_Slot slots[] = {
  1073. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::Mode>::py_repr},
  1074. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::Mode>::tp_richcompare},
  1075. {Py_tp_methods, tp_methods},
  1076. {0, NULL}
  1077. };
  1078. static PyType_Spec spec = {
  1079. // name
  1080. "megengine.core._imperative_rt.ops.BatchConvBias.Mode",
  1081. // basicsize
  1082. sizeof(EnumWrapper<BatchConvBias::Mode>),
  1083. // itemsize
  1084. 0,
  1085. // flags
  1086. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1087. // slots
  1088. slots
  1089. };
  1090. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1091. mgb_assert(
  1092. e_type->tp_setattro(
  1093. reinterpret_cast<PyObject*>(e_type),
  1094. py::cast("__name__").release().ptr(),
  1095. py::cast("Mode").release().ptr()) >= 0);
  1096. mgb_assert(
  1097. e_type->tp_setattro(
  1098. reinterpret_cast<PyObject*>(e_type),
  1099. py::cast("__module__").release().ptr(),
  1100. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1101. mgb_assert(
  1102. e_type->tp_setattro(
  1103. reinterpret_cast<PyObject*>(e_type),
  1104. py::cast("__qualname__").release().ptr(),
  1105. py::cast("BatchConvBias.Mode").release().ptr()) >= 0);
  1106. {
  1107. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1108. reinterpret_cast<EnumWrapper<BatchConvBias::Mode>*>(inst)->value = BatchConvBias::Mode::CROSS_CORRELATION;
  1109. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CROSS_CORRELATION", inst) >= 0);
  1110. EnumWrapper<BatchConvBias::Mode>::pyobj_insts[0] = inst;
  1111. }{
  1112. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1113. reinterpret_cast<EnumWrapper<BatchConvBias::Mode>*>(inst)->value = BatchConvBias::Mode::CONVOLUTION;
  1114. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONVOLUTION", inst) >= 0);
  1115. EnumWrapper<BatchConvBias::Mode>::pyobj_insts[1] = inst;
  1116. }
  1117. Py_INCREF(e_type);
  1118. mgb_assert(PyDict_SetItemString(
  1119. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1120. }
  1121. template<> struct EnumTrait<BatchConvBias::Sparse> {
  1122. static constexpr const char *name = "BatchConvBias.Sparse";
  1123. static constexpr std::underlying_type_t<BatchConvBias::Sparse> max = 2 - 1;
  1124. };
  1125. template<> PyTypeObject* EnumWrapper<BatchConvBias::Sparse>::type = nullptr;
  1126. template<> const char*
  1127. EnumWrapper<BatchConvBias::Sparse>::members[] = {"DENSE", "GROUP"};
  1128. template<> std::unordered_map<std::string, BatchConvBias::Sparse>
  1129. EnumWrapper<BatchConvBias::Sparse>::mem2value = {{normalize_enum("DENSE"), BatchConvBias::Sparse::DENSE}, {normalize_enum("GROUP"), BatchConvBias::Sparse::GROUP}};
  1130. template<> PyObject* EnumWrapper<BatchConvBias::Sparse>::pyobj_insts[2] = {nullptr};
  1131. void _init_py_BatchConvBias_Sparse(PyTypeObject& py_type) {
  1132. auto& e_type = EnumWrapper<BatchConvBias::Sparse>::type;
  1133. static PyMethodDef tp_methods[] = {
  1134. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::Sparse>::py_dump, METH_NOARGS, NULL},
  1135. {NULL} /* Sentinel */
  1136. };
  1137. static PyType_Slot slots[] = {
  1138. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::Sparse>::py_repr},
  1139. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::Sparse>::tp_richcompare},
  1140. {Py_tp_methods, tp_methods},
  1141. {0, NULL}
  1142. };
  1143. static PyType_Spec spec = {
  1144. // name
  1145. "megengine.core._imperative_rt.ops.BatchConvBias.Sparse",
  1146. // basicsize
  1147. sizeof(EnumWrapper<BatchConvBias::Sparse>),
  1148. // itemsize
  1149. 0,
  1150. // flags
  1151. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1152. // slots
  1153. slots
  1154. };
  1155. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1156. mgb_assert(
  1157. e_type->tp_setattro(
  1158. reinterpret_cast<PyObject*>(e_type),
  1159. py::cast("__name__").release().ptr(),
  1160. py::cast("Sparse").release().ptr()) >= 0);
  1161. mgb_assert(
  1162. e_type->tp_setattro(
  1163. reinterpret_cast<PyObject*>(e_type),
  1164. py::cast("__module__").release().ptr(),
  1165. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1166. mgb_assert(
  1167. e_type->tp_setattro(
  1168. reinterpret_cast<PyObject*>(e_type),
  1169. py::cast("__qualname__").release().ptr(),
  1170. py::cast("BatchConvBias.Sparse").release().ptr()) >= 0);
  1171. {
  1172. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1173. reinterpret_cast<EnumWrapper<BatchConvBias::Sparse>*>(inst)->value = BatchConvBias::Sparse::DENSE;
  1174. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DENSE", inst) >= 0);
  1175. EnumWrapper<BatchConvBias::Sparse>::pyobj_insts[0] = inst;
  1176. }{
  1177. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1178. reinterpret_cast<EnumWrapper<BatchConvBias::Sparse>*>(inst)->value = BatchConvBias::Sparse::GROUP;
  1179. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GROUP", inst) >= 0);
  1180. EnumWrapper<BatchConvBias::Sparse>::pyobj_insts[1] = inst;
  1181. }
  1182. Py_INCREF(e_type);
  1183. mgb_assert(PyDict_SetItemString(
  1184. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1185. }
  1186. void _init_py_BatchConvBias_Format(PyTypeObject& py_type) {
  1187. auto& e_type = EnumWrapper<BatchConvBias::Format>::type;
  1188. Py_INCREF(e_type);
  1189. mgb_assert(PyDict_SetItemString(
  1190. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1191. }
  1192. template<> struct EnumTrait<BatchConvBias::ComputeMode> {
  1193. static constexpr const char *name = "BatchConvBias.ComputeMode";
  1194. static constexpr std::underlying_type_t<BatchConvBias::ComputeMode> max = 2 - 1;
  1195. };
  1196. template<> PyTypeObject* EnumWrapper<BatchConvBias::ComputeMode>::type = nullptr;
  1197. template<> const char*
  1198. EnumWrapper<BatchConvBias::ComputeMode>::members[] = {"DEFAULT", "FLOAT32"};
  1199. template<> std::unordered_map<std::string, BatchConvBias::ComputeMode>
  1200. EnumWrapper<BatchConvBias::ComputeMode>::mem2value = {{normalize_enum("DEFAULT"), BatchConvBias::ComputeMode::DEFAULT}, {normalize_enum("FLOAT32"), BatchConvBias::ComputeMode::FLOAT32}};
  1201. template<> PyObject* EnumWrapper<BatchConvBias::ComputeMode>::pyobj_insts[2] = {nullptr};
  1202. void _init_py_BatchConvBias_ComputeMode(PyTypeObject& py_type) {
  1203. auto& e_type = EnumWrapper<BatchConvBias::ComputeMode>::type;
  1204. static PyMethodDef tp_methods[] = {
  1205. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchConvBias::ComputeMode>::py_dump, METH_NOARGS, NULL},
  1206. {NULL} /* Sentinel */
  1207. };
  1208. static PyType_Slot slots[] = {
  1209. {Py_tp_repr, (void*)EnumWrapper<BatchConvBias::ComputeMode>::py_repr},
  1210. {Py_tp_richcompare, (void*)EnumWrapper<BatchConvBias::ComputeMode>::tp_richcompare},
  1211. {Py_tp_methods, tp_methods},
  1212. {0, NULL}
  1213. };
  1214. static PyType_Spec spec = {
  1215. // name
  1216. "megengine.core._imperative_rt.ops.BatchConvBias.ComputeMode",
  1217. // basicsize
  1218. sizeof(EnumWrapper<BatchConvBias::ComputeMode>),
  1219. // itemsize
  1220. 0,
  1221. // flags
  1222. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1223. // slots
  1224. slots
  1225. };
  1226. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1227. mgb_assert(
  1228. e_type->tp_setattro(
  1229. reinterpret_cast<PyObject*>(e_type),
  1230. py::cast("__name__").release().ptr(),
  1231. py::cast("ComputeMode").release().ptr()) >= 0);
  1232. mgb_assert(
  1233. e_type->tp_setattro(
  1234. reinterpret_cast<PyObject*>(e_type),
  1235. py::cast("__module__").release().ptr(),
  1236. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1237. mgb_assert(
  1238. e_type->tp_setattro(
  1239. reinterpret_cast<PyObject*>(e_type),
  1240. py::cast("__qualname__").release().ptr(),
  1241. py::cast("BatchConvBias.ComputeMode").release().ptr()) >= 0);
  1242. {
  1243. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1244. reinterpret_cast<EnumWrapper<BatchConvBias::ComputeMode>*>(inst)->value = BatchConvBias::ComputeMode::DEFAULT;
  1245. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  1246. EnumWrapper<BatchConvBias::ComputeMode>::pyobj_insts[0] = inst;
  1247. }{
  1248. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1249. reinterpret_cast<EnumWrapper<BatchConvBias::ComputeMode>*>(inst)->value = BatchConvBias::ComputeMode::FLOAT32;
  1250. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT32", inst) >= 0);
  1251. EnumWrapper<BatchConvBias::ComputeMode>::pyobj_insts[1] = inst;
  1252. }
  1253. Py_INCREF(e_type);
  1254. mgb_assert(PyDict_SetItemString(
  1255. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1256. }
  1257. template<> struct EnumTrait<BatchConvBias::Strategy> {
  1258. static constexpr const char *name = "BatchConvBias.Strategy";
  1259. static constexpr std::underlying_type_t<BatchConvBias::Strategy> max = (1llu << 4) - 1;
  1260. };
  1261. template<> PyTypeObject* BitCombinedEnumWrapper<BatchConvBias::Strategy>::type = nullptr;
  1262. template<> const char*
  1263. BitCombinedEnumWrapper<BatchConvBias::Strategy>::members[] = {"HEURISTIC", "PROFILE", "REPRODUCIBLE", "OPTIMIZED"};
  1264. template<> std::unordered_map<std::string, BatchConvBias::Strategy>
  1265. BitCombinedEnumWrapper<BatchConvBias::Strategy>::mem2value = {{normalize_enum("HEURISTIC"), BatchConvBias::Strategy::HEURISTIC}, {normalize_enum("PROFILE"), BatchConvBias::Strategy::PROFILE}, {normalize_enum("REPRODUCIBLE"), BatchConvBias::Strategy::REPRODUCIBLE}, {normalize_enum("OPTIMIZED"), BatchConvBias::Strategy::OPTIMIZED}};
  1266. template<> PyObject* BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[4] = {nullptr};
  1267. void _init_py_BatchConvBias_Strategy(PyTypeObject& py_type) {
  1268. auto& e_type = BitCombinedEnumWrapper<BatchConvBias::Strategy>::type;
  1269. static PyMethodDef tp_methods[] = {
  1270. {const_cast<char*>("dump"), (PyCFunction)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_dump, METH_NOARGS, NULL},
  1271. {NULL} /* Sentinel */
  1272. };
  1273. static PyType_Slot slots[] = {
  1274. {Py_tp_repr, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_repr},
  1275. {Py_tp_richcompare, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::tp_richcompare},
  1276. {Py_tp_methods, tp_methods},
  1277. {Py_tp_new, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_new_combined_enum},
  1278. {Py_nb_or, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_or},
  1279. {Py_nb_and, (void*)BitCombinedEnumWrapper<BatchConvBias::Strategy>::py_and},
  1280. {0, NULL}
  1281. };
  1282. static PyType_Spec spec = {
  1283. // name
  1284. "megengine.core._imperative_rt.ops.BatchConvBias.Strategy",
  1285. // basicsize
  1286. sizeof(BitCombinedEnumWrapper<BatchConvBias::Strategy>),
  1287. // itemsize
  1288. 0,
  1289. // flags
  1290. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1291. // slots
  1292. slots
  1293. };
  1294. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1295. mgb_assert(
  1296. e_type->tp_setattro(
  1297. reinterpret_cast<PyObject*>(e_type),
  1298. py::cast("__name__").release().ptr(),
  1299. py::cast("Strategy").release().ptr()) >= 0);
  1300. mgb_assert(
  1301. e_type->tp_setattro(
  1302. reinterpret_cast<PyObject*>(e_type),
  1303. py::cast("__module__").release().ptr(),
  1304. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1305. mgb_assert(
  1306. e_type->tp_setattro(
  1307. reinterpret_cast<PyObject*>(e_type),
  1308. py::cast("__qualname__").release().ptr(),
  1309. py::cast("BatchConvBias.Strategy").release().ptr()) >= 0);
  1310. {
  1311. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1312. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::HEURISTIC;
  1313. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "HEURISTIC", inst) >= 0);
  1314. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[0] = inst;
  1315. }{
  1316. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1317. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::PROFILE;
  1318. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PROFILE", inst) >= 0);
  1319. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[1] = inst;
  1320. }{
  1321. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1322. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::REPRODUCIBLE;
  1323. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPRODUCIBLE", inst) >= 0);
  1324. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[2] = inst;
  1325. }{
  1326. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1327. reinterpret_cast<BitCombinedEnumWrapper<BatchConvBias::Strategy>*>(inst)->value = BatchConvBias::Strategy::OPTIMIZED;
  1328. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "OPTIMIZED", inst) >= 0);
  1329. BitCombinedEnumWrapper<BatchConvBias::Strategy>::pyobj_insts[3] = inst;
  1330. }
  1331. Py_INCREF(e_type);
  1332. mgb_assert(PyDict_SetItemString(
  1333. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1334. }
  1335. PyOpDefBegin(BatchConvBias) // {
  1336. static PyGetSetDef py_getsetters[];
  1337. static PyMethodDef tp_methods[];
  1338. static PyObject* getstate(PyObject* self, PyObject*) {
  1339. auto& opdef = reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst();
  1340. static_cast<void>(opdef);
  1341. std::unordered_map<std::string, py::object> state {
  1342. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)},
  1343. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  1344. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  1345. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  1346. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  1347. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  1348. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  1349. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  1350. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  1351. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  1352. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  1353. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  1354. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  1355. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  1356. };
  1357. return py::cast(state).release().ptr();
  1358. }
  1359. static PyObject* setstate(PyObject* self, PyObject* args) {
  1360. PyObject* dict = PyTuple_GetItem(args, 0);
  1361. if (!dict) return NULL;
  1362. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  1363. auto& opdef = reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst();
  1364. static_cast<void>(opdef);
  1365. {
  1366. auto&& iter = state.find("nonlineMode");
  1367. if (iter != state.end()) {
  1368. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  1369. }
  1370. }
  1371. {
  1372. auto&& iter = state.find("mode");
  1373. if (iter != state.end()) {
  1374. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  1375. }
  1376. }
  1377. {
  1378. auto&& iter = state.find("pad_h");
  1379. if (iter != state.end()) {
  1380. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  1381. }
  1382. }
  1383. {
  1384. auto&& iter = state.find("pad_w");
  1385. if (iter != state.end()) {
  1386. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  1387. }
  1388. }
  1389. {
  1390. auto&& iter = state.find("stride_h");
  1391. if (iter != state.end()) {
  1392. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  1393. }
  1394. }
  1395. {
  1396. auto&& iter = state.find("stride_w");
  1397. if (iter != state.end()) {
  1398. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  1399. }
  1400. }
  1401. {
  1402. auto&& iter = state.find("dilate_h");
  1403. if (iter != state.end()) {
  1404. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  1405. }
  1406. }
  1407. {
  1408. auto&& iter = state.find("dilate_w");
  1409. if (iter != state.end()) {
  1410. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  1411. }
  1412. }
  1413. {
  1414. auto&& iter = state.find("sparse");
  1415. if (iter != state.end()) {
  1416. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  1417. }
  1418. }
  1419. {
  1420. auto&& iter = state.find("format");
  1421. if (iter != state.end()) {
  1422. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  1423. }
  1424. }
  1425. {
  1426. auto&& iter = state.find("compute_mode");
  1427. if (iter != state.end()) {
  1428. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  1429. }
  1430. }
  1431. {
  1432. auto&& iter = state.find("strategy");
  1433. if (iter != state.end()) {
  1434. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  1435. }
  1436. }
  1437. {
  1438. auto&& iter = state.find("workspace_limit");
  1439. if (iter != state.end()) {
  1440. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  1441. }
  1442. }
  1443. {
  1444. auto&& iter = state.find("dtype");
  1445. if (iter != state.end()) {
  1446. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  1447. }
  1448. }
  1449. Py_RETURN_NONE;
  1450. }
  1451. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  1452. // };
  1453. PyOpDefEnd(BatchConvBias)
  1454. int PyOp(BatchConvBias)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  1455. static const char* kwlist[] = {"nonlineMode", "mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL};
  1456. PyObject *nonlineMode = NULL, *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL;
  1457. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &nonlineMode, &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &dtype, &scope))
  1458. return -1;
  1459. if (nonlineMode) {
  1460. try {
  1461. // TODO: remove this guard which is used for pybind11 implicit conversion
  1462. py::detail::loader_life_support guard{};
  1463. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().nonlineMode =
  1464. py::cast<decltype(BatchConvBias::nonlineMode)>(py::handle(nonlineMode));
  1465. } CATCH_ALL(-1)
  1466. }
  1467. if (mode) {
  1468. try {
  1469. // TODO: remove this guard which is used for pybind11 implicit conversion
  1470. py::detail::loader_life_support guard{};
  1471. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().mode =
  1472. py::cast<decltype(BatchConvBias::mode)>(py::handle(mode));
  1473. } CATCH_ALL(-1)
  1474. }
  1475. if (pad_h) {
  1476. try {
  1477. // TODO: remove this guard which is used for pybind11 implicit conversion
  1478. py::detail::loader_life_support guard{};
  1479. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().pad_h =
  1480. py::cast<decltype(BatchConvBias::pad_h)>(py::handle(pad_h));
  1481. } CATCH_ALL(-1)
  1482. }
  1483. if (pad_w) {
  1484. try {
  1485. // TODO: remove this guard which is used for pybind11 implicit conversion
  1486. py::detail::loader_life_support guard{};
  1487. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().pad_w =
  1488. py::cast<decltype(BatchConvBias::pad_w)>(py::handle(pad_w));
  1489. } CATCH_ALL(-1)
  1490. }
  1491. if (stride_h) {
  1492. try {
  1493. // TODO: remove this guard which is used for pybind11 implicit conversion
  1494. py::detail::loader_life_support guard{};
  1495. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().stride_h =
  1496. py::cast<decltype(BatchConvBias::stride_h)>(py::handle(stride_h));
  1497. } CATCH_ALL(-1)
  1498. }
  1499. if (stride_w) {
  1500. try {
  1501. // TODO: remove this guard which is used for pybind11 implicit conversion
  1502. py::detail::loader_life_support guard{};
  1503. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().stride_w =
  1504. py::cast<decltype(BatchConvBias::stride_w)>(py::handle(stride_w));
  1505. } CATCH_ALL(-1)
  1506. }
  1507. if (dilate_h) {
  1508. try {
  1509. // TODO: remove this guard which is used for pybind11 implicit conversion
  1510. py::detail::loader_life_support guard{};
  1511. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().dilate_h =
  1512. py::cast<decltype(BatchConvBias::dilate_h)>(py::handle(dilate_h));
  1513. } CATCH_ALL(-1)
  1514. }
  1515. if (dilate_w) {
  1516. try {
  1517. // TODO: remove this guard which is used for pybind11 implicit conversion
  1518. py::detail::loader_life_support guard{};
  1519. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().dilate_w =
  1520. py::cast<decltype(BatchConvBias::dilate_w)>(py::handle(dilate_w));
  1521. } CATCH_ALL(-1)
  1522. }
  1523. if (sparse) {
  1524. try {
  1525. // TODO: remove this guard which is used for pybind11 implicit conversion
  1526. py::detail::loader_life_support guard{};
  1527. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().sparse =
  1528. py::cast<decltype(BatchConvBias::sparse)>(py::handle(sparse));
  1529. } CATCH_ALL(-1)
  1530. }
  1531. if (format) {
  1532. try {
  1533. // TODO: remove this guard which is used for pybind11 implicit conversion
  1534. py::detail::loader_life_support guard{};
  1535. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().format =
  1536. py::cast<decltype(BatchConvBias::format)>(py::handle(format));
  1537. } CATCH_ALL(-1)
  1538. }
  1539. if (compute_mode) {
  1540. try {
  1541. // TODO: remove this guard which is used for pybind11 implicit conversion
  1542. py::detail::loader_life_support guard{};
  1543. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().compute_mode =
  1544. py::cast<decltype(BatchConvBias::compute_mode)>(py::handle(compute_mode));
  1545. } CATCH_ALL(-1)
  1546. }
  1547. if (strategy) {
  1548. try {
  1549. // TODO: remove this guard which is used for pybind11 implicit conversion
  1550. py::detail::loader_life_support guard{};
  1551. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().strategy =
  1552. py::cast<decltype(BatchConvBias::strategy)>(py::handle(strategy));
  1553. } CATCH_ALL(-1)
  1554. }
  1555. if (workspace_limit) {
  1556. try {
  1557. // TODO: remove this guard which is used for pybind11 implicit conversion
  1558. py::detail::loader_life_support guard{};
  1559. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().workspace_limit =
  1560. py::cast<decltype(BatchConvBias::workspace_limit)>(py::handle(workspace_limit));
  1561. } CATCH_ALL(-1)
  1562. }
  1563. if (dtype) {
  1564. try {
  1565. // TODO: remove this guard which is used for pybind11 implicit conversion
  1566. py::detail::loader_life_support guard{};
  1567. reinterpret_cast<PyOp(BatchConvBias)*>(self)->inst().dtype =
  1568. py::cast<decltype(BatchConvBias::dtype)>(py::handle(dtype));
  1569. } CATCH_ALL(-1)
  1570. }
  1571. if (scope) {
  1572. try {
  1573. reinterpret_cast<PyOp(OpDef)*>(self)->op
  1574. ->set_scope(py::cast<std::string>(py::handle(scope)));
  1575. } CATCH_ALL(-1)
  1576. }
  1577. return 0;
  1578. }
  1579. PyGetSetDef PyOp(BatchConvBias)::py_getsetters[] = {
  1580. {const_cast<char*>("nonlineMode"), py_get_generic(BatchConvBias, nonlineMode), py_set_generic(BatchConvBias, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  1581. {const_cast<char*>("mode"), py_get_generic(BatchConvBias, mode), py_set_generic(BatchConvBias, mode), const_cast<char*>("mode"), NULL},
  1582. {const_cast<char*>("pad_h"), py_get_generic(BatchConvBias, pad_h), py_set_generic(BatchConvBias, pad_h), const_cast<char*>("pad_h"), NULL},
  1583. {const_cast<char*>("pad_w"), py_get_generic(BatchConvBias, pad_w), py_set_generic(BatchConvBias, pad_w), const_cast<char*>("pad_w"), NULL},
  1584. {const_cast<char*>("stride_h"), py_get_generic(BatchConvBias, stride_h), py_set_generic(BatchConvBias, stride_h), const_cast<char*>("stride_h"), NULL},
  1585. {const_cast<char*>("stride_w"), py_get_generic(BatchConvBias, stride_w), py_set_generic(BatchConvBias, stride_w), const_cast<char*>("stride_w"), NULL},
  1586. {const_cast<char*>("dilate_h"), py_get_generic(BatchConvBias, dilate_h), py_set_generic(BatchConvBias, dilate_h), const_cast<char*>("dilate_h"), NULL},
  1587. {const_cast<char*>("dilate_w"), py_get_generic(BatchConvBias, dilate_w), py_set_generic(BatchConvBias, dilate_w), const_cast<char*>("dilate_w"), NULL},
  1588. {const_cast<char*>("sparse"), py_get_generic(BatchConvBias, sparse), py_set_generic(BatchConvBias, sparse), const_cast<char*>("sparse"), NULL},
  1589. {const_cast<char*>("format"), py_get_generic(BatchConvBias, format), py_set_generic(BatchConvBias, format), const_cast<char*>("format"), NULL},
  1590. {const_cast<char*>("compute_mode"), py_get_generic(BatchConvBias, compute_mode), py_set_generic(BatchConvBias, compute_mode), const_cast<char*>("compute_mode"), NULL},
  1591. {const_cast<char*>("strategy"), py_get_generic(BatchConvBias, strategy), py_set_generic(BatchConvBias, strategy), const_cast<char*>("strategy"), NULL},
  1592. {const_cast<char*>("workspace_limit"), py_get_generic(BatchConvBias, workspace_limit), py_set_generic(BatchConvBias, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  1593. {const_cast<char*>("dtype"), py_get_generic(BatchConvBias, dtype), py_set_generic(BatchConvBias, dtype), const_cast<char*>("dtype"), NULL},
  1594. {NULL} /* Sentinel */
  1595. };
  1596. PyMethodDef PyOp(BatchConvBias)::tp_methods[] = {
  1597. {const_cast<char*>("__getstate__"), PyOp(BatchConvBias)::getstate, METH_NOARGS, "BatchConvBias getstate"},
  1598. {const_cast<char*>("__setstate__"), PyOp(BatchConvBias)::setstate, METH_VARARGS, "BatchConvBias setstate"},
  1599. {NULL} /* Sentinel */
  1600. };
  1601. void _init_py_BatchConvBias(py::module m) {
  1602. using py_op = PyOp(BatchConvBias);
  1603. auto& py_type = PyOpType(BatchConvBias);
  1604. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  1605. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchConvBias";
  1606. py_type.tp_basicsize = sizeof(PyOp(BatchConvBias));
  1607. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  1608. py_type.tp_doc = "BatchConvBias";
  1609. py_type.tp_base = &PyOpType(OpDef);
  1610. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  1611. py_type.tp_new = py_new_generic<py_op>;
  1612. py_type.tp_init = py_op::py_init;
  1613. py_type.tp_methods = py_op::tp_methods;
  1614. py_type.tp_getset = py_op::py_getsetters;
  1615. mgb_assert(PyType_Ready(&py_type) >= 0);
  1616. _init_py_BatchConvBias_NonlineMode(py_type);
  1617. _init_py_BatchConvBias_Mode(py_type);
  1618. _init_py_BatchConvBias_Sparse(py_type);
  1619. _init_py_BatchConvBias_Format(py_type);
  1620. _init_py_BatchConvBias_ComputeMode(py_type);
  1621. _init_py_BatchConvBias_Strategy(py_type);
  1622. PyType_Modified(&py_type);
  1623. m.add_object("BatchConvBias", reinterpret_cast<PyObject*>(&py_type));
  1624. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchConvBias::typeinfo(), &py_type).second);
  1625. }
  1626. template<> struct EnumTrait<BatchNorm::ParamDim> {
  1627. static constexpr const char *name = "BatchNorm.ParamDim";
  1628. static constexpr std::underlying_type_t<BatchNorm::ParamDim> max = 4 - 1;
  1629. };
  1630. template<> PyTypeObject* EnumWrapper<BatchNorm::ParamDim>::type = nullptr;
  1631. template<> const char*
  1632. EnumWrapper<BatchNorm::ParamDim>::members[] = {"DIM_11HW", "DIM_1CHW", "DIM_1C11", "DIM_111C"};
  1633. template<> std::unordered_map<std::string, BatchNorm::ParamDim>
  1634. EnumWrapper<BatchNorm::ParamDim>::mem2value = {{normalize_enum("DIM_11HW"), BatchNorm::ParamDim::DIM_11HW}, {normalize_enum("DIM_1CHW"), BatchNorm::ParamDim::DIM_1CHW}, {normalize_enum("DIM_1C11"), BatchNorm::ParamDim::DIM_1C11}, {normalize_enum("DIM_111C"), BatchNorm::ParamDim::DIM_111C}};
  1635. template<> PyObject* EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[4] = {nullptr};
  1636. void _init_py_BatchNorm_ParamDim(PyTypeObject& py_type) {
  1637. auto& e_type = EnumWrapper<BatchNorm::ParamDim>::type;
  1638. static PyMethodDef tp_methods[] = {
  1639. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchNorm::ParamDim>::py_dump, METH_NOARGS, NULL},
  1640. {NULL} /* Sentinel */
  1641. };
  1642. static PyType_Slot slots[] = {
  1643. {Py_tp_repr, (void*)EnumWrapper<BatchNorm::ParamDim>::py_repr},
  1644. {Py_tp_richcompare, (void*)EnumWrapper<BatchNorm::ParamDim>::tp_richcompare},
  1645. {Py_tp_methods, tp_methods},
  1646. {0, NULL}
  1647. };
  1648. static PyType_Spec spec = {
  1649. // name
  1650. "megengine.core._imperative_rt.ops.BatchNorm.ParamDim",
  1651. // basicsize
  1652. sizeof(EnumWrapper<BatchNorm::ParamDim>),
  1653. // itemsize
  1654. 0,
  1655. // flags
  1656. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1657. // slots
  1658. slots
  1659. };
  1660. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1661. mgb_assert(
  1662. e_type->tp_setattro(
  1663. reinterpret_cast<PyObject*>(e_type),
  1664. py::cast("__name__").release().ptr(),
  1665. py::cast("ParamDim").release().ptr()) >= 0);
  1666. mgb_assert(
  1667. e_type->tp_setattro(
  1668. reinterpret_cast<PyObject*>(e_type),
  1669. py::cast("__module__").release().ptr(),
  1670. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1671. mgb_assert(
  1672. e_type->tp_setattro(
  1673. reinterpret_cast<PyObject*>(e_type),
  1674. py::cast("__qualname__").release().ptr(),
  1675. py::cast("BatchNorm.ParamDim").release().ptr()) >= 0);
  1676. {
  1677. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1678. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_11HW;
  1679. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_11HW", inst) >= 0);
  1680. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[0] = inst;
  1681. }{
  1682. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1683. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_1CHW;
  1684. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_1CHW", inst) >= 0);
  1685. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[1] = inst;
  1686. }{
  1687. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1688. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_1C11;
  1689. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_1C11", inst) >= 0);
  1690. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[2] = inst;
  1691. }{
  1692. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1693. reinterpret_cast<EnumWrapper<BatchNorm::ParamDim>*>(inst)->value = BatchNorm::ParamDim::DIM_111C;
  1694. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_111C", inst) >= 0);
  1695. EnumWrapper<BatchNorm::ParamDim>::pyobj_insts[3] = inst;
  1696. }
  1697. Py_INCREF(e_type);
  1698. mgb_assert(PyDict_SetItemString(
  1699. py_type.tp_dict, "ParamDim", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1700. }
  1701. template<> struct EnumTrait<BatchNorm::FwdMode> {
  1702. static constexpr const char *name = "BatchNorm.FwdMode";
  1703. static constexpr std::underlying_type_t<BatchNorm::FwdMode> max = 2 - 1;
  1704. };
  1705. template<> PyTypeObject* EnumWrapper<BatchNorm::FwdMode>::type = nullptr;
  1706. template<> const char*
  1707. EnumWrapper<BatchNorm::FwdMode>::members[] = {"TRAINING", "INFERENCE"};
  1708. template<> std::unordered_map<std::string, BatchNorm::FwdMode>
  1709. EnumWrapper<BatchNorm::FwdMode>::mem2value = {{normalize_enum("TRAINING"), BatchNorm::FwdMode::TRAINING}, {normalize_enum("INFERENCE"), BatchNorm::FwdMode::INFERENCE}};
  1710. template<> PyObject* EnumWrapper<BatchNorm::FwdMode>::pyobj_insts[2] = {nullptr};
  1711. void _init_py_BatchNorm_FwdMode(PyTypeObject& py_type) {
  1712. auto& e_type = EnumWrapper<BatchNorm::FwdMode>::type;
  1713. static PyMethodDef tp_methods[] = {
  1714. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchNorm::FwdMode>::py_dump, METH_NOARGS, NULL},
  1715. {NULL} /* Sentinel */
  1716. };
  1717. static PyType_Slot slots[] = {
  1718. {Py_tp_repr, (void*)EnumWrapper<BatchNorm::FwdMode>::py_repr},
  1719. {Py_tp_richcompare, (void*)EnumWrapper<BatchNorm::FwdMode>::tp_richcompare},
  1720. {Py_tp_methods, tp_methods},
  1721. {0, NULL}
  1722. };
  1723. static PyType_Spec spec = {
  1724. // name
  1725. "megengine.core._imperative_rt.ops.BatchNorm.FwdMode",
  1726. // basicsize
  1727. sizeof(EnumWrapper<BatchNorm::FwdMode>),
  1728. // itemsize
  1729. 0,
  1730. // flags
  1731. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  1732. // slots
  1733. slots
  1734. };
  1735. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  1736. mgb_assert(
  1737. e_type->tp_setattro(
  1738. reinterpret_cast<PyObject*>(e_type),
  1739. py::cast("__name__").release().ptr(),
  1740. py::cast("FwdMode").release().ptr()) >= 0);
  1741. mgb_assert(
  1742. e_type->tp_setattro(
  1743. reinterpret_cast<PyObject*>(e_type),
  1744. py::cast("__module__").release().ptr(),
  1745. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  1746. mgb_assert(
  1747. e_type->tp_setattro(
  1748. reinterpret_cast<PyObject*>(e_type),
  1749. py::cast("__qualname__").release().ptr(),
  1750. py::cast("BatchNorm.FwdMode").release().ptr()) >= 0);
  1751. {
  1752. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1753. reinterpret_cast<EnumWrapper<BatchNorm::FwdMode>*>(inst)->value = BatchNorm::FwdMode::TRAINING;
  1754. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRAINING", inst) >= 0);
  1755. EnumWrapper<BatchNorm::FwdMode>::pyobj_insts[0] = inst;
  1756. }{
  1757. PyObject* inst = e_type->tp_alloc(e_type, 0);
  1758. reinterpret_cast<EnumWrapper<BatchNorm::FwdMode>*>(inst)->value = BatchNorm::FwdMode::INFERENCE;
  1759. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "INFERENCE", inst) >= 0);
  1760. EnumWrapper<BatchNorm::FwdMode>::pyobj_insts[1] = inst;
  1761. }
  1762. Py_INCREF(e_type);
  1763. mgb_assert(PyDict_SetItemString(
  1764. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1765. }
  1766. PyOpDefBegin(BatchNorm) // {
  1767. static PyGetSetDef py_getsetters[];
  1768. static PyMethodDef tp_methods[];
  1769. static PyObject* getstate(PyObject* self, PyObject*) {
  1770. auto& opdef = reinterpret_cast<PyOp(BatchNorm)*>(self)->inst();
  1771. static_cast<void>(opdef);
  1772. std::unordered_map<std::string, py::object> state {
  1773. {"param_dim", serialization<decltype(opdef.param_dim)>::dump(opdef.param_dim)},
  1774. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)},
  1775. {"epsilon", serialization<decltype(opdef.epsilon)>::dump(opdef.epsilon)},
  1776. {"avg_factor", serialization<decltype(opdef.avg_factor)>::dump(opdef.avg_factor)},
  1777. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)},
  1778. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)}
  1779. };
  1780. return py::cast(state).release().ptr();
  1781. }
  1782. static PyObject* setstate(PyObject* self, PyObject* args) {
  1783. PyObject* dict = PyTuple_GetItem(args, 0);
  1784. if (!dict) return NULL;
  1785. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  1786. auto& opdef = reinterpret_cast<PyOp(BatchNorm)*>(self)->inst();
  1787. static_cast<void>(opdef);
  1788. {
  1789. auto&& iter = state.find("param_dim");
  1790. if (iter != state.end()) {
  1791. opdef.param_dim = serialization<decltype(opdef.param_dim)>::load(iter->second);
  1792. }
  1793. }
  1794. {
  1795. auto&& iter = state.find("fwd_mode");
  1796. if (iter != state.end()) {
  1797. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  1798. }
  1799. }
  1800. {
  1801. auto&& iter = state.find("epsilon");
  1802. if (iter != state.end()) {
  1803. opdef.epsilon = serialization<decltype(opdef.epsilon)>::load(iter->second);
  1804. }
  1805. }
  1806. {
  1807. auto&& iter = state.find("avg_factor");
  1808. if (iter != state.end()) {
  1809. opdef.avg_factor = serialization<decltype(opdef.avg_factor)>::load(iter->second);
  1810. }
  1811. }
  1812. {
  1813. auto&& iter = state.find("scale");
  1814. if (iter != state.end()) {
  1815. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  1816. }
  1817. }
  1818. {
  1819. auto&& iter = state.find("bias");
  1820. if (iter != state.end()) {
  1821. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  1822. }
  1823. }
  1824. Py_RETURN_NONE;
  1825. }
  1826. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  1827. // };
  1828. PyOpDefEnd(BatchNorm)
  1829. int PyOp(BatchNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  1830. static const char* kwlist[] = {"param_dim", "fwd_mode", "epsilon", "avg_factor", "scale", "bias", "scope", NULL};
  1831. PyObject *param_dim = NULL, *fwd_mode = NULL, *epsilon = NULL, *avg_factor = NULL, *scale = NULL, *bias = NULL, *scope = NULL;
  1832. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOO", const_cast<char**>(kwlist), &param_dim, &fwd_mode, &epsilon, &avg_factor, &scale, &bias, &scope))
  1833. return -1;
  1834. if (param_dim) {
  1835. try {
  1836. // TODO: remove this guard which is used for pybind11 implicit conversion
  1837. py::detail::loader_life_support guard{};
  1838. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().param_dim =
  1839. py::cast<decltype(BatchNorm::param_dim)>(py::handle(param_dim));
  1840. } CATCH_ALL(-1)
  1841. }
  1842. if (fwd_mode) {
  1843. try {
  1844. // TODO: remove this guard which is used for pybind11 implicit conversion
  1845. py::detail::loader_life_support guard{};
  1846. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().fwd_mode =
  1847. py::cast<decltype(BatchNorm::fwd_mode)>(py::handle(fwd_mode));
  1848. } CATCH_ALL(-1)
  1849. }
  1850. if (epsilon) {
  1851. try {
  1852. // TODO: remove this guard which is used for pybind11 implicit conversion
  1853. py::detail::loader_life_support guard{};
  1854. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().epsilon =
  1855. py::cast<decltype(BatchNorm::epsilon)>(py::handle(epsilon));
  1856. } CATCH_ALL(-1)
  1857. }
  1858. if (avg_factor) {
  1859. try {
  1860. // TODO: remove this guard which is used for pybind11 implicit conversion
  1861. py::detail::loader_life_support guard{};
  1862. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().avg_factor =
  1863. py::cast<decltype(BatchNorm::avg_factor)>(py::handle(avg_factor));
  1864. } CATCH_ALL(-1)
  1865. }
  1866. if (scale) {
  1867. try {
  1868. // TODO: remove this guard which is used for pybind11 implicit conversion
  1869. py::detail::loader_life_support guard{};
  1870. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().scale =
  1871. py::cast<decltype(BatchNorm::scale)>(py::handle(scale));
  1872. } CATCH_ALL(-1)
  1873. }
  1874. if (bias) {
  1875. try {
  1876. // TODO: remove this guard which is used for pybind11 implicit conversion
  1877. py::detail::loader_life_support guard{};
  1878. reinterpret_cast<PyOp(BatchNorm)*>(self)->inst().bias =
  1879. py::cast<decltype(BatchNorm::bias)>(py::handle(bias));
  1880. } CATCH_ALL(-1)
  1881. }
  1882. if (scope) {
  1883. try {
  1884. reinterpret_cast<PyOp(OpDef)*>(self)->op
  1885. ->set_scope(py::cast<std::string>(py::handle(scope)));
  1886. } CATCH_ALL(-1)
  1887. }
  1888. return 0;
  1889. }
  1890. PyGetSetDef PyOp(BatchNorm)::py_getsetters[] = {
  1891. {const_cast<char*>("param_dim"), py_get_generic(BatchNorm, param_dim), py_set_generic(BatchNorm, param_dim), const_cast<char*>("param_dim"), NULL},
  1892. {const_cast<char*>("fwd_mode"), py_get_generic(BatchNorm, fwd_mode), py_set_generic(BatchNorm, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  1893. {const_cast<char*>("epsilon"), py_get_generic(BatchNorm, epsilon), py_set_generic(BatchNorm, epsilon), const_cast<char*>("epsilon"), NULL},
  1894. {const_cast<char*>("avg_factor"), py_get_generic(BatchNorm, avg_factor), py_set_generic(BatchNorm, avg_factor), const_cast<char*>("avg_factor"), NULL},
  1895. {const_cast<char*>("scale"), py_get_generic(BatchNorm, scale), py_set_generic(BatchNorm, scale), const_cast<char*>("scale"), NULL},
  1896. {const_cast<char*>("bias"), py_get_generic(BatchNorm, bias), py_set_generic(BatchNorm, bias), const_cast<char*>("bias"), NULL},
  1897. {NULL} /* Sentinel */
  1898. };
  1899. PyMethodDef PyOp(BatchNorm)::tp_methods[] = {
  1900. {const_cast<char*>("__getstate__"), PyOp(BatchNorm)::getstate, METH_NOARGS, "BatchNorm getstate"},
  1901. {const_cast<char*>("__setstate__"), PyOp(BatchNorm)::setstate, METH_VARARGS, "BatchNorm setstate"},
  1902. {NULL} /* Sentinel */
  1903. };
  1904. void _init_py_BatchNorm(py::module m) {
  1905. using py_op = PyOp(BatchNorm);
  1906. auto& py_type = PyOpType(BatchNorm);
  1907. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  1908. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchNorm";
  1909. py_type.tp_basicsize = sizeof(PyOp(BatchNorm));
  1910. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  1911. py_type.tp_doc = "BatchNorm";
  1912. py_type.tp_base = &PyOpType(OpDef);
  1913. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  1914. py_type.tp_new = py_new_generic<py_op>;
  1915. py_type.tp_init = py_op::py_init;
  1916. py_type.tp_methods = py_op::tp_methods;
  1917. py_type.tp_getset = py_op::py_getsetters;
  1918. mgb_assert(PyType_Ready(&py_type) >= 0);
  1919. _init_py_BatchNorm_ParamDim(py_type);
  1920. _init_py_BatchNorm_FwdMode(py_type);
  1921. PyType_Modified(&py_type);
  1922. m.add_object("BatchNorm", reinterpret_cast<PyObject*>(&py_type));
  1923. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchNorm::typeinfo(), &py_type).second);
  1924. }
  1925. void _init_py_BatchNormBackward_ParamDim(PyTypeObject& py_type) {
  1926. auto& e_type = EnumWrapper<BatchNormBackward::ParamDim>::type;
  1927. Py_INCREF(e_type);
  1928. mgb_assert(PyDict_SetItemString(
  1929. py_type.tp_dict, "ParamDim", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1930. }
  1931. void _init_py_BatchNormBackward_FwdMode(PyTypeObject& py_type) {
  1932. auto& e_type = EnumWrapper<BatchNormBackward::FwdMode>::type;
  1933. Py_INCREF(e_type);
  1934. mgb_assert(PyDict_SetItemString(
  1935. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  1936. }
  1937. PyOpDefBegin(BatchNormBackward) // {
  1938. static PyGetSetDef py_getsetters[];
  1939. static PyMethodDef tp_methods[];
  1940. static PyObject* getstate(PyObject* self, PyObject*) {
  1941. auto& opdef = reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst();
  1942. static_cast<void>(opdef);
  1943. std::unordered_map<std::string, py::object> state {
  1944. {"param_dim", serialization<decltype(opdef.param_dim)>::dump(opdef.param_dim)},
  1945. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)},
  1946. {"epsilon", serialization<decltype(opdef.epsilon)>::dump(opdef.epsilon)},
  1947. {"avg_factor", serialization<decltype(opdef.avg_factor)>::dump(opdef.avg_factor)},
  1948. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)},
  1949. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)}
  1950. };
  1951. return py::cast(state).release().ptr();
  1952. }
  1953. static PyObject* setstate(PyObject* self, PyObject* args) {
  1954. PyObject* dict = PyTuple_GetItem(args, 0);
  1955. if (!dict) return NULL;
  1956. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  1957. auto& opdef = reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst();
  1958. static_cast<void>(opdef);
  1959. {
  1960. auto&& iter = state.find("param_dim");
  1961. if (iter != state.end()) {
  1962. opdef.param_dim = serialization<decltype(opdef.param_dim)>::load(iter->second);
  1963. }
  1964. }
  1965. {
  1966. auto&& iter = state.find("fwd_mode");
  1967. if (iter != state.end()) {
  1968. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  1969. }
  1970. }
  1971. {
  1972. auto&& iter = state.find("epsilon");
  1973. if (iter != state.end()) {
  1974. opdef.epsilon = serialization<decltype(opdef.epsilon)>::load(iter->second);
  1975. }
  1976. }
  1977. {
  1978. auto&& iter = state.find("avg_factor");
  1979. if (iter != state.end()) {
  1980. opdef.avg_factor = serialization<decltype(opdef.avg_factor)>::load(iter->second);
  1981. }
  1982. }
  1983. {
  1984. auto&& iter = state.find("scale");
  1985. if (iter != state.end()) {
  1986. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  1987. }
  1988. }
  1989. {
  1990. auto&& iter = state.find("bias");
  1991. if (iter != state.end()) {
  1992. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  1993. }
  1994. }
  1995. Py_RETURN_NONE;
  1996. }
  1997. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  1998. // };
  1999. PyOpDefEnd(BatchNormBackward)
  2000. int PyOp(BatchNormBackward)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2001. static const char* kwlist[] = {"param_dim", "fwd_mode", "epsilon", "avg_factor", "scale", "bias", "scope", NULL};
  2002. PyObject *param_dim = NULL, *fwd_mode = NULL, *epsilon = NULL, *avg_factor = NULL, *scale = NULL, *bias = NULL, *scope = NULL;
  2003. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOO", const_cast<char**>(kwlist), &param_dim, &fwd_mode, &epsilon, &avg_factor, &scale, &bias, &scope))
  2004. return -1;
  2005. if (param_dim) {
  2006. try {
  2007. // TODO: remove this guard which is used for pybind11 implicit conversion
  2008. py::detail::loader_life_support guard{};
  2009. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().param_dim =
  2010. py::cast<decltype(BatchNormBackward::param_dim)>(py::handle(param_dim));
  2011. } CATCH_ALL(-1)
  2012. }
  2013. if (fwd_mode) {
  2014. try {
  2015. // TODO: remove this guard which is used for pybind11 implicit conversion
  2016. py::detail::loader_life_support guard{};
  2017. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().fwd_mode =
  2018. py::cast<decltype(BatchNormBackward::fwd_mode)>(py::handle(fwd_mode));
  2019. } CATCH_ALL(-1)
  2020. }
  2021. if (epsilon) {
  2022. try {
  2023. // TODO: remove this guard which is used for pybind11 implicit conversion
  2024. py::detail::loader_life_support guard{};
  2025. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().epsilon =
  2026. py::cast<decltype(BatchNormBackward::epsilon)>(py::handle(epsilon));
  2027. } CATCH_ALL(-1)
  2028. }
  2029. if (avg_factor) {
  2030. try {
  2031. // TODO: remove this guard which is used for pybind11 implicit conversion
  2032. py::detail::loader_life_support guard{};
  2033. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().avg_factor =
  2034. py::cast<decltype(BatchNormBackward::avg_factor)>(py::handle(avg_factor));
  2035. } CATCH_ALL(-1)
  2036. }
  2037. if (scale) {
  2038. try {
  2039. // TODO: remove this guard which is used for pybind11 implicit conversion
  2040. py::detail::loader_life_support guard{};
  2041. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().scale =
  2042. py::cast<decltype(BatchNormBackward::scale)>(py::handle(scale));
  2043. } CATCH_ALL(-1)
  2044. }
  2045. if (bias) {
  2046. try {
  2047. // TODO: remove this guard which is used for pybind11 implicit conversion
  2048. py::detail::loader_life_support guard{};
  2049. reinterpret_cast<PyOp(BatchNormBackward)*>(self)->inst().bias =
  2050. py::cast<decltype(BatchNormBackward::bias)>(py::handle(bias));
  2051. } CATCH_ALL(-1)
  2052. }
  2053. if (scope) {
  2054. try {
  2055. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2056. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2057. } CATCH_ALL(-1)
  2058. }
  2059. return 0;
  2060. }
  2061. PyGetSetDef PyOp(BatchNormBackward)::py_getsetters[] = {
  2062. {const_cast<char*>("param_dim"), py_get_generic(BatchNormBackward, param_dim), py_set_generic(BatchNormBackward, param_dim), const_cast<char*>("param_dim"), NULL},
  2063. {const_cast<char*>("fwd_mode"), py_get_generic(BatchNormBackward, fwd_mode), py_set_generic(BatchNormBackward, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  2064. {const_cast<char*>("epsilon"), py_get_generic(BatchNormBackward, epsilon), py_set_generic(BatchNormBackward, epsilon), const_cast<char*>("epsilon"), NULL},
  2065. {const_cast<char*>("avg_factor"), py_get_generic(BatchNormBackward, avg_factor), py_set_generic(BatchNormBackward, avg_factor), const_cast<char*>("avg_factor"), NULL},
  2066. {const_cast<char*>("scale"), py_get_generic(BatchNormBackward, scale), py_set_generic(BatchNormBackward, scale), const_cast<char*>("scale"), NULL},
  2067. {const_cast<char*>("bias"), py_get_generic(BatchNormBackward, bias), py_set_generic(BatchNormBackward, bias), const_cast<char*>("bias"), NULL},
  2068. {NULL} /* Sentinel */
  2069. };
  2070. PyMethodDef PyOp(BatchNormBackward)::tp_methods[] = {
  2071. {const_cast<char*>("__getstate__"), PyOp(BatchNormBackward)::getstate, METH_NOARGS, "BatchNormBackward getstate"},
  2072. {const_cast<char*>("__setstate__"), PyOp(BatchNormBackward)::setstate, METH_VARARGS, "BatchNormBackward setstate"},
  2073. {NULL} /* Sentinel */
  2074. };
  2075. void _init_py_BatchNormBackward(py::module m) {
  2076. using py_op = PyOp(BatchNormBackward);
  2077. auto& py_type = PyOpType(BatchNormBackward);
  2078. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2079. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchNormBackward";
  2080. py_type.tp_basicsize = sizeof(PyOp(BatchNormBackward));
  2081. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2082. py_type.tp_doc = "BatchNormBackward";
  2083. py_type.tp_base = &PyOpType(OpDef);
  2084. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2085. py_type.tp_new = py_new_generic<py_op>;
  2086. py_type.tp_init = py_op::py_init;
  2087. py_type.tp_methods = py_op::tp_methods;
  2088. py_type.tp_getset = py_op::py_getsetters;
  2089. mgb_assert(PyType_Ready(&py_type) >= 0);
  2090. _init_py_BatchNormBackward_ParamDim(py_type);
  2091. _init_py_BatchNormBackward_FwdMode(py_type);
  2092. PyType_Modified(&py_type);
  2093. m.add_object("BatchNormBackward", reinterpret_cast<PyObject*>(&py_type));
  2094. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchNormBackward::typeinfo(), &py_type).second);
  2095. }
  2096. PyOpDefBegin(BatchedIncrMeshIndexing) // {
  2097. static PyGetSetDef py_getsetters[];
  2098. static PyMethodDef tp_methods[];
  2099. static PyObject* getstate(PyObject* self, PyObject*) {
  2100. auto& opdef = reinterpret_cast<PyOp(BatchedIncrMeshIndexing)*>(self)->inst();
  2101. static_cast<void>(opdef);
  2102. std::unordered_map<std::string, py::object> state {
  2103. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  2104. };
  2105. return py::cast(state).release().ptr();
  2106. }
  2107. static PyObject* setstate(PyObject* self, PyObject* args) {
  2108. PyObject* dict = PyTuple_GetItem(args, 0);
  2109. if (!dict) return NULL;
  2110. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2111. auto& opdef = reinterpret_cast<PyOp(BatchedIncrMeshIndexing)*>(self)->inst();
  2112. static_cast<void>(opdef);
  2113. {
  2114. auto&& iter = state.find("items");
  2115. if (iter != state.end()) {
  2116. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  2117. }
  2118. }
  2119. Py_RETURN_NONE;
  2120. }
  2121. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2122. // };
  2123. PyOpDefEnd(BatchedIncrMeshIndexing)
  2124. int PyOp(BatchedIncrMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2125. static const char* kwlist[] = {"items", "scope", NULL};
  2126. PyObject *items = NULL, *scope = NULL;
  2127. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  2128. return -1;
  2129. if (items) {
  2130. try {
  2131. // TODO: remove this guard which is used for pybind11 implicit conversion
  2132. py::detail::loader_life_support guard{};
  2133. reinterpret_cast<PyOp(BatchedIncrMeshIndexing)*>(self)->inst().items =
  2134. py::cast<decltype(BatchedIncrMeshIndexing::items)>(py::handle(items));
  2135. } CATCH_ALL(-1)
  2136. }
  2137. if (scope) {
  2138. try {
  2139. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2140. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2141. } CATCH_ALL(-1)
  2142. }
  2143. return 0;
  2144. }
  2145. PyGetSetDef PyOp(BatchedIncrMeshIndexing)::py_getsetters[] = {
  2146. {const_cast<char*>("items"), py_get_generic(BatchedIncrMeshIndexing, items), py_set_generic(BatchedIncrMeshIndexing, items), const_cast<char*>("items"), NULL},
  2147. {NULL} /* Sentinel */
  2148. };
  2149. PyMethodDef PyOp(BatchedIncrMeshIndexing)::tp_methods[] = {
  2150. {const_cast<char*>("__getstate__"), PyOp(BatchedIncrMeshIndexing)::getstate, METH_NOARGS, "BatchedIncrMeshIndexing getstate"},
  2151. {const_cast<char*>("__setstate__"), PyOp(BatchedIncrMeshIndexing)::setstate, METH_VARARGS, "BatchedIncrMeshIndexing setstate"},
  2152. {NULL} /* Sentinel */
  2153. };
  2154. void _init_py_BatchedIncrMeshIndexing(py::module m) {
  2155. using py_op = PyOp(BatchedIncrMeshIndexing);
  2156. auto& py_type = PyOpType(BatchedIncrMeshIndexing);
  2157. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2158. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedIncrMeshIndexing";
  2159. py_type.tp_basicsize = sizeof(PyOp(BatchedIncrMeshIndexing));
  2160. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2161. py_type.tp_doc = "BatchedIncrMeshIndexing";
  2162. py_type.tp_base = &PyOpType(OpDef);
  2163. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2164. py_type.tp_new = py_new_generic<py_op>;
  2165. py_type.tp_init = py_op::py_init;
  2166. py_type.tp_methods = py_op::tp_methods;
  2167. py_type.tp_getset = py_op::py_getsetters;
  2168. mgb_assert(PyType_Ready(&py_type) >= 0);
  2169. PyType_Modified(&py_type);
  2170. m.add_object("BatchedIncrMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  2171. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedIncrMeshIndexing::typeinfo(), &py_type).second);
  2172. }
  2173. template<> struct EnumTrait<BatchedMatrixMul::ComputeMode> {
  2174. static constexpr const char *name = "BatchedMatrixMul.ComputeMode";
  2175. static constexpr std::underlying_type_t<BatchedMatrixMul::ComputeMode> max = 2 - 1;
  2176. };
  2177. template<> PyTypeObject* EnumWrapper<BatchedMatrixMul::ComputeMode>::type = nullptr;
  2178. template<> const char*
  2179. EnumWrapper<BatchedMatrixMul::ComputeMode>::members[] = {"DEFAULT", "FLOAT32"};
  2180. template<> std::unordered_map<std::string, BatchedMatrixMul::ComputeMode>
  2181. EnumWrapper<BatchedMatrixMul::ComputeMode>::mem2value = {{normalize_enum("DEFAULT"), BatchedMatrixMul::ComputeMode::DEFAULT}, {normalize_enum("FLOAT32"), BatchedMatrixMul::ComputeMode::FLOAT32}};
  2182. template<> PyObject* EnumWrapper<BatchedMatrixMul::ComputeMode>::pyobj_insts[2] = {nullptr};
  2183. void _init_py_BatchedMatrixMul_ComputeMode(PyTypeObject& py_type) {
  2184. auto& e_type = EnumWrapper<BatchedMatrixMul::ComputeMode>::type;
  2185. static PyMethodDef tp_methods[] = {
  2186. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchedMatrixMul::ComputeMode>::py_dump, METH_NOARGS, NULL},
  2187. {NULL} /* Sentinel */
  2188. };
  2189. static PyType_Slot slots[] = {
  2190. {Py_tp_repr, (void*)EnumWrapper<BatchedMatrixMul::ComputeMode>::py_repr},
  2191. {Py_tp_richcompare, (void*)EnumWrapper<BatchedMatrixMul::ComputeMode>::tp_richcompare},
  2192. {Py_tp_methods, tp_methods},
  2193. {0, NULL}
  2194. };
  2195. static PyType_Spec spec = {
  2196. // name
  2197. "megengine.core._imperative_rt.ops.BatchedMatrixMul.ComputeMode",
  2198. // basicsize
  2199. sizeof(EnumWrapper<BatchedMatrixMul::ComputeMode>),
  2200. // itemsize
  2201. 0,
  2202. // flags
  2203. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  2204. // slots
  2205. slots
  2206. };
  2207. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  2208. mgb_assert(
  2209. e_type->tp_setattro(
  2210. reinterpret_cast<PyObject*>(e_type),
  2211. py::cast("__name__").release().ptr(),
  2212. py::cast("ComputeMode").release().ptr()) >= 0);
  2213. mgb_assert(
  2214. e_type->tp_setattro(
  2215. reinterpret_cast<PyObject*>(e_type),
  2216. py::cast("__module__").release().ptr(),
  2217. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  2218. mgb_assert(
  2219. e_type->tp_setattro(
  2220. reinterpret_cast<PyObject*>(e_type),
  2221. py::cast("__qualname__").release().ptr(),
  2222. py::cast("BatchedMatrixMul.ComputeMode").release().ptr()) >= 0);
  2223. {
  2224. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2225. reinterpret_cast<EnumWrapper<BatchedMatrixMul::ComputeMode>*>(inst)->value = BatchedMatrixMul::ComputeMode::DEFAULT;
  2226. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  2227. EnumWrapper<BatchedMatrixMul::ComputeMode>::pyobj_insts[0] = inst;
  2228. }{
  2229. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2230. reinterpret_cast<EnumWrapper<BatchedMatrixMul::ComputeMode>*>(inst)->value = BatchedMatrixMul::ComputeMode::FLOAT32;
  2231. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT32", inst) >= 0);
  2232. EnumWrapper<BatchedMatrixMul::ComputeMode>::pyobj_insts[1] = inst;
  2233. }
  2234. Py_INCREF(e_type);
  2235. mgb_assert(PyDict_SetItemString(
  2236. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2237. }
  2238. template<> struct EnumTrait<BatchedMatrixMul::Format> {
  2239. static constexpr const char *name = "BatchedMatrixMul.Format";
  2240. static constexpr std::underlying_type_t<BatchedMatrixMul::Format> max = 5 - 1;
  2241. };
  2242. template<> PyTypeObject* EnumWrapper<BatchedMatrixMul::Format>::type = nullptr;
  2243. template<> const char*
  2244. EnumWrapper<BatchedMatrixMul::Format>::members[] = {"DEFAULT", "MK4", "MK8", "MK4_DOT", "N32K4_DOT"};
  2245. template<> std::unordered_map<std::string, BatchedMatrixMul::Format>
  2246. EnumWrapper<BatchedMatrixMul::Format>::mem2value = {{normalize_enum("DEFAULT"), BatchedMatrixMul::Format::DEFAULT}, {normalize_enum("MK4"), BatchedMatrixMul::Format::MK4}, {normalize_enum("MK8"), BatchedMatrixMul::Format::MK8}, {normalize_enum("MK4_DOT"), BatchedMatrixMul::Format::MK4_DOT}, {normalize_enum("N32K4_DOT"), BatchedMatrixMul::Format::N32K4_DOT}};
  2247. template<> PyObject* EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[5] = {nullptr};
  2248. void _init_py_BatchedMatrixMul_Format(PyTypeObject& py_type) {
  2249. auto& e_type = EnumWrapper<BatchedMatrixMul::Format>::type;
  2250. static PyMethodDef tp_methods[] = {
  2251. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<BatchedMatrixMul::Format>::py_dump, METH_NOARGS, NULL},
  2252. {NULL} /* Sentinel */
  2253. };
  2254. static PyType_Slot slots[] = {
  2255. {Py_tp_repr, (void*)EnumWrapper<BatchedMatrixMul::Format>::py_repr},
  2256. {Py_tp_richcompare, (void*)EnumWrapper<BatchedMatrixMul::Format>::tp_richcompare},
  2257. {Py_tp_methods, tp_methods},
  2258. {0, NULL}
  2259. };
  2260. static PyType_Spec spec = {
  2261. // name
  2262. "megengine.core._imperative_rt.ops.BatchedMatrixMul.Format",
  2263. // basicsize
  2264. sizeof(EnumWrapper<BatchedMatrixMul::Format>),
  2265. // itemsize
  2266. 0,
  2267. // flags
  2268. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  2269. // slots
  2270. slots
  2271. };
  2272. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  2273. mgb_assert(
  2274. e_type->tp_setattro(
  2275. reinterpret_cast<PyObject*>(e_type),
  2276. py::cast("__name__").release().ptr(),
  2277. py::cast("Format").release().ptr()) >= 0);
  2278. mgb_assert(
  2279. e_type->tp_setattro(
  2280. reinterpret_cast<PyObject*>(e_type),
  2281. py::cast("__module__").release().ptr(),
  2282. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  2283. mgb_assert(
  2284. e_type->tp_setattro(
  2285. reinterpret_cast<PyObject*>(e_type),
  2286. py::cast("__qualname__").release().ptr(),
  2287. py::cast("BatchedMatrixMul.Format").release().ptr()) >= 0);
  2288. {
  2289. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2290. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::DEFAULT;
  2291. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  2292. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[0] = inst;
  2293. }{
  2294. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2295. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::MK4;
  2296. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK4", inst) >= 0);
  2297. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[1] = inst;
  2298. }{
  2299. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2300. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::MK8;
  2301. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK8", inst) >= 0);
  2302. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[2] = inst;
  2303. }{
  2304. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2305. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::MK4_DOT;
  2306. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK4_DOT", inst) >= 0);
  2307. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[3] = inst;
  2308. }{
  2309. PyObject* inst = e_type->tp_alloc(e_type, 0);
  2310. reinterpret_cast<EnumWrapper<BatchedMatrixMul::Format>*>(inst)->value = BatchedMatrixMul::Format::N32K4_DOT;
  2311. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "N32K4_DOT", inst) >= 0);
  2312. EnumWrapper<BatchedMatrixMul::Format>::pyobj_insts[4] = inst;
  2313. }
  2314. Py_INCREF(e_type);
  2315. mgb_assert(PyDict_SetItemString(
  2316. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2317. }
  2318. void _init_py_BatchedMatrixMul_Strategy(PyTypeObject& py_type) {
  2319. auto& e_type = BitCombinedEnumWrapper<BatchedMatrixMul::Strategy>::type;
  2320. Py_INCREF(e_type);
  2321. mgb_assert(PyDict_SetItemString(
  2322. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  2323. }
  2324. PyOpDefBegin(BatchedMatrixMul) // {
  2325. static PyGetSetDef py_getsetters[];
  2326. static PyMethodDef tp_methods[];
  2327. static PyObject* getstate(PyObject* self, PyObject*) {
  2328. auto& opdef = reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst();
  2329. static_cast<void>(opdef);
  2330. std::unordered_map<std::string, py::object> state {
  2331. {"transposeA", serialization<decltype(opdef.transposeA)>::dump(opdef.transposeA)},
  2332. {"transposeB", serialization<decltype(opdef.transposeB)>::dump(opdef.transposeB)},
  2333. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  2334. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  2335. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  2336. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  2337. {"dimA", serialization<decltype(opdef.dimA)>::dump(opdef.dimA)},
  2338. {"dimB", serialization<decltype(opdef.dimB)>::dump(opdef.dimB)}
  2339. };
  2340. return py::cast(state).release().ptr();
  2341. }
  2342. static PyObject* setstate(PyObject* self, PyObject* args) {
  2343. PyObject* dict = PyTuple_GetItem(args, 0);
  2344. if (!dict) return NULL;
  2345. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2346. auto& opdef = reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst();
  2347. static_cast<void>(opdef);
  2348. {
  2349. auto&& iter = state.find("transposeA");
  2350. if (iter != state.end()) {
  2351. opdef.transposeA = serialization<decltype(opdef.transposeA)>::load(iter->second);
  2352. }
  2353. }
  2354. {
  2355. auto&& iter = state.find("transposeB");
  2356. if (iter != state.end()) {
  2357. opdef.transposeB = serialization<decltype(opdef.transposeB)>::load(iter->second);
  2358. }
  2359. }
  2360. {
  2361. auto&& iter = state.find("compute_mode");
  2362. if (iter != state.end()) {
  2363. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  2364. }
  2365. }
  2366. {
  2367. auto&& iter = state.find("format");
  2368. if (iter != state.end()) {
  2369. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  2370. }
  2371. }
  2372. {
  2373. auto&& iter = state.find("strategy");
  2374. if (iter != state.end()) {
  2375. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  2376. }
  2377. }
  2378. {
  2379. auto&& iter = state.find("workspace_limit");
  2380. if (iter != state.end()) {
  2381. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  2382. }
  2383. }
  2384. {
  2385. auto&& iter = state.find("dimA");
  2386. if (iter != state.end()) {
  2387. opdef.dimA = serialization<decltype(opdef.dimA)>::load(iter->second);
  2388. }
  2389. }
  2390. {
  2391. auto&& iter = state.find("dimB");
  2392. if (iter != state.end()) {
  2393. opdef.dimB = serialization<decltype(opdef.dimB)>::load(iter->second);
  2394. }
  2395. }
  2396. Py_RETURN_NONE;
  2397. }
  2398. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2399. // };
  2400. PyOpDefEnd(BatchedMatrixMul)
  2401. int PyOp(BatchedMatrixMul)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2402. static const char* kwlist[] = {"transposeA", "transposeB", "compute_mode", "format", "strategy", "workspace_limit", "dimA", "dimB", "scope", NULL};
  2403. PyObject *transposeA = NULL, *transposeB = NULL, *compute_mode = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *dimA = NULL, *dimB = NULL, *scope = NULL;
  2404. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &transposeA, &transposeB, &compute_mode, &format, &strategy, &workspace_limit, &dimA, &dimB, &scope))
  2405. return -1;
  2406. if (transposeA) {
  2407. try {
  2408. // TODO: remove this guard which is used for pybind11 implicit conversion
  2409. py::detail::loader_life_support guard{};
  2410. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().transposeA =
  2411. py::cast<decltype(BatchedMatrixMul::transposeA)>(py::handle(transposeA));
  2412. } CATCH_ALL(-1)
  2413. }
  2414. if (transposeB) {
  2415. try {
  2416. // TODO: remove this guard which is used for pybind11 implicit conversion
  2417. py::detail::loader_life_support guard{};
  2418. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().transposeB =
  2419. py::cast<decltype(BatchedMatrixMul::transposeB)>(py::handle(transposeB));
  2420. } CATCH_ALL(-1)
  2421. }
  2422. if (compute_mode) {
  2423. try {
  2424. // TODO: remove this guard which is used for pybind11 implicit conversion
  2425. py::detail::loader_life_support guard{};
  2426. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().compute_mode =
  2427. py::cast<decltype(BatchedMatrixMul::compute_mode)>(py::handle(compute_mode));
  2428. } CATCH_ALL(-1)
  2429. }
  2430. if (format) {
  2431. try {
  2432. // TODO: remove this guard which is used for pybind11 implicit conversion
  2433. py::detail::loader_life_support guard{};
  2434. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().format =
  2435. py::cast<decltype(BatchedMatrixMul::format)>(py::handle(format));
  2436. } CATCH_ALL(-1)
  2437. }
  2438. if (strategy) {
  2439. try {
  2440. // TODO: remove this guard which is used for pybind11 implicit conversion
  2441. py::detail::loader_life_support guard{};
  2442. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().strategy =
  2443. py::cast<decltype(BatchedMatrixMul::strategy)>(py::handle(strategy));
  2444. } CATCH_ALL(-1)
  2445. }
  2446. if (workspace_limit) {
  2447. try {
  2448. // TODO: remove this guard which is used for pybind11 implicit conversion
  2449. py::detail::loader_life_support guard{};
  2450. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().workspace_limit =
  2451. py::cast<decltype(BatchedMatrixMul::workspace_limit)>(py::handle(workspace_limit));
  2452. } CATCH_ALL(-1)
  2453. }
  2454. if (dimA) {
  2455. try {
  2456. // TODO: remove this guard which is used for pybind11 implicit conversion
  2457. py::detail::loader_life_support guard{};
  2458. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().dimA =
  2459. py::cast<decltype(BatchedMatrixMul::dimA)>(py::handle(dimA));
  2460. } CATCH_ALL(-1)
  2461. }
  2462. if (dimB) {
  2463. try {
  2464. // TODO: remove this guard which is used for pybind11 implicit conversion
  2465. py::detail::loader_life_support guard{};
  2466. reinterpret_cast<PyOp(BatchedMatrixMul)*>(self)->inst().dimB =
  2467. py::cast<decltype(BatchedMatrixMul::dimB)>(py::handle(dimB));
  2468. } CATCH_ALL(-1)
  2469. }
  2470. if (scope) {
  2471. try {
  2472. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2473. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2474. } CATCH_ALL(-1)
  2475. }
  2476. return 0;
  2477. }
  2478. PyGetSetDef PyOp(BatchedMatrixMul)::py_getsetters[] = {
  2479. {const_cast<char*>("transposeA"), py_get_generic(BatchedMatrixMul, transposeA), py_set_generic(BatchedMatrixMul, transposeA), const_cast<char*>("transposeA"), NULL},
  2480. {const_cast<char*>("transposeB"), py_get_generic(BatchedMatrixMul, transposeB), py_set_generic(BatchedMatrixMul, transposeB), const_cast<char*>("transposeB"), NULL},
  2481. {const_cast<char*>("compute_mode"), py_get_generic(BatchedMatrixMul, compute_mode), py_set_generic(BatchedMatrixMul, compute_mode), const_cast<char*>("compute_mode"), NULL},
  2482. {const_cast<char*>("format"), py_get_generic(BatchedMatrixMul, format), py_set_generic(BatchedMatrixMul, format), const_cast<char*>("format"), NULL},
  2483. {const_cast<char*>("strategy"), py_get_generic(BatchedMatrixMul, strategy), py_set_generic(BatchedMatrixMul, strategy), const_cast<char*>("strategy"), NULL},
  2484. {const_cast<char*>("workspace_limit"), py_get_generic(BatchedMatrixMul, workspace_limit), py_set_generic(BatchedMatrixMul, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  2485. {const_cast<char*>("dimA"), py_get_generic(BatchedMatrixMul, dimA), py_set_generic(BatchedMatrixMul, dimA), const_cast<char*>("dimA"), NULL},
  2486. {const_cast<char*>("dimB"), py_get_generic(BatchedMatrixMul, dimB), py_set_generic(BatchedMatrixMul, dimB), const_cast<char*>("dimB"), NULL},
  2487. {NULL} /* Sentinel */
  2488. };
  2489. PyMethodDef PyOp(BatchedMatrixMul)::tp_methods[] = {
  2490. {const_cast<char*>("__getstate__"), PyOp(BatchedMatrixMul)::getstate, METH_NOARGS, "BatchedMatrixMul getstate"},
  2491. {const_cast<char*>("__setstate__"), PyOp(BatchedMatrixMul)::setstate, METH_VARARGS, "BatchedMatrixMul setstate"},
  2492. {NULL} /* Sentinel */
  2493. };
  2494. void _init_py_BatchedMatrixMul(py::module m) {
  2495. using py_op = PyOp(BatchedMatrixMul);
  2496. auto& py_type = PyOpType(BatchedMatrixMul);
  2497. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2498. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedMatrixMul";
  2499. py_type.tp_basicsize = sizeof(PyOp(BatchedMatrixMul));
  2500. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2501. py_type.tp_doc = "BatchedMatrixMul";
  2502. py_type.tp_base = &PyOpType(OpDef);
  2503. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2504. py_type.tp_new = py_new_generic<py_op>;
  2505. py_type.tp_init = py_op::py_init;
  2506. py_type.tp_methods = py_op::tp_methods;
  2507. py_type.tp_getset = py_op::py_getsetters;
  2508. mgb_assert(PyType_Ready(&py_type) >= 0);
  2509. _init_py_BatchedMatrixMul_ComputeMode(py_type);
  2510. _init_py_BatchedMatrixMul_Format(py_type);
  2511. _init_py_BatchedMatrixMul_Strategy(py_type);
  2512. PyType_Modified(&py_type);
  2513. m.add_object("BatchedMatrixMul", reinterpret_cast<PyObject*>(&py_type));
  2514. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedMatrixMul::typeinfo(), &py_type).second);
  2515. }
  2516. PyOpDefBegin(BatchedMeshIndexing) // {
  2517. static PyGetSetDef py_getsetters[];
  2518. static PyMethodDef tp_methods[];
  2519. static PyObject* getstate(PyObject* self, PyObject*) {
  2520. auto& opdef = reinterpret_cast<PyOp(BatchedMeshIndexing)*>(self)->inst();
  2521. static_cast<void>(opdef);
  2522. std::unordered_map<std::string, py::object> state {
  2523. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  2524. };
  2525. return py::cast(state).release().ptr();
  2526. }
  2527. static PyObject* setstate(PyObject* self, PyObject* args) {
  2528. PyObject* dict = PyTuple_GetItem(args, 0);
  2529. if (!dict) return NULL;
  2530. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2531. auto& opdef = reinterpret_cast<PyOp(BatchedMeshIndexing)*>(self)->inst();
  2532. static_cast<void>(opdef);
  2533. {
  2534. auto&& iter = state.find("items");
  2535. if (iter != state.end()) {
  2536. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  2537. }
  2538. }
  2539. Py_RETURN_NONE;
  2540. }
  2541. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2542. // };
  2543. PyOpDefEnd(BatchedMeshIndexing)
  2544. int PyOp(BatchedMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2545. static const char* kwlist[] = {"items", "scope", NULL};
  2546. PyObject *items = NULL, *scope = NULL;
  2547. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  2548. return -1;
  2549. if (items) {
  2550. try {
  2551. // TODO: remove this guard which is used for pybind11 implicit conversion
  2552. py::detail::loader_life_support guard{};
  2553. reinterpret_cast<PyOp(BatchedMeshIndexing)*>(self)->inst().items =
  2554. py::cast<decltype(BatchedMeshIndexing::items)>(py::handle(items));
  2555. } CATCH_ALL(-1)
  2556. }
  2557. if (scope) {
  2558. try {
  2559. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2560. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2561. } CATCH_ALL(-1)
  2562. }
  2563. return 0;
  2564. }
  2565. PyGetSetDef PyOp(BatchedMeshIndexing)::py_getsetters[] = {
  2566. {const_cast<char*>("items"), py_get_generic(BatchedMeshIndexing, items), py_set_generic(BatchedMeshIndexing, items), const_cast<char*>("items"), NULL},
  2567. {NULL} /* Sentinel */
  2568. };
  2569. PyMethodDef PyOp(BatchedMeshIndexing)::tp_methods[] = {
  2570. {const_cast<char*>("__getstate__"), PyOp(BatchedMeshIndexing)::getstate, METH_NOARGS, "BatchedMeshIndexing getstate"},
  2571. {const_cast<char*>("__setstate__"), PyOp(BatchedMeshIndexing)::setstate, METH_VARARGS, "BatchedMeshIndexing setstate"},
  2572. {NULL} /* Sentinel */
  2573. };
  2574. void _init_py_BatchedMeshIndexing(py::module m) {
  2575. using py_op = PyOp(BatchedMeshIndexing);
  2576. auto& py_type = PyOpType(BatchedMeshIndexing);
  2577. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2578. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedMeshIndexing";
  2579. py_type.tp_basicsize = sizeof(PyOp(BatchedMeshIndexing));
  2580. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2581. py_type.tp_doc = "BatchedMeshIndexing";
  2582. py_type.tp_base = &PyOpType(OpDef);
  2583. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2584. py_type.tp_new = py_new_generic<py_op>;
  2585. py_type.tp_init = py_op::py_init;
  2586. py_type.tp_methods = py_op::tp_methods;
  2587. py_type.tp_getset = py_op::py_getsetters;
  2588. mgb_assert(PyType_Ready(&py_type) >= 0);
  2589. PyType_Modified(&py_type);
  2590. m.add_object("BatchedMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  2591. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedMeshIndexing::typeinfo(), &py_type).second);
  2592. }
  2593. PyOpDefBegin(BatchedSetMeshIndexing) // {
  2594. static PyGetSetDef py_getsetters[];
  2595. static PyMethodDef tp_methods[];
  2596. static PyObject* getstate(PyObject* self, PyObject*) {
  2597. auto& opdef = reinterpret_cast<PyOp(BatchedSetMeshIndexing)*>(self)->inst();
  2598. static_cast<void>(opdef);
  2599. std::unordered_map<std::string, py::object> state {
  2600. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  2601. };
  2602. return py::cast(state).release().ptr();
  2603. }
  2604. static PyObject* setstate(PyObject* self, PyObject* args) {
  2605. PyObject* dict = PyTuple_GetItem(args, 0);
  2606. if (!dict) return NULL;
  2607. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2608. auto& opdef = reinterpret_cast<PyOp(BatchedSetMeshIndexing)*>(self)->inst();
  2609. static_cast<void>(opdef);
  2610. {
  2611. auto&& iter = state.find("items");
  2612. if (iter != state.end()) {
  2613. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  2614. }
  2615. }
  2616. Py_RETURN_NONE;
  2617. }
  2618. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2619. // };
  2620. PyOpDefEnd(BatchedSetMeshIndexing)
  2621. int PyOp(BatchedSetMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2622. static const char* kwlist[] = {"items", "scope", NULL};
  2623. PyObject *items = NULL, *scope = NULL;
  2624. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  2625. return -1;
  2626. if (items) {
  2627. try {
  2628. // TODO: remove this guard which is used for pybind11 implicit conversion
  2629. py::detail::loader_life_support guard{};
  2630. reinterpret_cast<PyOp(BatchedSetMeshIndexing)*>(self)->inst().items =
  2631. py::cast<decltype(BatchedSetMeshIndexing::items)>(py::handle(items));
  2632. } CATCH_ALL(-1)
  2633. }
  2634. if (scope) {
  2635. try {
  2636. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2637. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2638. } CATCH_ALL(-1)
  2639. }
  2640. return 0;
  2641. }
  2642. PyGetSetDef PyOp(BatchedSetMeshIndexing)::py_getsetters[] = {
  2643. {const_cast<char*>("items"), py_get_generic(BatchedSetMeshIndexing, items), py_set_generic(BatchedSetMeshIndexing, items), const_cast<char*>("items"), NULL},
  2644. {NULL} /* Sentinel */
  2645. };
  2646. PyMethodDef PyOp(BatchedSetMeshIndexing)::tp_methods[] = {
  2647. {const_cast<char*>("__getstate__"), PyOp(BatchedSetMeshIndexing)::getstate, METH_NOARGS, "BatchedSetMeshIndexing getstate"},
  2648. {const_cast<char*>("__setstate__"), PyOp(BatchedSetMeshIndexing)::setstate, METH_VARARGS, "BatchedSetMeshIndexing setstate"},
  2649. {NULL} /* Sentinel */
  2650. };
  2651. void _init_py_BatchedSetMeshIndexing(py::module m) {
  2652. using py_op = PyOp(BatchedSetMeshIndexing);
  2653. auto& py_type = PyOpType(BatchedSetMeshIndexing);
  2654. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2655. py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedSetMeshIndexing";
  2656. py_type.tp_basicsize = sizeof(PyOp(BatchedSetMeshIndexing));
  2657. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2658. py_type.tp_doc = "BatchedSetMeshIndexing";
  2659. py_type.tp_base = &PyOpType(OpDef);
  2660. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2661. py_type.tp_new = py_new_generic<py_op>;
  2662. py_type.tp_init = py_op::py_init;
  2663. py_type.tp_methods = py_op::tp_methods;
  2664. py_type.tp_getset = py_op::py_getsetters;
  2665. mgb_assert(PyType_Ready(&py_type) >= 0);
  2666. PyType_Modified(&py_type);
  2667. m.add_object("BatchedSetMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  2668. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedSetMeshIndexing::typeinfo(), &py_type).second);
  2669. }
  2670. PyOpDefBegin(BetaRNG) // {
  2671. static PyGetSetDef py_getsetters[];
  2672. static PyMethodDef tp_methods[];
  2673. static PyObject* getstate(PyObject* self, PyObject*) {
  2674. auto& opdef = reinterpret_cast<PyOp(BetaRNG)*>(self)->inst();
  2675. static_cast<void>(opdef);
  2676. std::unordered_map<std::string, py::object> state {
  2677. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  2678. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  2679. };
  2680. return py::cast(state).release().ptr();
  2681. }
  2682. static PyObject* setstate(PyObject* self, PyObject* args) {
  2683. PyObject* dict = PyTuple_GetItem(args, 0);
  2684. if (!dict) return NULL;
  2685. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2686. auto& opdef = reinterpret_cast<PyOp(BetaRNG)*>(self)->inst();
  2687. static_cast<void>(opdef);
  2688. {
  2689. auto&& iter = state.find("seed");
  2690. if (iter != state.end()) {
  2691. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  2692. }
  2693. }
  2694. {
  2695. auto&& iter = state.find("handle");
  2696. if (iter != state.end()) {
  2697. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  2698. }
  2699. }
  2700. Py_RETURN_NONE;
  2701. }
  2702. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2703. // };
  2704. PyOpDefEnd(BetaRNG)
  2705. int PyOp(BetaRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2706. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  2707. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  2708. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  2709. return -1;
  2710. if (seed) {
  2711. try {
  2712. // TODO: remove this guard which is used for pybind11 implicit conversion
  2713. py::detail::loader_life_support guard{};
  2714. reinterpret_cast<PyOp(BetaRNG)*>(self)->inst().seed =
  2715. py::cast<decltype(BetaRNG::seed)>(py::handle(seed));
  2716. } CATCH_ALL(-1)
  2717. }
  2718. if (handle) {
  2719. try {
  2720. // TODO: remove this guard which is used for pybind11 implicit conversion
  2721. py::detail::loader_life_support guard{};
  2722. reinterpret_cast<PyOp(BetaRNG)*>(self)->inst().handle =
  2723. py::cast<decltype(BetaRNG::handle)>(py::handle(handle));
  2724. } CATCH_ALL(-1)
  2725. }
  2726. if (scope) {
  2727. try {
  2728. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2729. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2730. } CATCH_ALL(-1)
  2731. }
  2732. return 0;
  2733. }
  2734. PyGetSetDef PyOp(BetaRNG)::py_getsetters[] = {
  2735. {const_cast<char*>("seed"), py_get_generic(BetaRNG, seed), py_set_generic(BetaRNG, seed), const_cast<char*>("seed"), NULL},
  2736. {const_cast<char*>("handle"), py_get_generic(BetaRNG, handle), py_set_generic(BetaRNG, handle), const_cast<char*>("handle"), NULL},
  2737. {NULL} /* Sentinel */
  2738. };
  2739. PyMethodDef PyOp(BetaRNG)::tp_methods[] = {
  2740. {const_cast<char*>("__getstate__"), PyOp(BetaRNG)::getstate, METH_NOARGS, "BetaRNG getstate"},
  2741. {const_cast<char*>("__setstate__"), PyOp(BetaRNG)::setstate, METH_VARARGS, "BetaRNG setstate"},
  2742. {NULL} /* Sentinel */
  2743. };
  2744. void _init_py_BetaRNG(py::module m) {
  2745. using py_op = PyOp(BetaRNG);
  2746. auto& py_type = PyOpType(BetaRNG);
  2747. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2748. py_type.tp_name = "megengine.core._imperative_rt.ops.BetaRNG";
  2749. py_type.tp_basicsize = sizeof(PyOp(BetaRNG));
  2750. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2751. py_type.tp_doc = "BetaRNG";
  2752. py_type.tp_base = &PyOpType(OpDef);
  2753. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2754. py_type.tp_new = py_new_generic<py_op>;
  2755. py_type.tp_init = py_op::py_init;
  2756. py_type.tp_methods = py_op::tp_methods;
  2757. py_type.tp_getset = py_op::py_getsetters;
  2758. mgb_assert(PyType_Ready(&py_type) >= 0);
  2759. PyType_Modified(&py_type);
  2760. m.add_object("BetaRNG", reinterpret_cast<PyObject*>(&py_type));
  2761. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BetaRNG::typeinfo(), &py_type).second);
  2762. }
  2763. PyOpDefBegin(Borrow) // {
  2764. static PyGetSetDef py_getsetters[];
  2765. static PyMethodDef tp_methods[];
  2766. static PyObject* getstate(PyObject* self, PyObject*) {
  2767. auto& opdef = reinterpret_cast<PyOp(Borrow)*>(self)->inst();
  2768. static_cast<void>(opdef);
  2769. std::unordered_map<std::string, py::object> state {
  2770. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  2771. };
  2772. return py::cast(state).release().ptr();
  2773. }
  2774. static PyObject* setstate(PyObject* self, PyObject* args) {
  2775. PyObject* dict = PyTuple_GetItem(args, 0);
  2776. if (!dict) return NULL;
  2777. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2778. auto& opdef = reinterpret_cast<PyOp(Borrow)*>(self)->inst();
  2779. static_cast<void>(opdef);
  2780. {
  2781. auto&& iter = state.find("comp_node");
  2782. if (iter != state.end()) {
  2783. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  2784. }
  2785. }
  2786. Py_RETURN_NONE;
  2787. }
  2788. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2789. // };
  2790. PyOpDefEnd(Borrow)
  2791. int PyOp(Borrow)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2792. static const char* kwlist[] = {"comp_node", "scope", NULL};
  2793. PyObject *comp_node = NULL, *scope = NULL;
  2794. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &comp_node, &scope))
  2795. return -1;
  2796. if (comp_node) {
  2797. try {
  2798. // TODO: remove this guard which is used for pybind11 implicit conversion
  2799. py::detail::loader_life_support guard{};
  2800. reinterpret_cast<PyOp(Borrow)*>(self)->inst().comp_node =
  2801. py::cast<decltype(Borrow::comp_node)>(py::handle(comp_node));
  2802. } CATCH_ALL(-1)
  2803. }
  2804. if (scope) {
  2805. try {
  2806. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2807. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2808. } CATCH_ALL(-1)
  2809. }
  2810. return 0;
  2811. }
  2812. PyGetSetDef PyOp(Borrow)::py_getsetters[] = {
  2813. {const_cast<char*>("comp_node"), py_get_generic(Borrow, comp_node), py_set_generic(Borrow, comp_node), const_cast<char*>("comp_node"), NULL},
  2814. {NULL} /* Sentinel */
  2815. };
  2816. PyMethodDef PyOp(Borrow)::tp_methods[] = {
  2817. {const_cast<char*>("__getstate__"), PyOp(Borrow)::getstate, METH_NOARGS, "Borrow getstate"},
  2818. {const_cast<char*>("__setstate__"), PyOp(Borrow)::setstate, METH_VARARGS, "Borrow setstate"},
  2819. {NULL} /* Sentinel */
  2820. };
  2821. void _init_py_Borrow(py::module m) {
  2822. using py_op = PyOp(Borrow);
  2823. auto& py_type = PyOpType(Borrow);
  2824. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2825. py_type.tp_name = "megengine.core._imperative_rt.ops.Borrow";
  2826. py_type.tp_basicsize = sizeof(PyOp(Borrow));
  2827. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2828. py_type.tp_doc = "Borrow";
  2829. py_type.tp_base = &PyOpType(OpDef);
  2830. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2831. py_type.tp_new = py_new_generic<py_op>;
  2832. py_type.tp_init = py_op::py_init;
  2833. py_type.tp_methods = py_op::tp_methods;
  2834. py_type.tp_getset = py_op::py_getsetters;
  2835. mgb_assert(PyType_Ready(&py_type) >= 0);
  2836. PyType_Modified(&py_type);
  2837. m.add_object("Borrow", reinterpret_cast<PyObject*>(&py_type));
  2838. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Borrow::typeinfo(), &py_type).second);
  2839. }
  2840. PyOpDefBegin(Broadcast) // {
  2841. static PyGetSetDef py_getsetters[];
  2842. static PyMethodDef tp_methods[];
  2843. static PyObject* getstate(PyObject* self, PyObject*) {
  2844. auto& opdef = reinterpret_cast<PyOp(Broadcast)*>(self)->inst();
  2845. static_cast<void>(opdef);
  2846. std::unordered_map<std::string, py::object> state {
  2847. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)}
  2848. };
  2849. return py::cast(state).release().ptr();
  2850. }
  2851. static PyObject* setstate(PyObject* self, PyObject* args) {
  2852. PyObject* dict = PyTuple_GetItem(args, 0);
  2853. if (!dict) return NULL;
  2854. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2855. auto& opdef = reinterpret_cast<PyOp(Broadcast)*>(self)->inst();
  2856. static_cast<void>(opdef);
  2857. {
  2858. auto&& iter = state.find("shape");
  2859. if (iter != state.end()) {
  2860. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  2861. }
  2862. }
  2863. Py_RETURN_NONE;
  2864. }
  2865. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2866. // };
  2867. PyOpDefEnd(Broadcast)
  2868. int PyOp(Broadcast)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2869. static const char* kwlist[] = {"shape", "scope", NULL};
  2870. PyObject *shape = NULL, *scope = NULL;
  2871. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &shape, &scope))
  2872. return -1;
  2873. if (shape) {
  2874. try {
  2875. // TODO: remove this guard which is used for pybind11 implicit conversion
  2876. py::detail::loader_life_support guard{};
  2877. reinterpret_cast<PyOp(Broadcast)*>(self)->inst().shape =
  2878. py::cast<decltype(Broadcast::shape)>(py::handle(shape));
  2879. } CATCH_ALL(-1)
  2880. }
  2881. if (scope) {
  2882. try {
  2883. reinterpret_cast<PyOp(OpDef)*>(self)->op
  2884. ->set_scope(py::cast<std::string>(py::handle(scope)));
  2885. } CATCH_ALL(-1)
  2886. }
  2887. return 0;
  2888. }
  2889. PyGetSetDef PyOp(Broadcast)::py_getsetters[] = {
  2890. {const_cast<char*>("shape"), py_get_generic(Broadcast, shape), py_set_generic(Broadcast, shape), const_cast<char*>("shape"), NULL},
  2891. {NULL} /* Sentinel */
  2892. };
  2893. PyMethodDef PyOp(Broadcast)::tp_methods[] = {
  2894. {const_cast<char*>("__getstate__"), PyOp(Broadcast)::getstate, METH_NOARGS, "Broadcast getstate"},
  2895. {const_cast<char*>("__setstate__"), PyOp(Broadcast)::setstate, METH_VARARGS, "Broadcast setstate"},
  2896. {NULL} /* Sentinel */
  2897. };
  2898. void _init_py_Broadcast(py::module m) {
  2899. using py_op = PyOp(Broadcast);
  2900. auto& py_type = PyOpType(Broadcast);
  2901. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  2902. py_type.tp_name = "megengine.core._imperative_rt.ops.Broadcast";
  2903. py_type.tp_basicsize = sizeof(PyOp(Broadcast));
  2904. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  2905. py_type.tp_doc = "Broadcast";
  2906. py_type.tp_base = &PyOpType(OpDef);
  2907. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  2908. py_type.tp_new = py_new_generic<py_op>;
  2909. py_type.tp_init = py_op::py_init;
  2910. py_type.tp_methods = py_op::tp_methods;
  2911. py_type.tp_getset = py_op::py_getsetters;
  2912. mgb_assert(PyType_Ready(&py_type) >= 0);
  2913. PyType_Modified(&py_type);
  2914. m.add_object("Broadcast", reinterpret_cast<PyObject*>(&py_type));
  2915. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Broadcast::typeinfo(), &py_type).second);
  2916. }
  2917. PyOpDefBegin(CambriconRuntime) // {
  2918. static PyGetSetDef py_getsetters[];
  2919. static PyMethodDef tp_methods[];
  2920. static PyObject* getstate(PyObject* self, PyObject*) {
  2921. auto& opdef = reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst();
  2922. static_cast<void>(opdef);
  2923. std::unordered_map<std::string, py::object> state {
  2924. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  2925. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)},
  2926. {"symbol", serialization<decltype(opdef.symbol)>::dump(opdef.symbol)},
  2927. {"tensor_dim_mutable", serialization<decltype(opdef.tensor_dim_mutable)>::dump(opdef.tensor_dim_mutable)}
  2928. };
  2929. return py::cast(state).release().ptr();
  2930. }
  2931. static PyObject* setstate(PyObject* self, PyObject* args) {
  2932. PyObject* dict = PyTuple_GetItem(args, 0);
  2933. if (!dict) return NULL;
  2934. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  2935. auto& opdef = reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst();
  2936. static_cast<void>(opdef);
  2937. {
  2938. auto&& iter = state.find("buf");
  2939. if (iter != state.end()) {
  2940. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  2941. }
  2942. }
  2943. {
  2944. auto&& iter = state.find("buf_size");
  2945. if (iter != state.end()) {
  2946. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  2947. }
  2948. }
  2949. {
  2950. auto&& iter = state.find("symbol");
  2951. if (iter != state.end()) {
  2952. opdef.symbol = serialization<decltype(opdef.symbol)>::load(iter->second);
  2953. }
  2954. }
  2955. {
  2956. auto&& iter = state.find("tensor_dim_mutable");
  2957. if (iter != state.end()) {
  2958. opdef.tensor_dim_mutable = serialization<decltype(opdef.tensor_dim_mutable)>::load(iter->second);
  2959. }
  2960. }
  2961. Py_RETURN_NONE;
  2962. }
  2963. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  2964. // };
  2965. PyOpDefEnd(CambriconRuntime)
  2966. int PyOp(CambriconRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  2967. static const char* kwlist[] = {"buf", "buf_size", "symbol", "tensor_dim_mutable", "scope", NULL};
  2968. PyObject *buf = NULL, *buf_size = NULL, *symbol = NULL, *tensor_dim_mutable = NULL, *scope = NULL;
  2969. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &buf, &buf_size, &symbol, &tensor_dim_mutable, &scope))
  2970. return -1;
  2971. if (buf) {
  2972. try {
  2973. // TODO: remove this guard which is used for pybind11 implicit conversion
  2974. py::detail::loader_life_support guard{};
  2975. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().buf =
  2976. py::cast<decltype(CambriconRuntime::buf)>(py::handle(buf));
  2977. } CATCH_ALL(-1)
  2978. }
  2979. if (buf_size) {
  2980. try {
  2981. // TODO: remove this guard which is used for pybind11 implicit conversion
  2982. py::detail::loader_life_support guard{};
  2983. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().buf_size =
  2984. py::cast<decltype(CambriconRuntime::buf_size)>(py::handle(buf_size));
  2985. } CATCH_ALL(-1)
  2986. }
  2987. if (symbol) {
  2988. try {
  2989. // TODO: remove this guard which is used for pybind11 implicit conversion
  2990. py::detail::loader_life_support guard{};
  2991. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().symbol =
  2992. py::cast<decltype(CambriconRuntime::symbol)>(py::handle(symbol));
  2993. } CATCH_ALL(-1)
  2994. }
  2995. if (tensor_dim_mutable) {
  2996. try {
  2997. // TODO: remove this guard which is used for pybind11 implicit conversion
  2998. py::detail::loader_life_support guard{};
  2999. reinterpret_cast<PyOp(CambriconRuntime)*>(self)->inst().tensor_dim_mutable =
  3000. py::cast<decltype(CambriconRuntime::tensor_dim_mutable)>(py::handle(tensor_dim_mutable));
  3001. } CATCH_ALL(-1)
  3002. }
  3003. if (scope) {
  3004. try {
  3005. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3006. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3007. } CATCH_ALL(-1)
  3008. }
  3009. return 0;
  3010. }
  3011. PyGetSetDef PyOp(CambriconRuntime)::py_getsetters[] = {
  3012. {const_cast<char*>("buf"), py_get_generic(CambriconRuntime, buf), py_set_generic(CambriconRuntime, buf), const_cast<char*>("buf"), NULL},
  3013. {const_cast<char*>("buf_size"), py_get_generic(CambriconRuntime, buf_size), py_set_generic(CambriconRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  3014. {const_cast<char*>("symbol"), py_get_generic(CambriconRuntime, symbol), py_set_generic(CambriconRuntime, symbol), const_cast<char*>("symbol"), NULL},
  3015. {const_cast<char*>("tensor_dim_mutable"), py_get_generic(CambriconRuntime, tensor_dim_mutable), py_set_generic(CambriconRuntime, tensor_dim_mutable), const_cast<char*>("tensor_dim_mutable"), NULL},
  3016. {NULL} /* Sentinel */
  3017. };
  3018. PyMethodDef PyOp(CambriconRuntime)::tp_methods[] = {
  3019. {const_cast<char*>("__getstate__"), PyOp(CambriconRuntime)::getstate, METH_NOARGS, "CambriconRuntime getstate"},
  3020. {const_cast<char*>("__setstate__"), PyOp(CambriconRuntime)::setstate, METH_VARARGS, "CambriconRuntime setstate"},
  3021. {NULL} /* Sentinel */
  3022. };
  3023. void _init_py_CambriconRuntime(py::module m) {
  3024. using py_op = PyOp(CambriconRuntime);
  3025. auto& py_type = PyOpType(CambriconRuntime);
  3026. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3027. py_type.tp_name = "megengine.core._imperative_rt.ops.CambriconRuntime";
  3028. py_type.tp_basicsize = sizeof(PyOp(CambriconRuntime));
  3029. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3030. py_type.tp_doc = "CambriconRuntime";
  3031. py_type.tp_base = &PyOpType(OpDef);
  3032. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3033. py_type.tp_new = py_new_generic<py_op>;
  3034. py_type.tp_init = py_op::py_init;
  3035. py_type.tp_methods = py_op::tp_methods;
  3036. py_type.tp_getset = py_op::py_getsetters;
  3037. mgb_assert(PyType_Ready(&py_type) >= 0);
  3038. PyType_Modified(&py_type);
  3039. m.add_object("CambriconRuntime", reinterpret_cast<PyObject*>(&py_type));
  3040. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CambriconRuntime::typeinfo(), &py_type).second);
  3041. }
  3042. PyOpDefBegin(CheckNonFinite) // {
  3043. static PyGetSetDef py_getsetters[];
  3044. static PyMethodDef tp_methods[];
  3045. static PyObject* getstate(PyObject* self, PyObject*) {
  3046. auto& opdef = reinterpret_cast<PyOp(CheckNonFinite)*>(self)->inst();
  3047. static_cast<void>(opdef);
  3048. std::unordered_map<std::string, py::object> state {
  3049. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)}
  3050. };
  3051. return py::cast(state).release().ptr();
  3052. }
  3053. static PyObject* setstate(PyObject* self, PyObject* args) {
  3054. PyObject* dict = PyTuple_GetItem(args, 0);
  3055. if (!dict) return NULL;
  3056. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3057. auto& opdef = reinterpret_cast<PyOp(CheckNonFinite)*>(self)->inst();
  3058. static_cast<void>(opdef);
  3059. {
  3060. auto&& iter = state.find("scale");
  3061. if (iter != state.end()) {
  3062. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  3063. }
  3064. }
  3065. Py_RETURN_NONE;
  3066. }
  3067. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3068. // };
  3069. PyOpDefEnd(CheckNonFinite)
  3070. int PyOp(CheckNonFinite)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3071. static const char* kwlist[] = {"scale", "scope", NULL};
  3072. PyObject *scale = NULL, *scope = NULL;
  3073. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &scale, &scope))
  3074. return -1;
  3075. if (scale) {
  3076. try {
  3077. // TODO: remove this guard which is used for pybind11 implicit conversion
  3078. py::detail::loader_life_support guard{};
  3079. reinterpret_cast<PyOp(CheckNonFinite)*>(self)->inst().scale =
  3080. py::cast<decltype(CheckNonFinite::scale)>(py::handle(scale));
  3081. } CATCH_ALL(-1)
  3082. }
  3083. if (scope) {
  3084. try {
  3085. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3086. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3087. } CATCH_ALL(-1)
  3088. }
  3089. return 0;
  3090. }
  3091. PyGetSetDef PyOp(CheckNonFinite)::py_getsetters[] = {
  3092. {const_cast<char*>("scale"), py_get_generic(CheckNonFinite, scale), py_set_generic(CheckNonFinite, scale), const_cast<char*>("scale"), NULL},
  3093. {NULL} /* Sentinel */
  3094. };
  3095. PyMethodDef PyOp(CheckNonFinite)::tp_methods[] = {
  3096. {const_cast<char*>("__getstate__"), PyOp(CheckNonFinite)::getstate, METH_NOARGS, "CheckNonFinite getstate"},
  3097. {const_cast<char*>("__setstate__"), PyOp(CheckNonFinite)::setstate, METH_VARARGS, "CheckNonFinite setstate"},
  3098. {NULL} /* Sentinel */
  3099. };
  3100. void _init_py_CheckNonFinite(py::module m) {
  3101. using py_op = PyOp(CheckNonFinite);
  3102. auto& py_type = PyOpType(CheckNonFinite);
  3103. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3104. py_type.tp_name = "megengine.core._imperative_rt.ops.CheckNonFinite";
  3105. py_type.tp_basicsize = sizeof(PyOp(CheckNonFinite));
  3106. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3107. py_type.tp_doc = "CheckNonFinite";
  3108. py_type.tp_base = &PyOpType(OpDef);
  3109. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3110. py_type.tp_new = py_new_generic<py_op>;
  3111. py_type.tp_init = py_op::py_init;
  3112. py_type.tp_methods = py_op::tp_methods;
  3113. py_type.tp_getset = py_op::py_getsetters;
  3114. mgb_assert(PyType_Ready(&py_type) >= 0);
  3115. PyType_Modified(&py_type);
  3116. m.add_object("CheckNonFinite", reinterpret_cast<PyObject*>(&py_type));
  3117. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CheckNonFinite::typeinfo(), &py_type).second);
  3118. }
  3119. template<> struct EnumTrait<CollectiveComm::Mode> {
  3120. static constexpr const char *name = "CollectiveComm.Mode";
  3121. static constexpr std::underlying_type_t<CollectiveComm::Mode> max = 11 - 1;
  3122. };
  3123. template<> PyTypeObject* EnumWrapper<CollectiveComm::Mode>::type = nullptr;
  3124. template<> const char*
  3125. EnumWrapper<CollectiveComm::Mode>::members[] = {"REDUCE_SUM", "BROADCAST", "ALL_GATHER", "REDUCE_SCATTER_SUM", "ALL_REDUCE_SUM", "ALL_REDUCE_MAX", "ALL_REDUCE_MIN", "ALL_REDUCE_PROD", "GATHER", "SCATTER", "ALL_TO_ALL"};
  3126. template<> std::unordered_map<std::string, CollectiveComm::Mode>
  3127. EnumWrapper<CollectiveComm::Mode>::mem2value = {{normalize_enum("REDUCE_SUM"), CollectiveComm::Mode::REDUCE_SUM}, {normalize_enum("BROADCAST"), CollectiveComm::Mode::BROADCAST}, {normalize_enum("ALL_GATHER"), CollectiveComm::Mode::ALL_GATHER}, {normalize_enum("REDUCE_SCATTER_SUM"), CollectiveComm::Mode::REDUCE_SCATTER_SUM}, {normalize_enum("ALL_REDUCE_SUM"), CollectiveComm::Mode::ALL_REDUCE_SUM}, {normalize_enum("ALL_REDUCE_MAX"), CollectiveComm::Mode::ALL_REDUCE_MAX}, {normalize_enum("ALL_REDUCE_MIN"), CollectiveComm::Mode::ALL_REDUCE_MIN}, {normalize_enum("ALL_REDUCE_PROD"), CollectiveComm::Mode::ALL_REDUCE_PROD}, {normalize_enum("GATHER"), CollectiveComm::Mode::GATHER}, {normalize_enum("SCATTER"), CollectiveComm::Mode::SCATTER}, {normalize_enum("ALL_TO_ALL"), CollectiveComm::Mode::ALL_TO_ALL}};
  3128. template<> PyObject* EnumWrapper<CollectiveComm::Mode>::pyobj_insts[11] = {nullptr};
  3129. void _init_py_CollectiveComm_Mode(PyTypeObject& py_type) {
  3130. auto& e_type = EnumWrapper<CollectiveComm::Mode>::type;
  3131. static PyMethodDef tp_methods[] = {
  3132. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<CollectiveComm::Mode>::py_dump, METH_NOARGS, NULL},
  3133. {NULL} /* Sentinel */
  3134. };
  3135. static PyType_Slot slots[] = {
  3136. {Py_tp_repr, (void*)EnumWrapper<CollectiveComm::Mode>::py_repr},
  3137. {Py_tp_richcompare, (void*)EnumWrapper<CollectiveComm::Mode>::tp_richcompare},
  3138. {Py_tp_methods, tp_methods},
  3139. {0, NULL}
  3140. };
  3141. static PyType_Spec spec = {
  3142. // name
  3143. "megengine.core._imperative_rt.ops.CollectiveComm.Mode",
  3144. // basicsize
  3145. sizeof(EnumWrapper<CollectiveComm::Mode>),
  3146. // itemsize
  3147. 0,
  3148. // flags
  3149. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  3150. // slots
  3151. slots
  3152. };
  3153. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  3154. mgb_assert(
  3155. e_type->tp_setattro(
  3156. reinterpret_cast<PyObject*>(e_type),
  3157. py::cast("__name__").release().ptr(),
  3158. py::cast("Mode").release().ptr()) >= 0);
  3159. mgb_assert(
  3160. e_type->tp_setattro(
  3161. reinterpret_cast<PyObject*>(e_type),
  3162. py::cast("__module__").release().ptr(),
  3163. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  3164. mgb_assert(
  3165. e_type->tp_setattro(
  3166. reinterpret_cast<PyObject*>(e_type),
  3167. py::cast("__qualname__").release().ptr(),
  3168. py::cast("CollectiveComm.Mode").release().ptr()) >= 0);
  3169. {
  3170. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3171. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::REDUCE_SUM;
  3172. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REDUCE_SUM", inst) >= 0);
  3173. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[0] = inst;
  3174. }{
  3175. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3176. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::BROADCAST;
  3177. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BROADCAST", inst) >= 0);
  3178. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[1] = inst;
  3179. }{
  3180. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3181. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_GATHER;
  3182. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_GATHER", inst) >= 0);
  3183. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[2] = inst;
  3184. }{
  3185. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3186. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::REDUCE_SCATTER_SUM;
  3187. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REDUCE_SCATTER_SUM", inst) >= 0);
  3188. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[3] = inst;
  3189. }{
  3190. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3191. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_SUM;
  3192. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_SUM", inst) >= 0);
  3193. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[4] = inst;
  3194. }{
  3195. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3196. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_MAX;
  3197. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_MAX", inst) >= 0);
  3198. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[5] = inst;
  3199. }{
  3200. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3201. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_MIN;
  3202. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_MIN", inst) >= 0);
  3203. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[6] = inst;
  3204. }{
  3205. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3206. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_PROD;
  3207. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_PROD", inst) >= 0);
  3208. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[7] = inst;
  3209. }{
  3210. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3211. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::GATHER;
  3212. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GATHER", inst) >= 0);
  3213. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[8] = inst;
  3214. }{
  3215. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3216. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::SCATTER;
  3217. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SCATTER", inst) >= 0);
  3218. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[9] = inst;
  3219. }{
  3220. PyObject* inst = e_type->tp_alloc(e_type, 0);
  3221. reinterpret_cast<EnumWrapper<CollectiveComm::Mode>*>(inst)->value = CollectiveComm::Mode::ALL_TO_ALL;
  3222. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_TO_ALL", inst) >= 0);
  3223. EnumWrapper<CollectiveComm::Mode>::pyobj_insts[10] = inst;
  3224. }
  3225. Py_INCREF(e_type);
  3226. mgb_assert(PyDict_SetItemString(
  3227. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3228. }
  3229. PyOpDefBegin(CollectiveComm) // {
  3230. static PyGetSetDef py_getsetters[];
  3231. static PyMethodDef tp_methods[];
  3232. static PyObject* getstate(PyObject* self, PyObject*) {
  3233. auto& opdef = reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst();
  3234. static_cast<void>(opdef);
  3235. std::unordered_map<std::string, py::object> state {
  3236. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  3237. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  3238. {"nr_devices", serialization<decltype(opdef.nr_devices)>::dump(opdef.nr_devices)},
  3239. {"rank", serialization<decltype(opdef.rank)>::dump(opdef.rank)},
  3240. {"is_root", serialization<decltype(opdef.is_root)>::dump(opdef.is_root)},
  3241. {"local_grad", serialization<decltype(opdef.local_grad)>::dump(opdef.local_grad)},
  3242. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  3243. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  3244. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  3245. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)},
  3246. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  3247. };
  3248. return py::cast(state).release().ptr();
  3249. }
  3250. static PyObject* setstate(PyObject* self, PyObject* args) {
  3251. PyObject* dict = PyTuple_GetItem(args, 0);
  3252. if (!dict) return NULL;
  3253. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3254. auto& opdef = reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst();
  3255. static_cast<void>(opdef);
  3256. {
  3257. auto&& iter = state.find("mode");
  3258. if (iter != state.end()) {
  3259. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  3260. }
  3261. }
  3262. {
  3263. auto&& iter = state.find("key");
  3264. if (iter != state.end()) {
  3265. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  3266. }
  3267. }
  3268. {
  3269. auto&& iter = state.find("nr_devices");
  3270. if (iter != state.end()) {
  3271. opdef.nr_devices = serialization<decltype(opdef.nr_devices)>::load(iter->second);
  3272. }
  3273. }
  3274. {
  3275. auto&& iter = state.find("rank");
  3276. if (iter != state.end()) {
  3277. opdef.rank = serialization<decltype(opdef.rank)>::load(iter->second);
  3278. }
  3279. }
  3280. {
  3281. auto&& iter = state.find("is_root");
  3282. if (iter != state.end()) {
  3283. opdef.is_root = serialization<decltype(opdef.is_root)>::load(iter->second);
  3284. }
  3285. }
  3286. {
  3287. auto&& iter = state.find("local_grad");
  3288. if (iter != state.end()) {
  3289. opdef.local_grad = serialization<decltype(opdef.local_grad)>::load(iter->second);
  3290. }
  3291. }
  3292. {
  3293. auto&& iter = state.find("addr");
  3294. if (iter != state.end()) {
  3295. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  3296. }
  3297. }
  3298. {
  3299. auto&& iter = state.find("port");
  3300. if (iter != state.end()) {
  3301. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  3302. }
  3303. }
  3304. {
  3305. auto&& iter = state.find("dtype");
  3306. if (iter != state.end()) {
  3307. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  3308. }
  3309. }
  3310. {
  3311. auto&& iter = state.find("backend");
  3312. if (iter != state.end()) {
  3313. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  3314. }
  3315. }
  3316. {
  3317. auto&& iter = state.find("comp_node");
  3318. if (iter != state.end()) {
  3319. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  3320. }
  3321. }
  3322. Py_RETURN_NONE;
  3323. }
  3324. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3325. // };
  3326. PyOpDefEnd(CollectiveComm)
  3327. int PyOp(CollectiveComm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3328. static const char* kwlist[] = {"mode", "key", "nr_devices", "rank", "is_root", "local_grad", "addr", "port", "dtype", "backend", "comp_node", "scope", NULL};
  3329. PyObject *mode = NULL, *key = NULL, *nr_devices = NULL, *rank = NULL, *is_root = NULL, *local_grad = NULL, *addr = NULL, *port = NULL, *dtype = NULL, *backend = NULL, *comp_node = NULL, *scope = NULL;
  3330. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &key, &nr_devices, &rank, &is_root, &local_grad, &addr, &port, &dtype, &backend, &comp_node, &scope))
  3331. return -1;
  3332. if (mode) {
  3333. try {
  3334. // TODO: remove this guard which is used for pybind11 implicit conversion
  3335. py::detail::loader_life_support guard{};
  3336. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().mode =
  3337. py::cast<decltype(CollectiveComm::mode)>(py::handle(mode));
  3338. } CATCH_ALL(-1)
  3339. }
  3340. if (key) {
  3341. try {
  3342. // TODO: remove this guard which is used for pybind11 implicit conversion
  3343. py::detail::loader_life_support guard{};
  3344. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().key =
  3345. py::cast<decltype(CollectiveComm::key)>(py::handle(key));
  3346. } CATCH_ALL(-1)
  3347. }
  3348. if (nr_devices) {
  3349. try {
  3350. // TODO: remove this guard which is used for pybind11 implicit conversion
  3351. py::detail::loader_life_support guard{};
  3352. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().nr_devices =
  3353. py::cast<decltype(CollectiveComm::nr_devices)>(py::handle(nr_devices));
  3354. } CATCH_ALL(-1)
  3355. }
  3356. if (rank) {
  3357. try {
  3358. // TODO: remove this guard which is used for pybind11 implicit conversion
  3359. py::detail::loader_life_support guard{};
  3360. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().rank =
  3361. py::cast<decltype(CollectiveComm::rank)>(py::handle(rank));
  3362. } CATCH_ALL(-1)
  3363. }
  3364. if (is_root) {
  3365. try {
  3366. // TODO: remove this guard which is used for pybind11 implicit conversion
  3367. py::detail::loader_life_support guard{};
  3368. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().is_root =
  3369. py::cast<decltype(CollectiveComm::is_root)>(py::handle(is_root));
  3370. } CATCH_ALL(-1)
  3371. }
  3372. if (local_grad) {
  3373. try {
  3374. // TODO: remove this guard which is used for pybind11 implicit conversion
  3375. py::detail::loader_life_support guard{};
  3376. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().local_grad =
  3377. py::cast<decltype(CollectiveComm::local_grad)>(py::handle(local_grad));
  3378. } CATCH_ALL(-1)
  3379. }
  3380. if (addr) {
  3381. try {
  3382. // TODO: remove this guard which is used for pybind11 implicit conversion
  3383. py::detail::loader_life_support guard{};
  3384. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().addr =
  3385. py::cast<decltype(CollectiveComm::addr)>(py::handle(addr));
  3386. } CATCH_ALL(-1)
  3387. }
  3388. if (port) {
  3389. try {
  3390. // TODO: remove this guard which is used for pybind11 implicit conversion
  3391. py::detail::loader_life_support guard{};
  3392. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().port =
  3393. py::cast<decltype(CollectiveComm::port)>(py::handle(port));
  3394. } CATCH_ALL(-1)
  3395. }
  3396. if (dtype) {
  3397. try {
  3398. // TODO: remove this guard which is used for pybind11 implicit conversion
  3399. py::detail::loader_life_support guard{};
  3400. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().dtype =
  3401. py::cast<decltype(CollectiveComm::dtype)>(py::handle(dtype));
  3402. } CATCH_ALL(-1)
  3403. }
  3404. if (backend) {
  3405. try {
  3406. // TODO: remove this guard which is used for pybind11 implicit conversion
  3407. py::detail::loader_life_support guard{};
  3408. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().backend =
  3409. py::cast<decltype(CollectiveComm::backend)>(py::handle(backend));
  3410. } CATCH_ALL(-1)
  3411. }
  3412. if (comp_node) {
  3413. try {
  3414. // TODO: remove this guard which is used for pybind11 implicit conversion
  3415. py::detail::loader_life_support guard{};
  3416. reinterpret_cast<PyOp(CollectiveComm)*>(self)->inst().comp_node =
  3417. py::cast<decltype(CollectiveComm::comp_node)>(py::handle(comp_node));
  3418. } CATCH_ALL(-1)
  3419. }
  3420. if (scope) {
  3421. try {
  3422. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3423. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3424. } CATCH_ALL(-1)
  3425. }
  3426. return 0;
  3427. }
  3428. PyGetSetDef PyOp(CollectiveComm)::py_getsetters[] = {
  3429. {const_cast<char*>("mode"), py_get_generic(CollectiveComm, mode), py_set_generic(CollectiveComm, mode), const_cast<char*>("mode"), NULL},
  3430. {const_cast<char*>("key"), py_get_generic(CollectiveComm, key), py_set_generic(CollectiveComm, key), const_cast<char*>("key"), NULL},
  3431. {const_cast<char*>("nr_devices"), py_get_generic(CollectiveComm, nr_devices), py_set_generic(CollectiveComm, nr_devices), const_cast<char*>("nr_devices"), NULL},
  3432. {const_cast<char*>("rank"), py_get_generic(CollectiveComm, rank), py_set_generic(CollectiveComm, rank), const_cast<char*>("rank"), NULL},
  3433. {const_cast<char*>("is_root"), py_get_generic(CollectiveComm, is_root), py_set_generic(CollectiveComm, is_root), const_cast<char*>("is_root"), NULL},
  3434. {const_cast<char*>("local_grad"), py_get_generic(CollectiveComm, local_grad), py_set_generic(CollectiveComm, local_grad), const_cast<char*>("local_grad"), NULL},
  3435. {const_cast<char*>("addr"), py_get_generic(CollectiveComm, addr), py_set_generic(CollectiveComm, addr), const_cast<char*>("addr"), NULL},
  3436. {const_cast<char*>("port"), py_get_generic(CollectiveComm, port), py_set_generic(CollectiveComm, port), const_cast<char*>("port"), NULL},
  3437. {const_cast<char*>("dtype"), py_get_generic(CollectiveComm, dtype), py_set_generic(CollectiveComm, dtype), const_cast<char*>("dtype"), NULL},
  3438. {const_cast<char*>("backend"), py_get_generic(CollectiveComm, backend), py_set_generic(CollectiveComm, backend), const_cast<char*>("backend"), NULL},
  3439. {const_cast<char*>("comp_node"), py_get_generic(CollectiveComm, comp_node), py_set_generic(CollectiveComm, comp_node), const_cast<char*>("comp_node"), NULL},
  3440. {NULL} /* Sentinel */
  3441. };
  3442. PyMethodDef PyOp(CollectiveComm)::tp_methods[] = {
  3443. {const_cast<char*>("__getstate__"), PyOp(CollectiveComm)::getstate, METH_NOARGS, "CollectiveComm getstate"},
  3444. {const_cast<char*>("__setstate__"), PyOp(CollectiveComm)::setstate, METH_VARARGS, "CollectiveComm setstate"},
  3445. {NULL} /* Sentinel */
  3446. };
  3447. void _init_py_CollectiveComm(py::module m) {
  3448. using py_op = PyOp(CollectiveComm);
  3449. auto& py_type = PyOpType(CollectiveComm);
  3450. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3451. py_type.tp_name = "megengine.core._imperative_rt.ops.CollectiveComm";
  3452. py_type.tp_basicsize = sizeof(PyOp(CollectiveComm));
  3453. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3454. py_type.tp_doc = "CollectiveComm";
  3455. py_type.tp_base = &PyOpType(OpDef);
  3456. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3457. py_type.tp_new = py_new_generic<py_op>;
  3458. py_type.tp_init = py_op::py_init;
  3459. py_type.tp_methods = py_op::tp_methods;
  3460. py_type.tp_getset = py_op::py_getsetters;
  3461. mgb_assert(PyType_Ready(&py_type) >= 0);
  3462. _init_py_CollectiveComm_Mode(py_type);
  3463. PyType_Modified(&py_type);
  3464. m.add_object("CollectiveComm", reinterpret_cast<PyObject*>(&py_type));
  3465. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CollectiveComm::typeinfo(), &py_type).second);
  3466. }
  3467. PyOpDefBegin(Concat) // {
  3468. static PyGetSetDef py_getsetters[];
  3469. static PyMethodDef tp_methods[];
  3470. static PyObject* getstate(PyObject* self, PyObject*) {
  3471. auto& opdef = reinterpret_cast<PyOp(Concat)*>(self)->inst();
  3472. static_cast<void>(opdef);
  3473. std::unordered_map<std::string, py::object> state {
  3474. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  3475. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  3476. };
  3477. return py::cast(state).release().ptr();
  3478. }
  3479. static PyObject* setstate(PyObject* self, PyObject* args) {
  3480. PyObject* dict = PyTuple_GetItem(args, 0);
  3481. if (!dict) return NULL;
  3482. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3483. auto& opdef = reinterpret_cast<PyOp(Concat)*>(self)->inst();
  3484. static_cast<void>(opdef);
  3485. {
  3486. auto&& iter = state.find("axis");
  3487. if (iter != state.end()) {
  3488. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  3489. }
  3490. }
  3491. {
  3492. auto&& iter = state.find("comp_node");
  3493. if (iter != state.end()) {
  3494. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  3495. }
  3496. }
  3497. Py_RETURN_NONE;
  3498. }
  3499. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3500. // };
  3501. PyOpDefEnd(Concat)
  3502. int PyOp(Concat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3503. static const char* kwlist[] = {"axis", "comp_node", "scope", NULL};
  3504. PyObject *axis = NULL, *comp_node = NULL, *scope = NULL;
  3505. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &comp_node, &scope))
  3506. return -1;
  3507. if (axis) {
  3508. try {
  3509. // TODO: remove this guard which is used for pybind11 implicit conversion
  3510. py::detail::loader_life_support guard{};
  3511. reinterpret_cast<PyOp(Concat)*>(self)->inst().axis =
  3512. py::cast<decltype(Concat::axis)>(py::handle(axis));
  3513. } CATCH_ALL(-1)
  3514. }
  3515. if (comp_node) {
  3516. try {
  3517. // TODO: remove this guard which is used for pybind11 implicit conversion
  3518. py::detail::loader_life_support guard{};
  3519. reinterpret_cast<PyOp(Concat)*>(self)->inst().comp_node =
  3520. py::cast<decltype(Concat::comp_node)>(py::handle(comp_node));
  3521. } CATCH_ALL(-1)
  3522. }
  3523. if (scope) {
  3524. try {
  3525. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3526. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3527. } CATCH_ALL(-1)
  3528. }
  3529. return 0;
  3530. }
  3531. PyGetSetDef PyOp(Concat)::py_getsetters[] = {
  3532. {const_cast<char*>("axis"), py_get_generic(Concat, axis), py_set_generic(Concat, axis), const_cast<char*>("axis"), NULL},
  3533. {const_cast<char*>("comp_node"), py_get_generic(Concat, comp_node), py_set_generic(Concat, comp_node), const_cast<char*>("comp_node"), NULL},
  3534. {NULL} /* Sentinel */
  3535. };
  3536. PyMethodDef PyOp(Concat)::tp_methods[] = {
  3537. {const_cast<char*>("__getstate__"), PyOp(Concat)::getstate, METH_NOARGS, "Concat getstate"},
  3538. {const_cast<char*>("__setstate__"), PyOp(Concat)::setstate, METH_VARARGS, "Concat setstate"},
  3539. {NULL} /* Sentinel */
  3540. };
  3541. void _init_py_Concat(py::module m) {
  3542. using py_op = PyOp(Concat);
  3543. auto& py_type = PyOpType(Concat);
  3544. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3545. py_type.tp_name = "megengine.core._imperative_rt.ops.Concat";
  3546. py_type.tp_basicsize = sizeof(PyOp(Concat));
  3547. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3548. py_type.tp_doc = "Concat";
  3549. py_type.tp_base = &PyOpType(OpDef);
  3550. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3551. py_type.tp_new = py_new_generic<py_op>;
  3552. py_type.tp_init = py_op::py_init;
  3553. py_type.tp_methods = py_op::tp_methods;
  3554. py_type.tp_getset = py_op::py_getsetters;
  3555. mgb_assert(PyType_Ready(&py_type) >= 0);
  3556. PyType_Modified(&py_type);
  3557. m.add_object("Concat", reinterpret_cast<PyObject*>(&py_type));
  3558. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Concat::typeinfo(), &py_type).second);
  3559. }
  3560. PyOpDefBegin(CondTake) // {
  3561. static PyGetSetDef py_getsetters[];
  3562. static PyMethodDef tp_methods[];
  3563. static PyObject* getstate(PyObject* self, PyObject*) {
  3564. auto& opdef = reinterpret_cast<PyOp(CondTake)*>(self)->inst();
  3565. static_cast<void>(opdef);
  3566. std::unordered_map<std::string, py::object> state {
  3567. };
  3568. return py::cast(state).release().ptr();
  3569. }
  3570. static PyObject* setstate(PyObject* self, PyObject* args) {
  3571. PyObject* dict = PyTuple_GetItem(args, 0);
  3572. if (!dict) return NULL;
  3573. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3574. auto& opdef = reinterpret_cast<PyOp(CondTake)*>(self)->inst();
  3575. static_cast<void>(opdef);
  3576. Py_RETURN_NONE;
  3577. }
  3578. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3579. // };
  3580. PyOpDefEnd(CondTake)
  3581. int PyOp(CondTake)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3582. return 0;
  3583. }
  3584. PyGetSetDef PyOp(CondTake)::py_getsetters[] = {
  3585. {NULL} /* Sentinel */
  3586. };
  3587. PyMethodDef PyOp(CondTake)::tp_methods[] = {
  3588. {const_cast<char*>("__getstate__"), PyOp(CondTake)::getstate, METH_NOARGS, "CondTake getstate"},
  3589. {const_cast<char*>("__setstate__"), PyOp(CondTake)::setstate, METH_VARARGS, "CondTake setstate"},
  3590. {NULL} /* Sentinel */
  3591. };
  3592. void _init_py_CondTake(py::module m) {
  3593. using py_op = PyOp(CondTake);
  3594. auto& py_type = PyOpType(CondTake);
  3595. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3596. py_type.tp_name = "megengine.core._imperative_rt.ops.CondTake";
  3597. py_type.tp_basicsize = sizeof(PyOp(CondTake));
  3598. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3599. py_type.tp_doc = "CondTake";
  3600. py_type.tp_base = &PyOpType(OpDef);
  3601. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3602. py_type.tp_new = py_new_generic<py_op>;
  3603. py_type.tp_init = py_op::py_init;
  3604. py_type.tp_methods = py_op::tp_methods;
  3605. py_type.tp_getset = py_op::py_getsetters;
  3606. mgb_assert(PyType_Ready(&py_type) >= 0);
  3607. PyType_Modified(&py_type);
  3608. m.add_object("CondTake", reinterpret_cast<PyObject*>(&py_type));
  3609. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CondTake::typeinfo(), &py_type).second);
  3610. }
  3611. void _init_py_ConvBias_NonlineMode(PyTypeObject& py_type) {
  3612. auto& e_type = EnumWrapper<ConvBias::NonlineMode>::type;
  3613. Py_INCREF(e_type);
  3614. mgb_assert(PyDict_SetItemString(
  3615. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3616. }
  3617. void _init_py_ConvBias_Mode(PyTypeObject& py_type) {
  3618. auto& e_type = EnumWrapper<ConvBias::Mode>::type;
  3619. Py_INCREF(e_type);
  3620. mgb_assert(PyDict_SetItemString(
  3621. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3622. }
  3623. void _init_py_ConvBias_Sparse(PyTypeObject& py_type) {
  3624. auto& e_type = EnumWrapper<ConvBias::Sparse>::type;
  3625. Py_INCREF(e_type);
  3626. mgb_assert(PyDict_SetItemString(
  3627. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3628. }
  3629. void _init_py_ConvBias_Format(PyTypeObject& py_type) {
  3630. auto& e_type = EnumWrapper<ConvBias::Format>::type;
  3631. Py_INCREF(e_type);
  3632. mgb_assert(PyDict_SetItemString(
  3633. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3634. }
  3635. void _init_py_ConvBias_ComputeMode(PyTypeObject& py_type) {
  3636. auto& e_type = EnumWrapper<ConvBias::ComputeMode>::type;
  3637. Py_INCREF(e_type);
  3638. mgb_assert(PyDict_SetItemString(
  3639. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3640. }
  3641. void _init_py_ConvBias_Strategy(PyTypeObject& py_type) {
  3642. auto& e_type = BitCombinedEnumWrapper<ConvBias::Strategy>::type;
  3643. Py_INCREF(e_type);
  3644. mgb_assert(PyDict_SetItemString(
  3645. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3646. }
  3647. PyOpDefBegin(ConvBias) // {
  3648. static PyGetSetDef py_getsetters[];
  3649. static PyMethodDef tp_methods[];
  3650. static PyObject* getstate(PyObject* self, PyObject*) {
  3651. auto& opdef = reinterpret_cast<PyOp(ConvBias)*>(self)->inst();
  3652. static_cast<void>(opdef);
  3653. std::unordered_map<std::string, py::object> state {
  3654. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)},
  3655. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  3656. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  3657. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  3658. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  3659. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  3660. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  3661. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  3662. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  3663. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  3664. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  3665. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  3666. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  3667. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  3668. };
  3669. return py::cast(state).release().ptr();
  3670. }
  3671. static PyObject* setstate(PyObject* self, PyObject* args) {
  3672. PyObject* dict = PyTuple_GetItem(args, 0);
  3673. if (!dict) return NULL;
  3674. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3675. auto& opdef = reinterpret_cast<PyOp(ConvBias)*>(self)->inst();
  3676. static_cast<void>(opdef);
  3677. {
  3678. auto&& iter = state.find("nonlineMode");
  3679. if (iter != state.end()) {
  3680. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  3681. }
  3682. }
  3683. {
  3684. auto&& iter = state.find("mode");
  3685. if (iter != state.end()) {
  3686. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  3687. }
  3688. }
  3689. {
  3690. auto&& iter = state.find("sparse");
  3691. if (iter != state.end()) {
  3692. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  3693. }
  3694. }
  3695. {
  3696. auto&& iter = state.find("format");
  3697. if (iter != state.end()) {
  3698. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  3699. }
  3700. }
  3701. {
  3702. auto&& iter = state.find("pad_h");
  3703. if (iter != state.end()) {
  3704. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  3705. }
  3706. }
  3707. {
  3708. auto&& iter = state.find("pad_w");
  3709. if (iter != state.end()) {
  3710. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  3711. }
  3712. }
  3713. {
  3714. auto&& iter = state.find("stride_h");
  3715. if (iter != state.end()) {
  3716. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  3717. }
  3718. }
  3719. {
  3720. auto&& iter = state.find("stride_w");
  3721. if (iter != state.end()) {
  3722. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  3723. }
  3724. }
  3725. {
  3726. auto&& iter = state.find("dilate_h");
  3727. if (iter != state.end()) {
  3728. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  3729. }
  3730. }
  3731. {
  3732. auto&& iter = state.find("dilate_w");
  3733. if (iter != state.end()) {
  3734. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  3735. }
  3736. }
  3737. {
  3738. auto&& iter = state.find("compute_mode");
  3739. if (iter != state.end()) {
  3740. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  3741. }
  3742. }
  3743. {
  3744. auto&& iter = state.find("strategy");
  3745. if (iter != state.end()) {
  3746. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  3747. }
  3748. }
  3749. {
  3750. auto&& iter = state.find("workspace_limit");
  3751. if (iter != state.end()) {
  3752. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  3753. }
  3754. }
  3755. {
  3756. auto&& iter = state.find("dtype");
  3757. if (iter != state.end()) {
  3758. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  3759. }
  3760. }
  3761. Py_RETURN_NONE;
  3762. }
  3763. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  3764. // };
  3765. PyOpDefEnd(ConvBias)
  3766. int PyOp(ConvBias)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  3767. static const char* kwlist[] = {"nonlineMode", "mode", "sparse", "format", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL};
  3768. PyObject *nonlineMode = NULL, *mode = NULL, *sparse = NULL, *format = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL;
  3769. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &nonlineMode, &mode, &sparse, &format, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &compute_mode, &strategy, &workspace_limit, &dtype, &scope))
  3770. return -1;
  3771. if (nonlineMode) {
  3772. try {
  3773. // TODO: remove this guard which is used for pybind11 implicit conversion
  3774. py::detail::loader_life_support guard{};
  3775. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().nonlineMode =
  3776. py::cast<decltype(ConvBias::nonlineMode)>(py::handle(nonlineMode));
  3777. } CATCH_ALL(-1)
  3778. }
  3779. if (mode) {
  3780. try {
  3781. // TODO: remove this guard which is used for pybind11 implicit conversion
  3782. py::detail::loader_life_support guard{};
  3783. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().mode =
  3784. py::cast<decltype(ConvBias::mode)>(py::handle(mode));
  3785. } CATCH_ALL(-1)
  3786. }
  3787. if (sparse) {
  3788. try {
  3789. // TODO: remove this guard which is used for pybind11 implicit conversion
  3790. py::detail::loader_life_support guard{};
  3791. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().sparse =
  3792. py::cast<decltype(ConvBias::sparse)>(py::handle(sparse));
  3793. } CATCH_ALL(-1)
  3794. }
  3795. if (format) {
  3796. try {
  3797. // TODO: remove this guard which is used for pybind11 implicit conversion
  3798. py::detail::loader_life_support guard{};
  3799. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().format =
  3800. py::cast<decltype(ConvBias::format)>(py::handle(format));
  3801. } CATCH_ALL(-1)
  3802. }
  3803. if (pad_h) {
  3804. try {
  3805. // TODO: remove this guard which is used for pybind11 implicit conversion
  3806. py::detail::loader_life_support guard{};
  3807. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().pad_h =
  3808. py::cast<decltype(ConvBias::pad_h)>(py::handle(pad_h));
  3809. } CATCH_ALL(-1)
  3810. }
  3811. if (pad_w) {
  3812. try {
  3813. // TODO: remove this guard which is used for pybind11 implicit conversion
  3814. py::detail::loader_life_support guard{};
  3815. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().pad_w =
  3816. py::cast<decltype(ConvBias::pad_w)>(py::handle(pad_w));
  3817. } CATCH_ALL(-1)
  3818. }
  3819. if (stride_h) {
  3820. try {
  3821. // TODO: remove this guard which is used for pybind11 implicit conversion
  3822. py::detail::loader_life_support guard{};
  3823. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().stride_h =
  3824. py::cast<decltype(ConvBias::stride_h)>(py::handle(stride_h));
  3825. } CATCH_ALL(-1)
  3826. }
  3827. if (stride_w) {
  3828. try {
  3829. // TODO: remove this guard which is used for pybind11 implicit conversion
  3830. py::detail::loader_life_support guard{};
  3831. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().stride_w =
  3832. py::cast<decltype(ConvBias::stride_w)>(py::handle(stride_w));
  3833. } CATCH_ALL(-1)
  3834. }
  3835. if (dilate_h) {
  3836. try {
  3837. // TODO: remove this guard which is used for pybind11 implicit conversion
  3838. py::detail::loader_life_support guard{};
  3839. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().dilate_h =
  3840. py::cast<decltype(ConvBias::dilate_h)>(py::handle(dilate_h));
  3841. } CATCH_ALL(-1)
  3842. }
  3843. if (dilate_w) {
  3844. try {
  3845. // TODO: remove this guard which is used for pybind11 implicit conversion
  3846. py::detail::loader_life_support guard{};
  3847. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().dilate_w =
  3848. py::cast<decltype(ConvBias::dilate_w)>(py::handle(dilate_w));
  3849. } CATCH_ALL(-1)
  3850. }
  3851. if (compute_mode) {
  3852. try {
  3853. // TODO: remove this guard which is used for pybind11 implicit conversion
  3854. py::detail::loader_life_support guard{};
  3855. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().compute_mode =
  3856. py::cast<decltype(ConvBias::compute_mode)>(py::handle(compute_mode));
  3857. } CATCH_ALL(-1)
  3858. }
  3859. if (strategy) {
  3860. try {
  3861. // TODO: remove this guard which is used for pybind11 implicit conversion
  3862. py::detail::loader_life_support guard{};
  3863. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().strategy =
  3864. py::cast<decltype(ConvBias::strategy)>(py::handle(strategy));
  3865. } CATCH_ALL(-1)
  3866. }
  3867. if (workspace_limit) {
  3868. try {
  3869. // TODO: remove this guard which is used for pybind11 implicit conversion
  3870. py::detail::loader_life_support guard{};
  3871. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().workspace_limit =
  3872. py::cast<decltype(ConvBias::workspace_limit)>(py::handle(workspace_limit));
  3873. } CATCH_ALL(-1)
  3874. }
  3875. if (dtype) {
  3876. try {
  3877. // TODO: remove this guard which is used for pybind11 implicit conversion
  3878. py::detail::loader_life_support guard{};
  3879. reinterpret_cast<PyOp(ConvBias)*>(self)->inst().dtype =
  3880. py::cast<decltype(ConvBias::dtype)>(py::handle(dtype));
  3881. } CATCH_ALL(-1)
  3882. }
  3883. if (scope) {
  3884. try {
  3885. reinterpret_cast<PyOp(OpDef)*>(self)->op
  3886. ->set_scope(py::cast<std::string>(py::handle(scope)));
  3887. } CATCH_ALL(-1)
  3888. }
  3889. return 0;
  3890. }
  3891. PyGetSetDef PyOp(ConvBias)::py_getsetters[] = {
  3892. {const_cast<char*>("nonlineMode"), py_get_generic(ConvBias, nonlineMode), py_set_generic(ConvBias, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  3893. {const_cast<char*>("mode"), py_get_generic(ConvBias, mode), py_set_generic(ConvBias, mode), const_cast<char*>("mode"), NULL},
  3894. {const_cast<char*>("sparse"), py_get_generic(ConvBias, sparse), py_set_generic(ConvBias, sparse), const_cast<char*>("sparse"), NULL},
  3895. {const_cast<char*>("format"), py_get_generic(ConvBias, format), py_set_generic(ConvBias, format), const_cast<char*>("format"), NULL},
  3896. {const_cast<char*>("pad_h"), py_get_generic(ConvBias, pad_h), py_set_generic(ConvBias, pad_h), const_cast<char*>("pad_h"), NULL},
  3897. {const_cast<char*>("pad_w"), py_get_generic(ConvBias, pad_w), py_set_generic(ConvBias, pad_w), const_cast<char*>("pad_w"), NULL},
  3898. {const_cast<char*>("stride_h"), py_get_generic(ConvBias, stride_h), py_set_generic(ConvBias, stride_h), const_cast<char*>("stride_h"), NULL},
  3899. {const_cast<char*>("stride_w"), py_get_generic(ConvBias, stride_w), py_set_generic(ConvBias, stride_w), const_cast<char*>("stride_w"), NULL},
  3900. {const_cast<char*>("dilate_h"), py_get_generic(ConvBias, dilate_h), py_set_generic(ConvBias, dilate_h), const_cast<char*>("dilate_h"), NULL},
  3901. {const_cast<char*>("dilate_w"), py_get_generic(ConvBias, dilate_w), py_set_generic(ConvBias, dilate_w), const_cast<char*>("dilate_w"), NULL},
  3902. {const_cast<char*>("compute_mode"), py_get_generic(ConvBias, compute_mode), py_set_generic(ConvBias, compute_mode), const_cast<char*>("compute_mode"), NULL},
  3903. {const_cast<char*>("strategy"), py_get_generic(ConvBias, strategy), py_set_generic(ConvBias, strategy), const_cast<char*>("strategy"), NULL},
  3904. {const_cast<char*>("workspace_limit"), py_get_generic(ConvBias, workspace_limit), py_set_generic(ConvBias, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  3905. {const_cast<char*>("dtype"), py_get_generic(ConvBias, dtype), py_set_generic(ConvBias, dtype), const_cast<char*>("dtype"), NULL},
  3906. {NULL} /* Sentinel */
  3907. };
  3908. PyMethodDef PyOp(ConvBias)::tp_methods[] = {
  3909. {const_cast<char*>("__getstate__"), PyOp(ConvBias)::getstate, METH_NOARGS, "ConvBias getstate"},
  3910. {const_cast<char*>("__setstate__"), PyOp(ConvBias)::setstate, METH_VARARGS, "ConvBias setstate"},
  3911. {NULL} /* Sentinel */
  3912. };
  3913. void _init_py_ConvBias(py::module m) {
  3914. using py_op = PyOp(ConvBias);
  3915. auto& py_type = PyOpType(ConvBias);
  3916. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  3917. py_type.tp_name = "megengine.core._imperative_rt.ops.ConvBias";
  3918. py_type.tp_basicsize = sizeof(PyOp(ConvBias));
  3919. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  3920. py_type.tp_doc = "ConvBias";
  3921. py_type.tp_base = &PyOpType(OpDef);
  3922. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  3923. py_type.tp_new = py_new_generic<py_op>;
  3924. py_type.tp_init = py_op::py_init;
  3925. py_type.tp_methods = py_op::tp_methods;
  3926. py_type.tp_getset = py_op::py_getsetters;
  3927. mgb_assert(PyType_Ready(&py_type) >= 0);
  3928. _init_py_ConvBias_NonlineMode(py_type);
  3929. _init_py_ConvBias_Mode(py_type);
  3930. _init_py_ConvBias_Sparse(py_type);
  3931. _init_py_ConvBias_Format(py_type);
  3932. _init_py_ConvBias_ComputeMode(py_type);
  3933. _init_py_ConvBias_Strategy(py_type);
  3934. PyType_Modified(&py_type);
  3935. m.add_object("ConvBias", reinterpret_cast<PyObject*>(&py_type));
  3936. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ConvBias::typeinfo(), &py_type).second);
  3937. }
  3938. void _init_py_Convolution_Mode(PyTypeObject& py_type) {
  3939. auto& e_type = EnumWrapper<Convolution::Mode>::type;
  3940. Py_INCREF(e_type);
  3941. mgb_assert(PyDict_SetItemString(
  3942. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3943. }
  3944. void _init_py_Convolution_Sparse(PyTypeObject& py_type) {
  3945. auto& e_type = EnumWrapper<Convolution::Sparse>::type;
  3946. Py_INCREF(e_type);
  3947. mgb_assert(PyDict_SetItemString(
  3948. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3949. }
  3950. void _init_py_Convolution_Format(PyTypeObject& py_type) {
  3951. auto& e_type = EnumWrapper<Convolution::Format>::type;
  3952. Py_INCREF(e_type);
  3953. mgb_assert(PyDict_SetItemString(
  3954. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3955. }
  3956. void _init_py_Convolution_ComputeMode(PyTypeObject& py_type) {
  3957. auto& e_type = EnumWrapper<Convolution::ComputeMode>::type;
  3958. Py_INCREF(e_type);
  3959. mgb_assert(PyDict_SetItemString(
  3960. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3961. }
  3962. void _init_py_Convolution_Strategy(PyTypeObject& py_type) {
  3963. auto& e_type = BitCombinedEnumWrapper<Convolution::Strategy>::type;
  3964. Py_INCREF(e_type);
  3965. mgb_assert(PyDict_SetItemString(
  3966. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  3967. }
  3968. PyOpDefBegin(Convolution) // {
  3969. static PyGetSetDef py_getsetters[];
  3970. static PyMethodDef tp_methods[];
  3971. static PyObject* getstate(PyObject* self, PyObject*) {
  3972. auto& opdef = reinterpret_cast<PyOp(Convolution)*>(self)->inst();
  3973. static_cast<void>(opdef);
  3974. std::unordered_map<std::string, py::object> state {
  3975. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  3976. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  3977. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  3978. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  3979. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  3980. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  3981. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  3982. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  3983. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  3984. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  3985. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  3986. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  3987. };
  3988. return py::cast(state).release().ptr();
  3989. }
  3990. static PyObject* setstate(PyObject* self, PyObject* args) {
  3991. PyObject* dict = PyTuple_GetItem(args, 0);
  3992. if (!dict) return NULL;
  3993. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  3994. auto& opdef = reinterpret_cast<PyOp(Convolution)*>(self)->inst();
  3995. static_cast<void>(opdef);
  3996. {
  3997. auto&& iter = state.find("mode");
  3998. if (iter != state.end()) {
  3999. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  4000. }
  4001. }
  4002. {
  4003. auto&& iter = state.find("pad_h");
  4004. if (iter != state.end()) {
  4005. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  4006. }
  4007. }
  4008. {
  4009. auto&& iter = state.find("pad_w");
  4010. if (iter != state.end()) {
  4011. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  4012. }
  4013. }
  4014. {
  4015. auto&& iter = state.find("stride_h");
  4016. if (iter != state.end()) {
  4017. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  4018. }
  4019. }
  4020. {
  4021. auto&& iter = state.find("stride_w");
  4022. if (iter != state.end()) {
  4023. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  4024. }
  4025. }
  4026. {
  4027. auto&& iter = state.find("dilate_h");
  4028. if (iter != state.end()) {
  4029. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  4030. }
  4031. }
  4032. {
  4033. auto&& iter = state.find("dilate_w");
  4034. if (iter != state.end()) {
  4035. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  4036. }
  4037. }
  4038. {
  4039. auto&& iter = state.find("sparse");
  4040. if (iter != state.end()) {
  4041. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  4042. }
  4043. }
  4044. {
  4045. auto&& iter = state.find("format");
  4046. if (iter != state.end()) {
  4047. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  4048. }
  4049. }
  4050. {
  4051. auto&& iter = state.find("compute_mode");
  4052. if (iter != state.end()) {
  4053. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  4054. }
  4055. }
  4056. {
  4057. auto&& iter = state.find("strategy");
  4058. if (iter != state.end()) {
  4059. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  4060. }
  4061. }
  4062. {
  4063. auto&& iter = state.find("workspace_limit");
  4064. if (iter != state.end()) {
  4065. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  4066. }
  4067. }
  4068. Py_RETURN_NONE;
  4069. }
  4070. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  4071. // };
  4072. PyOpDefEnd(Convolution)
  4073. int PyOp(Convolution)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  4074. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "scope", NULL};
  4075. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  4076. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &scope))
  4077. return -1;
  4078. if (mode) {
  4079. try {
  4080. // TODO: remove this guard which is used for pybind11 implicit conversion
  4081. py::detail::loader_life_support guard{};
  4082. reinterpret_cast<PyOp(Convolution)*>(self)->inst().mode =
  4083. py::cast<decltype(Convolution::mode)>(py::handle(mode));
  4084. } CATCH_ALL(-1)
  4085. }
  4086. if (pad_h) {
  4087. try {
  4088. // TODO: remove this guard which is used for pybind11 implicit conversion
  4089. py::detail::loader_life_support guard{};
  4090. reinterpret_cast<PyOp(Convolution)*>(self)->inst().pad_h =
  4091. py::cast<decltype(Convolution::pad_h)>(py::handle(pad_h));
  4092. } CATCH_ALL(-1)
  4093. }
  4094. if (pad_w) {
  4095. try {
  4096. // TODO: remove this guard which is used for pybind11 implicit conversion
  4097. py::detail::loader_life_support guard{};
  4098. reinterpret_cast<PyOp(Convolution)*>(self)->inst().pad_w =
  4099. py::cast<decltype(Convolution::pad_w)>(py::handle(pad_w));
  4100. } CATCH_ALL(-1)
  4101. }
  4102. if (stride_h) {
  4103. try {
  4104. // TODO: remove this guard which is used for pybind11 implicit conversion
  4105. py::detail::loader_life_support guard{};
  4106. reinterpret_cast<PyOp(Convolution)*>(self)->inst().stride_h =
  4107. py::cast<decltype(Convolution::stride_h)>(py::handle(stride_h));
  4108. } CATCH_ALL(-1)
  4109. }
  4110. if (stride_w) {
  4111. try {
  4112. // TODO: remove this guard which is used for pybind11 implicit conversion
  4113. py::detail::loader_life_support guard{};
  4114. reinterpret_cast<PyOp(Convolution)*>(self)->inst().stride_w =
  4115. py::cast<decltype(Convolution::stride_w)>(py::handle(stride_w));
  4116. } CATCH_ALL(-1)
  4117. }
  4118. if (dilate_h) {
  4119. try {
  4120. // TODO: remove this guard which is used for pybind11 implicit conversion
  4121. py::detail::loader_life_support guard{};
  4122. reinterpret_cast<PyOp(Convolution)*>(self)->inst().dilate_h =
  4123. py::cast<decltype(Convolution::dilate_h)>(py::handle(dilate_h));
  4124. } CATCH_ALL(-1)
  4125. }
  4126. if (dilate_w) {
  4127. try {
  4128. // TODO: remove this guard which is used for pybind11 implicit conversion
  4129. py::detail::loader_life_support guard{};
  4130. reinterpret_cast<PyOp(Convolution)*>(self)->inst().dilate_w =
  4131. py::cast<decltype(Convolution::dilate_w)>(py::handle(dilate_w));
  4132. } CATCH_ALL(-1)
  4133. }
  4134. if (sparse) {
  4135. try {
  4136. // TODO: remove this guard which is used for pybind11 implicit conversion
  4137. py::detail::loader_life_support guard{};
  4138. reinterpret_cast<PyOp(Convolution)*>(self)->inst().sparse =
  4139. py::cast<decltype(Convolution::sparse)>(py::handle(sparse));
  4140. } CATCH_ALL(-1)
  4141. }
  4142. if (format) {
  4143. try {
  4144. // TODO: remove this guard which is used for pybind11 implicit conversion
  4145. py::detail::loader_life_support guard{};
  4146. reinterpret_cast<PyOp(Convolution)*>(self)->inst().format =
  4147. py::cast<decltype(Convolution::format)>(py::handle(format));
  4148. } CATCH_ALL(-1)
  4149. }
  4150. if (compute_mode) {
  4151. try {
  4152. // TODO: remove this guard which is used for pybind11 implicit conversion
  4153. py::detail::loader_life_support guard{};
  4154. reinterpret_cast<PyOp(Convolution)*>(self)->inst().compute_mode =
  4155. py::cast<decltype(Convolution::compute_mode)>(py::handle(compute_mode));
  4156. } CATCH_ALL(-1)
  4157. }
  4158. if (strategy) {
  4159. try {
  4160. // TODO: remove this guard which is used for pybind11 implicit conversion
  4161. py::detail::loader_life_support guard{};
  4162. reinterpret_cast<PyOp(Convolution)*>(self)->inst().strategy =
  4163. py::cast<decltype(Convolution::strategy)>(py::handle(strategy));
  4164. } CATCH_ALL(-1)
  4165. }
  4166. if (workspace_limit) {
  4167. try {
  4168. // TODO: remove this guard which is used for pybind11 implicit conversion
  4169. py::detail::loader_life_support guard{};
  4170. reinterpret_cast<PyOp(Convolution)*>(self)->inst().workspace_limit =
  4171. py::cast<decltype(Convolution::workspace_limit)>(py::handle(workspace_limit));
  4172. } CATCH_ALL(-1)
  4173. }
  4174. if (scope) {
  4175. try {
  4176. reinterpret_cast<PyOp(OpDef)*>(self)->op
  4177. ->set_scope(py::cast<std::string>(py::handle(scope)));
  4178. } CATCH_ALL(-1)
  4179. }
  4180. return 0;
  4181. }
  4182. PyGetSetDef PyOp(Convolution)::py_getsetters[] = {
  4183. {const_cast<char*>("mode"), py_get_generic(Convolution, mode), py_set_generic(Convolution, mode), const_cast<char*>("mode"), NULL},
  4184. {const_cast<char*>("pad_h"), py_get_generic(Convolution, pad_h), py_set_generic(Convolution, pad_h), const_cast<char*>("pad_h"), NULL},
  4185. {const_cast<char*>("pad_w"), py_get_generic(Convolution, pad_w), py_set_generic(Convolution, pad_w), const_cast<char*>("pad_w"), NULL},
  4186. {const_cast<char*>("stride_h"), py_get_generic(Convolution, stride_h), py_set_generic(Convolution, stride_h), const_cast<char*>("stride_h"), NULL},
  4187. {const_cast<char*>("stride_w"), py_get_generic(Convolution, stride_w), py_set_generic(Convolution, stride_w), const_cast<char*>("stride_w"), NULL},
  4188. {const_cast<char*>("dilate_h"), py_get_generic(Convolution, dilate_h), py_set_generic(Convolution, dilate_h), const_cast<char*>("dilate_h"), NULL},
  4189. {const_cast<char*>("dilate_w"), py_get_generic(Convolution, dilate_w), py_set_generic(Convolution, dilate_w), const_cast<char*>("dilate_w"), NULL},
  4190. {const_cast<char*>("sparse"), py_get_generic(Convolution, sparse), py_set_generic(Convolution, sparse), const_cast<char*>("sparse"), NULL},
  4191. {const_cast<char*>("format"), py_get_generic(Convolution, format), py_set_generic(Convolution, format), const_cast<char*>("format"), NULL},
  4192. {const_cast<char*>("compute_mode"), py_get_generic(Convolution, compute_mode), py_set_generic(Convolution, compute_mode), const_cast<char*>("compute_mode"), NULL},
  4193. {const_cast<char*>("strategy"), py_get_generic(Convolution, strategy), py_set_generic(Convolution, strategy), const_cast<char*>("strategy"), NULL},
  4194. {const_cast<char*>("workspace_limit"), py_get_generic(Convolution, workspace_limit), py_set_generic(Convolution, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  4195. {NULL} /* Sentinel */
  4196. };
  4197. PyMethodDef PyOp(Convolution)::tp_methods[] = {
  4198. {const_cast<char*>("__getstate__"), PyOp(Convolution)::getstate, METH_NOARGS, "Convolution getstate"},
  4199. {const_cast<char*>("__setstate__"), PyOp(Convolution)::setstate, METH_VARARGS, "Convolution setstate"},
  4200. {NULL} /* Sentinel */
  4201. };
  4202. void _init_py_Convolution(py::module m) {
  4203. using py_op = PyOp(Convolution);
  4204. auto& py_type = PyOpType(Convolution);
  4205. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  4206. py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution";
  4207. py_type.tp_basicsize = sizeof(PyOp(Convolution));
  4208. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  4209. py_type.tp_doc = "Convolution";
  4210. py_type.tp_base = &PyOpType(OpDef);
  4211. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  4212. py_type.tp_new = py_new_generic<py_op>;
  4213. py_type.tp_init = py_op::py_init;
  4214. py_type.tp_methods = py_op::tp_methods;
  4215. py_type.tp_getset = py_op::py_getsetters;
  4216. mgb_assert(PyType_Ready(&py_type) >= 0);
  4217. _init_py_Convolution_Mode(py_type);
  4218. _init_py_Convolution_Sparse(py_type);
  4219. _init_py_Convolution_Format(py_type);
  4220. _init_py_Convolution_ComputeMode(py_type);
  4221. _init_py_Convolution_Strategy(py_type);
  4222. PyType_Modified(&py_type);
  4223. m.add_object("Convolution", reinterpret_cast<PyObject*>(&py_type));
  4224. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution::typeinfo(), &py_type).second);
  4225. }
  4226. template<> struct EnumTrait<Convolution3D::Mode> {
  4227. static constexpr const char *name = "Convolution3D.Mode";
  4228. static constexpr std::underlying_type_t<Convolution3D::Mode> max = 2 - 1;
  4229. };
  4230. template<> PyTypeObject* EnumWrapper<Convolution3D::Mode>::type = nullptr;
  4231. template<> const char*
  4232. EnumWrapper<Convolution3D::Mode>::members[] = {"CROSS_CORRELATION", "CONVOLUTION"};
  4233. template<> std::unordered_map<std::string, Convolution3D::Mode>
  4234. EnumWrapper<Convolution3D::Mode>::mem2value = {{normalize_enum("CROSS_CORRELATION"), Convolution3D::Mode::CROSS_CORRELATION}, {normalize_enum("CONVOLUTION"), Convolution3D::Mode::CONVOLUTION}};
  4235. template<> PyObject* EnumWrapper<Convolution3D::Mode>::pyobj_insts[2] = {nullptr};
  4236. void _init_py_Convolution3D_Mode(PyTypeObject& py_type) {
  4237. auto& e_type = EnumWrapper<Convolution3D::Mode>::type;
  4238. static PyMethodDef tp_methods[] = {
  4239. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::Mode>::py_dump, METH_NOARGS, NULL},
  4240. {NULL} /* Sentinel */
  4241. };
  4242. static PyType_Slot slots[] = {
  4243. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::Mode>::py_repr},
  4244. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::Mode>::tp_richcompare},
  4245. {Py_tp_methods, tp_methods},
  4246. {0, NULL}
  4247. };
  4248. static PyType_Spec spec = {
  4249. // name
  4250. "megengine.core._imperative_rt.ops.Convolution3D.Mode",
  4251. // basicsize
  4252. sizeof(EnumWrapper<Convolution3D::Mode>),
  4253. // itemsize
  4254. 0,
  4255. // flags
  4256. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4257. // slots
  4258. slots
  4259. };
  4260. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4261. mgb_assert(
  4262. e_type->tp_setattro(
  4263. reinterpret_cast<PyObject*>(e_type),
  4264. py::cast("__name__").release().ptr(),
  4265. py::cast("Mode").release().ptr()) >= 0);
  4266. mgb_assert(
  4267. e_type->tp_setattro(
  4268. reinterpret_cast<PyObject*>(e_type),
  4269. py::cast("__module__").release().ptr(),
  4270. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4271. mgb_assert(
  4272. e_type->tp_setattro(
  4273. reinterpret_cast<PyObject*>(e_type),
  4274. py::cast("__qualname__").release().ptr(),
  4275. py::cast("Convolution3D.Mode").release().ptr()) >= 0);
  4276. {
  4277. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4278. reinterpret_cast<EnumWrapper<Convolution3D::Mode>*>(inst)->value = Convolution3D::Mode::CROSS_CORRELATION;
  4279. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CROSS_CORRELATION", inst) >= 0);
  4280. EnumWrapper<Convolution3D::Mode>::pyobj_insts[0] = inst;
  4281. }{
  4282. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4283. reinterpret_cast<EnumWrapper<Convolution3D::Mode>*>(inst)->value = Convolution3D::Mode::CONVOLUTION;
  4284. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONVOLUTION", inst) >= 0);
  4285. EnumWrapper<Convolution3D::Mode>::pyobj_insts[1] = inst;
  4286. }
  4287. Py_INCREF(e_type);
  4288. mgb_assert(PyDict_SetItemString(
  4289. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4290. }
  4291. template<> struct EnumTrait<Convolution3D::Sparse> {
  4292. static constexpr const char *name = "Convolution3D.Sparse";
  4293. static constexpr std::underlying_type_t<Convolution3D::Sparse> max = 2 - 1;
  4294. };
  4295. template<> PyTypeObject* EnumWrapper<Convolution3D::Sparse>::type = nullptr;
  4296. template<> const char*
  4297. EnumWrapper<Convolution3D::Sparse>::members[] = {"DENSE", "GROUP"};
  4298. template<> std::unordered_map<std::string, Convolution3D::Sparse>
  4299. EnumWrapper<Convolution3D::Sparse>::mem2value = {{normalize_enum("DENSE"), Convolution3D::Sparse::DENSE}, {normalize_enum("GROUP"), Convolution3D::Sparse::GROUP}};
  4300. template<> PyObject* EnumWrapper<Convolution3D::Sparse>::pyobj_insts[2] = {nullptr};
  4301. void _init_py_Convolution3D_Sparse(PyTypeObject& py_type) {
  4302. auto& e_type = EnumWrapper<Convolution3D::Sparse>::type;
  4303. static PyMethodDef tp_methods[] = {
  4304. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::Sparse>::py_dump, METH_NOARGS, NULL},
  4305. {NULL} /* Sentinel */
  4306. };
  4307. static PyType_Slot slots[] = {
  4308. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::Sparse>::py_repr},
  4309. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::Sparse>::tp_richcompare},
  4310. {Py_tp_methods, tp_methods},
  4311. {0, NULL}
  4312. };
  4313. static PyType_Spec spec = {
  4314. // name
  4315. "megengine.core._imperative_rt.ops.Convolution3D.Sparse",
  4316. // basicsize
  4317. sizeof(EnumWrapper<Convolution3D::Sparse>),
  4318. // itemsize
  4319. 0,
  4320. // flags
  4321. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4322. // slots
  4323. slots
  4324. };
  4325. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4326. mgb_assert(
  4327. e_type->tp_setattro(
  4328. reinterpret_cast<PyObject*>(e_type),
  4329. py::cast("__name__").release().ptr(),
  4330. py::cast("Sparse").release().ptr()) >= 0);
  4331. mgb_assert(
  4332. e_type->tp_setattro(
  4333. reinterpret_cast<PyObject*>(e_type),
  4334. py::cast("__module__").release().ptr(),
  4335. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4336. mgb_assert(
  4337. e_type->tp_setattro(
  4338. reinterpret_cast<PyObject*>(e_type),
  4339. py::cast("__qualname__").release().ptr(),
  4340. py::cast("Convolution3D.Sparse").release().ptr()) >= 0);
  4341. {
  4342. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4343. reinterpret_cast<EnumWrapper<Convolution3D::Sparse>*>(inst)->value = Convolution3D::Sparse::DENSE;
  4344. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DENSE", inst) >= 0);
  4345. EnumWrapper<Convolution3D::Sparse>::pyobj_insts[0] = inst;
  4346. }{
  4347. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4348. reinterpret_cast<EnumWrapper<Convolution3D::Sparse>*>(inst)->value = Convolution3D::Sparse::GROUP;
  4349. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GROUP", inst) >= 0);
  4350. EnumWrapper<Convolution3D::Sparse>::pyobj_insts[1] = inst;
  4351. }
  4352. Py_INCREF(e_type);
  4353. mgb_assert(PyDict_SetItemString(
  4354. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4355. }
  4356. template<> struct EnumTrait<Convolution3D::DataType> {
  4357. static constexpr const char *name = "Convolution3D.DataType";
  4358. static constexpr std::underlying_type_t<Convolution3D::DataType> max = 2 - 1;
  4359. };
  4360. template<> PyTypeObject* EnumWrapper<Convolution3D::DataType>::type = nullptr;
  4361. template<> const char*
  4362. EnumWrapper<Convolution3D::DataType>::members[] = {"FLOAT", "FLOAT_IO16xC32"};
  4363. template<> std::unordered_map<std::string, Convolution3D::DataType>
  4364. EnumWrapper<Convolution3D::DataType>::mem2value = {{normalize_enum("FLOAT"), Convolution3D::DataType::FLOAT}, {normalize_enum("FLOAT_IO16xC32"), Convolution3D::DataType::FLOAT_IO16xC32}};
  4365. template<> PyObject* EnumWrapper<Convolution3D::DataType>::pyobj_insts[2] = {nullptr};
  4366. void _init_py_Convolution3D_DataType(PyTypeObject& py_type) {
  4367. auto& e_type = EnumWrapper<Convolution3D::DataType>::type;
  4368. static PyMethodDef tp_methods[] = {
  4369. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::DataType>::py_dump, METH_NOARGS, NULL},
  4370. {NULL} /* Sentinel */
  4371. };
  4372. static PyType_Slot slots[] = {
  4373. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::DataType>::py_repr},
  4374. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::DataType>::tp_richcompare},
  4375. {Py_tp_methods, tp_methods},
  4376. {0, NULL}
  4377. };
  4378. static PyType_Spec spec = {
  4379. // name
  4380. "megengine.core._imperative_rt.ops.Convolution3D.DataType",
  4381. // basicsize
  4382. sizeof(EnumWrapper<Convolution3D::DataType>),
  4383. // itemsize
  4384. 0,
  4385. // flags
  4386. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4387. // slots
  4388. slots
  4389. };
  4390. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4391. mgb_assert(
  4392. e_type->tp_setattro(
  4393. reinterpret_cast<PyObject*>(e_type),
  4394. py::cast("__name__").release().ptr(),
  4395. py::cast("DataType").release().ptr()) >= 0);
  4396. mgb_assert(
  4397. e_type->tp_setattro(
  4398. reinterpret_cast<PyObject*>(e_type),
  4399. py::cast("__module__").release().ptr(),
  4400. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4401. mgb_assert(
  4402. e_type->tp_setattro(
  4403. reinterpret_cast<PyObject*>(e_type),
  4404. py::cast("__qualname__").release().ptr(),
  4405. py::cast("Convolution3D.DataType").release().ptr()) >= 0);
  4406. {
  4407. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4408. reinterpret_cast<EnumWrapper<Convolution3D::DataType>*>(inst)->value = Convolution3D::DataType::FLOAT;
  4409. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT", inst) >= 0);
  4410. EnumWrapper<Convolution3D::DataType>::pyobj_insts[0] = inst;
  4411. }{
  4412. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4413. reinterpret_cast<EnumWrapper<Convolution3D::DataType>*>(inst)->value = Convolution3D::DataType::FLOAT_IO16xC32;
  4414. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_IO16xC32", inst) >= 0);
  4415. EnumWrapper<Convolution3D::DataType>::pyobj_insts[1] = inst;
  4416. }
  4417. Py_INCREF(e_type);
  4418. mgb_assert(PyDict_SetItemString(
  4419. py_type.tp_dict, "DataType", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4420. }
  4421. template<> struct EnumTrait<Convolution3D::Format> {
  4422. static constexpr const char *name = "Convolution3D.Format";
  4423. static constexpr std::underlying_type_t<Convolution3D::Format> max = 2 - 1;
  4424. };
  4425. template<> PyTypeObject* EnumWrapper<Convolution3D::Format>::type = nullptr;
  4426. template<> const char*
  4427. EnumWrapper<Convolution3D::Format>::members[] = {"NCDHW", "NDHWC"};
  4428. template<> std::unordered_map<std::string, Convolution3D::Format>
  4429. EnumWrapper<Convolution3D::Format>::mem2value = {{normalize_enum("NCDHW"), Convolution3D::Format::NCDHW}, {normalize_enum("NDHWC"), Convolution3D::Format::NDHWC}};
  4430. template<> PyObject* EnumWrapper<Convolution3D::Format>::pyobj_insts[2] = {nullptr};
  4431. void _init_py_Convolution3D_Format(PyTypeObject& py_type) {
  4432. auto& e_type = EnumWrapper<Convolution3D::Format>::type;
  4433. static PyMethodDef tp_methods[] = {
  4434. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Convolution3D::Format>::py_dump, METH_NOARGS, NULL},
  4435. {NULL} /* Sentinel */
  4436. };
  4437. static PyType_Slot slots[] = {
  4438. {Py_tp_repr, (void*)EnumWrapper<Convolution3D::Format>::py_repr},
  4439. {Py_tp_richcompare, (void*)EnumWrapper<Convolution3D::Format>::tp_richcompare},
  4440. {Py_tp_methods, tp_methods},
  4441. {0, NULL}
  4442. };
  4443. static PyType_Spec spec = {
  4444. // name
  4445. "megengine.core._imperative_rt.ops.Convolution3D.Format",
  4446. // basicsize
  4447. sizeof(EnumWrapper<Convolution3D::Format>),
  4448. // itemsize
  4449. 0,
  4450. // flags
  4451. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  4452. // slots
  4453. slots
  4454. };
  4455. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  4456. mgb_assert(
  4457. e_type->tp_setattro(
  4458. reinterpret_cast<PyObject*>(e_type),
  4459. py::cast("__name__").release().ptr(),
  4460. py::cast("Format").release().ptr()) >= 0);
  4461. mgb_assert(
  4462. e_type->tp_setattro(
  4463. reinterpret_cast<PyObject*>(e_type),
  4464. py::cast("__module__").release().ptr(),
  4465. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  4466. mgb_assert(
  4467. e_type->tp_setattro(
  4468. reinterpret_cast<PyObject*>(e_type),
  4469. py::cast("__qualname__").release().ptr(),
  4470. py::cast("Convolution3D.Format").release().ptr()) >= 0);
  4471. {
  4472. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4473. reinterpret_cast<EnumWrapper<Convolution3D::Format>*>(inst)->value = Convolution3D::Format::NCDHW;
  4474. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCDHW", inst) >= 0);
  4475. EnumWrapper<Convolution3D::Format>::pyobj_insts[0] = inst;
  4476. }{
  4477. PyObject* inst = e_type->tp_alloc(e_type, 0);
  4478. reinterpret_cast<EnumWrapper<Convolution3D::Format>*>(inst)->value = Convolution3D::Format::NDHWC;
  4479. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NDHWC", inst) >= 0);
  4480. EnumWrapper<Convolution3D::Format>::pyobj_insts[1] = inst;
  4481. }
  4482. Py_INCREF(e_type);
  4483. mgb_assert(PyDict_SetItemString(
  4484. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4485. }
  4486. void _init_py_Convolution3D_Strategy(PyTypeObject& py_type) {
  4487. auto& e_type = BitCombinedEnumWrapper<Convolution3D::Strategy>::type;
  4488. Py_INCREF(e_type);
  4489. mgb_assert(PyDict_SetItemString(
  4490. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4491. }
  4492. PyOpDefBegin(Convolution3D) // {
  4493. static PyGetSetDef py_getsetters[];
  4494. static PyMethodDef tp_methods[];
  4495. static PyObject* getstate(PyObject* self, PyObject*) {
  4496. auto& opdef = reinterpret_cast<PyOp(Convolution3D)*>(self)->inst();
  4497. static_cast<void>(opdef);
  4498. std::unordered_map<std::string, py::object> state {
  4499. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  4500. {"pad_d", serialization<decltype(opdef.pad_d)>::dump(opdef.pad_d)},
  4501. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  4502. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  4503. {"stride_d", serialization<decltype(opdef.stride_d)>::dump(opdef.stride_d)},
  4504. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  4505. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  4506. {"dilate_d", serialization<decltype(opdef.dilate_d)>::dump(opdef.dilate_d)},
  4507. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  4508. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  4509. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  4510. {"data_type", serialization<decltype(opdef.data_type)>::dump(opdef.data_type)},
  4511. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  4512. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  4513. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  4514. };
  4515. return py::cast(state).release().ptr();
  4516. }
  4517. static PyObject* setstate(PyObject* self, PyObject* args) {
  4518. PyObject* dict = PyTuple_GetItem(args, 0);
  4519. if (!dict) return NULL;
  4520. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  4521. auto& opdef = reinterpret_cast<PyOp(Convolution3D)*>(self)->inst();
  4522. static_cast<void>(opdef);
  4523. {
  4524. auto&& iter = state.find("mode");
  4525. if (iter != state.end()) {
  4526. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  4527. }
  4528. }
  4529. {
  4530. auto&& iter = state.find("pad_d");
  4531. if (iter != state.end()) {
  4532. opdef.pad_d = serialization<decltype(opdef.pad_d)>::load(iter->second);
  4533. }
  4534. }
  4535. {
  4536. auto&& iter = state.find("pad_h");
  4537. if (iter != state.end()) {
  4538. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  4539. }
  4540. }
  4541. {
  4542. auto&& iter = state.find("pad_w");
  4543. if (iter != state.end()) {
  4544. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  4545. }
  4546. }
  4547. {
  4548. auto&& iter = state.find("stride_d");
  4549. if (iter != state.end()) {
  4550. opdef.stride_d = serialization<decltype(opdef.stride_d)>::load(iter->second);
  4551. }
  4552. }
  4553. {
  4554. auto&& iter = state.find("stride_h");
  4555. if (iter != state.end()) {
  4556. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  4557. }
  4558. }
  4559. {
  4560. auto&& iter = state.find("stride_w");
  4561. if (iter != state.end()) {
  4562. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  4563. }
  4564. }
  4565. {
  4566. auto&& iter = state.find("dilate_d");
  4567. if (iter != state.end()) {
  4568. opdef.dilate_d = serialization<decltype(opdef.dilate_d)>::load(iter->second);
  4569. }
  4570. }
  4571. {
  4572. auto&& iter = state.find("dilate_h");
  4573. if (iter != state.end()) {
  4574. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  4575. }
  4576. }
  4577. {
  4578. auto&& iter = state.find("dilate_w");
  4579. if (iter != state.end()) {
  4580. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  4581. }
  4582. }
  4583. {
  4584. auto&& iter = state.find("sparse");
  4585. if (iter != state.end()) {
  4586. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  4587. }
  4588. }
  4589. {
  4590. auto&& iter = state.find("data_type");
  4591. if (iter != state.end()) {
  4592. opdef.data_type = serialization<decltype(opdef.data_type)>::load(iter->second);
  4593. }
  4594. }
  4595. {
  4596. auto&& iter = state.find("format");
  4597. if (iter != state.end()) {
  4598. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  4599. }
  4600. }
  4601. {
  4602. auto&& iter = state.find("strategy");
  4603. if (iter != state.end()) {
  4604. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  4605. }
  4606. }
  4607. {
  4608. auto&& iter = state.find("workspace_limit");
  4609. if (iter != state.end()) {
  4610. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  4611. }
  4612. }
  4613. Py_RETURN_NONE;
  4614. }
  4615. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  4616. // };
  4617. PyOpDefEnd(Convolution3D)
  4618. int PyOp(Convolution3D)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  4619. static const char* kwlist[] = {"mode", "pad_d", "pad_h", "pad_w", "stride_d", "stride_h", "stride_w", "dilate_d", "dilate_h", "dilate_w", "sparse", "data_type", "format", "strategy", "workspace_limit", "scope", NULL};
  4620. PyObject *mode = NULL, *pad_d = NULL, *pad_h = NULL, *pad_w = NULL, *stride_d = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_d = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *data_type = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  4621. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_d, &pad_h, &pad_w, &stride_d, &stride_h, &stride_w, &dilate_d, &dilate_h, &dilate_w, &sparse, &data_type, &format, &strategy, &workspace_limit, &scope))
  4622. return -1;
  4623. if (mode) {
  4624. try {
  4625. // TODO: remove this guard which is used for pybind11 implicit conversion
  4626. py::detail::loader_life_support guard{};
  4627. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().mode =
  4628. py::cast<decltype(Convolution3D::mode)>(py::handle(mode));
  4629. } CATCH_ALL(-1)
  4630. }
  4631. if (pad_d) {
  4632. try {
  4633. // TODO: remove this guard which is used for pybind11 implicit conversion
  4634. py::detail::loader_life_support guard{};
  4635. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().pad_d =
  4636. py::cast<decltype(Convolution3D::pad_d)>(py::handle(pad_d));
  4637. } CATCH_ALL(-1)
  4638. }
  4639. if (pad_h) {
  4640. try {
  4641. // TODO: remove this guard which is used for pybind11 implicit conversion
  4642. py::detail::loader_life_support guard{};
  4643. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().pad_h =
  4644. py::cast<decltype(Convolution3D::pad_h)>(py::handle(pad_h));
  4645. } CATCH_ALL(-1)
  4646. }
  4647. if (pad_w) {
  4648. try {
  4649. // TODO: remove this guard which is used for pybind11 implicit conversion
  4650. py::detail::loader_life_support guard{};
  4651. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().pad_w =
  4652. py::cast<decltype(Convolution3D::pad_w)>(py::handle(pad_w));
  4653. } CATCH_ALL(-1)
  4654. }
  4655. if (stride_d) {
  4656. try {
  4657. // TODO: remove this guard which is used for pybind11 implicit conversion
  4658. py::detail::loader_life_support guard{};
  4659. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().stride_d =
  4660. py::cast<decltype(Convolution3D::stride_d)>(py::handle(stride_d));
  4661. } CATCH_ALL(-1)
  4662. }
  4663. if (stride_h) {
  4664. try {
  4665. // TODO: remove this guard which is used for pybind11 implicit conversion
  4666. py::detail::loader_life_support guard{};
  4667. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().stride_h =
  4668. py::cast<decltype(Convolution3D::stride_h)>(py::handle(stride_h));
  4669. } CATCH_ALL(-1)
  4670. }
  4671. if (stride_w) {
  4672. try {
  4673. // TODO: remove this guard which is used for pybind11 implicit conversion
  4674. py::detail::loader_life_support guard{};
  4675. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().stride_w =
  4676. py::cast<decltype(Convolution3D::stride_w)>(py::handle(stride_w));
  4677. } CATCH_ALL(-1)
  4678. }
  4679. if (dilate_d) {
  4680. try {
  4681. // TODO: remove this guard which is used for pybind11 implicit conversion
  4682. py::detail::loader_life_support guard{};
  4683. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().dilate_d =
  4684. py::cast<decltype(Convolution3D::dilate_d)>(py::handle(dilate_d));
  4685. } CATCH_ALL(-1)
  4686. }
  4687. if (dilate_h) {
  4688. try {
  4689. // TODO: remove this guard which is used for pybind11 implicit conversion
  4690. py::detail::loader_life_support guard{};
  4691. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().dilate_h =
  4692. py::cast<decltype(Convolution3D::dilate_h)>(py::handle(dilate_h));
  4693. } CATCH_ALL(-1)
  4694. }
  4695. if (dilate_w) {
  4696. try {
  4697. // TODO: remove this guard which is used for pybind11 implicit conversion
  4698. py::detail::loader_life_support guard{};
  4699. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().dilate_w =
  4700. py::cast<decltype(Convolution3D::dilate_w)>(py::handle(dilate_w));
  4701. } CATCH_ALL(-1)
  4702. }
  4703. if (sparse) {
  4704. try {
  4705. // TODO: remove this guard which is used for pybind11 implicit conversion
  4706. py::detail::loader_life_support guard{};
  4707. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().sparse =
  4708. py::cast<decltype(Convolution3D::sparse)>(py::handle(sparse));
  4709. } CATCH_ALL(-1)
  4710. }
  4711. if (data_type) {
  4712. try {
  4713. // TODO: remove this guard which is used for pybind11 implicit conversion
  4714. py::detail::loader_life_support guard{};
  4715. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().data_type =
  4716. py::cast<decltype(Convolution3D::data_type)>(py::handle(data_type));
  4717. } CATCH_ALL(-1)
  4718. }
  4719. if (format) {
  4720. try {
  4721. // TODO: remove this guard which is used for pybind11 implicit conversion
  4722. py::detail::loader_life_support guard{};
  4723. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().format =
  4724. py::cast<decltype(Convolution3D::format)>(py::handle(format));
  4725. } CATCH_ALL(-1)
  4726. }
  4727. if (strategy) {
  4728. try {
  4729. // TODO: remove this guard which is used for pybind11 implicit conversion
  4730. py::detail::loader_life_support guard{};
  4731. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().strategy =
  4732. py::cast<decltype(Convolution3D::strategy)>(py::handle(strategy));
  4733. } CATCH_ALL(-1)
  4734. }
  4735. if (workspace_limit) {
  4736. try {
  4737. // TODO: remove this guard which is used for pybind11 implicit conversion
  4738. py::detail::loader_life_support guard{};
  4739. reinterpret_cast<PyOp(Convolution3D)*>(self)->inst().workspace_limit =
  4740. py::cast<decltype(Convolution3D::workspace_limit)>(py::handle(workspace_limit));
  4741. } CATCH_ALL(-1)
  4742. }
  4743. if (scope) {
  4744. try {
  4745. reinterpret_cast<PyOp(OpDef)*>(self)->op
  4746. ->set_scope(py::cast<std::string>(py::handle(scope)));
  4747. } CATCH_ALL(-1)
  4748. }
  4749. return 0;
  4750. }
  4751. PyGetSetDef PyOp(Convolution3D)::py_getsetters[] = {
  4752. {const_cast<char*>("mode"), py_get_generic(Convolution3D, mode), py_set_generic(Convolution3D, mode), const_cast<char*>("mode"), NULL},
  4753. {const_cast<char*>("pad_d"), py_get_generic(Convolution3D, pad_d), py_set_generic(Convolution3D, pad_d), const_cast<char*>("pad_d"), NULL},
  4754. {const_cast<char*>("pad_h"), py_get_generic(Convolution3D, pad_h), py_set_generic(Convolution3D, pad_h), const_cast<char*>("pad_h"), NULL},
  4755. {const_cast<char*>("pad_w"), py_get_generic(Convolution3D, pad_w), py_set_generic(Convolution3D, pad_w), const_cast<char*>("pad_w"), NULL},
  4756. {const_cast<char*>("stride_d"), py_get_generic(Convolution3D, stride_d), py_set_generic(Convolution3D, stride_d), const_cast<char*>("stride_d"), NULL},
  4757. {const_cast<char*>("stride_h"), py_get_generic(Convolution3D, stride_h), py_set_generic(Convolution3D, stride_h), const_cast<char*>("stride_h"), NULL},
  4758. {const_cast<char*>("stride_w"), py_get_generic(Convolution3D, stride_w), py_set_generic(Convolution3D, stride_w), const_cast<char*>("stride_w"), NULL},
  4759. {const_cast<char*>("dilate_d"), py_get_generic(Convolution3D, dilate_d), py_set_generic(Convolution3D, dilate_d), const_cast<char*>("dilate_d"), NULL},
  4760. {const_cast<char*>("dilate_h"), py_get_generic(Convolution3D, dilate_h), py_set_generic(Convolution3D, dilate_h), const_cast<char*>("dilate_h"), NULL},
  4761. {const_cast<char*>("dilate_w"), py_get_generic(Convolution3D, dilate_w), py_set_generic(Convolution3D, dilate_w), const_cast<char*>("dilate_w"), NULL},
  4762. {const_cast<char*>("sparse"), py_get_generic(Convolution3D, sparse), py_set_generic(Convolution3D, sparse), const_cast<char*>("sparse"), NULL},
  4763. {const_cast<char*>("data_type"), py_get_generic(Convolution3D, data_type), py_set_generic(Convolution3D, data_type), const_cast<char*>("data_type"), NULL},
  4764. {const_cast<char*>("format"), py_get_generic(Convolution3D, format), py_set_generic(Convolution3D, format), const_cast<char*>("format"), NULL},
  4765. {const_cast<char*>("strategy"), py_get_generic(Convolution3D, strategy), py_set_generic(Convolution3D, strategy), const_cast<char*>("strategy"), NULL},
  4766. {const_cast<char*>("workspace_limit"), py_get_generic(Convolution3D, workspace_limit), py_set_generic(Convolution3D, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  4767. {NULL} /* Sentinel */
  4768. };
  4769. PyMethodDef PyOp(Convolution3D)::tp_methods[] = {
  4770. {const_cast<char*>("__getstate__"), PyOp(Convolution3D)::getstate, METH_NOARGS, "Convolution3D getstate"},
  4771. {const_cast<char*>("__setstate__"), PyOp(Convolution3D)::setstate, METH_VARARGS, "Convolution3D setstate"},
  4772. {NULL} /* Sentinel */
  4773. };
  4774. void _init_py_Convolution3D(py::module m) {
  4775. using py_op = PyOp(Convolution3D);
  4776. auto& py_type = PyOpType(Convolution3D);
  4777. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  4778. py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution3D";
  4779. py_type.tp_basicsize = sizeof(PyOp(Convolution3D));
  4780. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  4781. py_type.tp_doc = "Convolution3D";
  4782. py_type.tp_base = &PyOpType(OpDef);
  4783. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  4784. py_type.tp_new = py_new_generic<py_op>;
  4785. py_type.tp_init = py_op::py_init;
  4786. py_type.tp_methods = py_op::tp_methods;
  4787. py_type.tp_getset = py_op::py_getsetters;
  4788. mgb_assert(PyType_Ready(&py_type) >= 0);
  4789. _init_py_Convolution3D_Mode(py_type);
  4790. _init_py_Convolution3D_Sparse(py_type);
  4791. _init_py_Convolution3D_DataType(py_type);
  4792. _init_py_Convolution3D_Format(py_type);
  4793. _init_py_Convolution3D_Strategy(py_type);
  4794. PyType_Modified(&py_type);
  4795. m.add_object("Convolution3D", reinterpret_cast<PyObject*>(&py_type));
  4796. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution3D::typeinfo(), &py_type).second);
  4797. }
  4798. void _init_py_Convolution3DBackwardData_Mode(PyTypeObject& py_type) {
  4799. auto& e_type = EnumWrapper<Convolution3DBackwardData::Mode>::type;
  4800. Py_INCREF(e_type);
  4801. mgb_assert(PyDict_SetItemString(
  4802. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4803. }
  4804. void _init_py_Convolution3DBackwardData_Sparse(PyTypeObject& py_type) {
  4805. auto& e_type = EnumWrapper<Convolution3DBackwardData::Sparse>::type;
  4806. Py_INCREF(e_type);
  4807. mgb_assert(PyDict_SetItemString(
  4808. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4809. }
  4810. void _init_py_Convolution3DBackwardData_DataType(PyTypeObject& py_type) {
  4811. auto& e_type = EnumWrapper<Convolution3DBackwardData::DataType>::type;
  4812. Py_INCREF(e_type);
  4813. mgb_assert(PyDict_SetItemString(
  4814. py_type.tp_dict, "DataType", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4815. }
  4816. void _init_py_Convolution3DBackwardData_Format(PyTypeObject& py_type) {
  4817. auto& e_type = EnumWrapper<Convolution3DBackwardData::Format>::type;
  4818. Py_INCREF(e_type);
  4819. mgb_assert(PyDict_SetItemString(
  4820. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4821. }
  4822. void _init_py_Convolution3DBackwardData_Strategy(PyTypeObject& py_type) {
  4823. auto& e_type = BitCombinedEnumWrapper<Convolution3DBackwardData::Strategy>::type;
  4824. Py_INCREF(e_type);
  4825. mgb_assert(PyDict_SetItemString(
  4826. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  4827. }
  4828. PyOpDefBegin(Convolution3DBackwardData) // {
  4829. static PyGetSetDef py_getsetters[];
  4830. static PyMethodDef tp_methods[];
  4831. static PyObject* getstate(PyObject* self, PyObject*) {
  4832. auto& opdef = reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst();
  4833. static_cast<void>(opdef);
  4834. std::unordered_map<std::string, py::object> state {
  4835. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  4836. {"pad_d", serialization<decltype(opdef.pad_d)>::dump(opdef.pad_d)},
  4837. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  4838. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  4839. {"stride_d", serialization<decltype(opdef.stride_d)>::dump(opdef.stride_d)},
  4840. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  4841. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  4842. {"dilate_d", serialization<decltype(opdef.dilate_d)>::dump(opdef.dilate_d)},
  4843. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  4844. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  4845. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  4846. {"data_type", serialization<decltype(opdef.data_type)>::dump(opdef.data_type)},
  4847. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  4848. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  4849. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  4850. };
  4851. return py::cast(state).release().ptr();
  4852. }
  4853. static PyObject* setstate(PyObject* self, PyObject* args) {
  4854. PyObject* dict = PyTuple_GetItem(args, 0);
  4855. if (!dict) return NULL;
  4856. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  4857. auto& opdef = reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst();
  4858. static_cast<void>(opdef);
  4859. {
  4860. auto&& iter = state.find("mode");
  4861. if (iter != state.end()) {
  4862. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  4863. }
  4864. }
  4865. {
  4866. auto&& iter = state.find("pad_d");
  4867. if (iter != state.end()) {
  4868. opdef.pad_d = serialization<decltype(opdef.pad_d)>::load(iter->second);
  4869. }
  4870. }
  4871. {
  4872. auto&& iter = state.find("pad_h");
  4873. if (iter != state.end()) {
  4874. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  4875. }
  4876. }
  4877. {
  4878. auto&& iter = state.find("pad_w");
  4879. if (iter != state.end()) {
  4880. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  4881. }
  4882. }
  4883. {
  4884. auto&& iter = state.find("stride_d");
  4885. if (iter != state.end()) {
  4886. opdef.stride_d = serialization<decltype(opdef.stride_d)>::load(iter->second);
  4887. }
  4888. }
  4889. {
  4890. auto&& iter = state.find("stride_h");
  4891. if (iter != state.end()) {
  4892. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  4893. }
  4894. }
  4895. {
  4896. auto&& iter = state.find("stride_w");
  4897. if (iter != state.end()) {
  4898. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  4899. }
  4900. }
  4901. {
  4902. auto&& iter = state.find("dilate_d");
  4903. if (iter != state.end()) {
  4904. opdef.dilate_d = serialization<decltype(opdef.dilate_d)>::load(iter->second);
  4905. }
  4906. }
  4907. {
  4908. auto&& iter = state.find("dilate_h");
  4909. if (iter != state.end()) {
  4910. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  4911. }
  4912. }
  4913. {
  4914. auto&& iter = state.find("dilate_w");
  4915. if (iter != state.end()) {
  4916. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  4917. }
  4918. }
  4919. {
  4920. auto&& iter = state.find("sparse");
  4921. if (iter != state.end()) {
  4922. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  4923. }
  4924. }
  4925. {
  4926. auto&& iter = state.find("data_type");
  4927. if (iter != state.end()) {
  4928. opdef.data_type = serialization<decltype(opdef.data_type)>::load(iter->second);
  4929. }
  4930. }
  4931. {
  4932. auto&& iter = state.find("format");
  4933. if (iter != state.end()) {
  4934. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  4935. }
  4936. }
  4937. {
  4938. auto&& iter = state.find("strategy");
  4939. if (iter != state.end()) {
  4940. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  4941. }
  4942. }
  4943. {
  4944. auto&& iter = state.find("workspace_limit");
  4945. if (iter != state.end()) {
  4946. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  4947. }
  4948. }
  4949. Py_RETURN_NONE;
  4950. }
  4951. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  4952. // };
  4953. PyOpDefEnd(Convolution3DBackwardData)
  4954. int PyOp(Convolution3DBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  4955. static const char* kwlist[] = {"mode", "pad_d", "pad_h", "pad_w", "stride_d", "stride_h", "stride_w", "dilate_d", "dilate_h", "dilate_w", "sparse", "data_type", "format", "strategy", "workspace_limit", "scope", NULL};
  4956. PyObject *mode = NULL, *pad_d = NULL, *pad_h = NULL, *pad_w = NULL, *stride_d = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_d = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *data_type = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  4957. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_d, &pad_h, &pad_w, &stride_d, &stride_h, &stride_w, &dilate_d, &dilate_h, &dilate_w, &sparse, &data_type, &format, &strategy, &workspace_limit, &scope))
  4958. return -1;
  4959. if (mode) {
  4960. try {
  4961. // TODO: remove this guard which is used for pybind11 implicit conversion
  4962. py::detail::loader_life_support guard{};
  4963. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().mode =
  4964. py::cast<decltype(Convolution3DBackwardData::mode)>(py::handle(mode));
  4965. } CATCH_ALL(-1)
  4966. }
  4967. if (pad_d) {
  4968. try {
  4969. // TODO: remove this guard which is used for pybind11 implicit conversion
  4970. py::detail::loader_life_support guard{};
  4971. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().pad_d =
  4972. py::cast<decltype(Convolution3DBackwardData::pad_d)>(py::handle(pad_d));
  4973. } CATCH_ALL(-1)
  4974. }
  4975. if (pad_h) {
  4976. try {
  4977. // TODO: remove this guard which is used for pybind11 implicit conversion
  4978. py::detail::loader_life_support guard{};
  4979. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().pad_h =
  4980. py::cast<decltype(Convolution3DBackwardData::pad_h)>(py::handle(pad_h));
  4981. } CATCH_ALL(-1)
  4982. }
  4983. if (pad_w) {
  4984. try {
  4985. // TODO: remove this guard which is used for pybind11 implicit conversion
  4986. py::detail::loader_life_support guard{};
  4987. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().pad_w =
  4988. py::cast<decltype(Convolution3DBackwardData::pad_w)>(py::handle(pad_w));
  4989. } CATCH_ALL(-1)
  4990. }
  4991. if (stride_d) {
  4992. try {
  4993. // TODO: remove this guard which is used for pybind11 implicit conversion
  4994. py::detail::loader_life_support guard{};
  4995. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().stride_d =
  4996. py::cast<decltype(Convolution3DBackwardData::stride_d)>(py::handle(stride_d));
  4997. } CATCH_ALL(-1)
  4998. }
  4999. if (stride_h) {
  5000. try {
  5001. // TODO: remove this guard which is used for pybind11 implicit conversion
  5002. py::detail::loader_life_support guard{};
  5003. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().stride_h =
  5004. py::cast<decltype(Convolution3DBackwardData::stride_h)>(py::handle(stride_h));
  5005. } CATCH_ALL(-1)
  5006. }
  5007. if (stride_w) {
  5008. try {
  5009. // TODO: remove this guard which is used for pybind11 implicit conversion
  5010. py::detail::loader_life_support guard{};
  5011. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().stride_w =
  5012. py::cast<decltype(Convolution3DBackwardData::stride_w)>(py::handle(stride_w));
  5013. } CATCH_ALL(-1)
  5014. }
  5015. if (dilate_d) {
  5016. try {
  5017. // TODO: remove this guard which is used for pybind11 implicit conversion
  5018. py::detail::loader_life_support guard{};
  5019. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().dilate_d =
  5020. py::cast<decltype(Convolution3DBackwardData::dilate_d)>(py::handle(dilate_d));
  5021. } CATCH_ALL(-1)
  5022. }
  5023. if (dilate_h) {
  5024. try {
  5025. // TODO: remove this guard which is used for pybind11 implicit conversion
  5026. py::detail::loader_life_support guard{};
  5027. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().dilate_h =
  5028. py::cast<decltype(Convolution3DBackwardData::dilate_h)>(py::handle(dilate_h));
  5029. } CATCH_ALL(-1)
  5030. }
  5031. if (dilate_w) {
  5032. try {
  5033. // TODO: remove this guard which is used for pybind11 implicit conversion
  5034. py::detail::loader_life_support guard{};
  5035. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().dilate_w =
  5036. py::cast<decltype(Convolution3DBackwardData::dilate_w)>(py::handle(dilate_w));
  5037. } CATCH_ALL(-1)
  5038. }
  5039. if (sparse) {
  5040. try {
  5041. // TODO: remove this guard which is used for pybind11 implicit conversion
  5042. py::detail::loader_life_support guard{};
  5043. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().sparse =
  5044. py::cast<decltype(Convolution3DBackwardData::sparse)>(py::handle(sparse));
  5045. } CATCH_ALL(-1)
  5046. }
  5047. if (data_type) {
  5048. try {
  5049. // TODO: remove this guard which is used for pybind11 implicit conversion
  5050. py::detail::loader_life_support guard{};
  5051. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().data_type =
  5052. py::cast<decltype(Convolution3DBackwardData::data_type)>(py::handle(data_type));
  5053. } CATCH_ALL(-1)
  5054. }
  5055. if (format) {
  5056. try {
  5057. // TODO: remove this guard which is used for pybind11 implicit conversion
  5058. py::detail::loader_life_support guard{};
  5059. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().format =
  5060. py::cast<decltype(Convolution3DBackwardData::format)>(py::handle(format));
  5061. } CATCH_ALL(-1)
  5062. }
  5063. if (strategy) {
  5064. try {
  5065. // TODO: remove this guard which is used for pybind11 implicit conversion
  5066. py::detail::loader_life_support guard{};
  5067. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().strategy =
  5068. py::cast<decltype(Convolution3DBackwardData::strategy)>(py::handle(strategy));
  5069. } CATCH_ALL(-1)
  5070. }
  5071. if (workspace_limit) {
  5072. try {
  5073. // TODO: remove this guard which is used for pybind11 implicit conversion
  5074. py::detail::loader_life_support guard{};
  5075. reinterpret_cast<PyOp(Convolution3DBackwardData)*>(self)->inst().workspace_limit =
  5076. py::cast<decltype(Convolution3DBackwardData::workspace_limit)>(py::handle(workspace_limit));
  5077. } CATCH_ALL(-1)
  5078. }
  5079. if (scope) {
  5080. try {
  5081. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5082. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5083. } CATCH_ALL(-1)
  5084. }
  5085. return 0;
  5086. }
  5087. PyGetSetDef PyOp(Convolution3DBackwardData)::py_getsetters[] = {
  5088. {const_cast<char*>("mode"), py_get_generic(Convolution3DBackwardData, mode), py_set_generic(Convolution3DBackwardData, mode), const_cast<char*>("mode"), NULL},
  5089. {const_cast<char*>("pad_d"), py_get_generic(Convolution3DBackwardData, pad_d), py_set_generic(Convolution3DBackwardData, pad_d), const_cast<char*>("pad_d"), NULL},
  5090. {const_cast<char*>("pad_h"), py_get_generic(Convolution3DBackwardData, pad_h), py_set_generic(Convolution3DBackwardData, pad_h), const_cast<char*>("pad_h"), NULL},
  5091. {const_cast<char*>("pad_w"), py_get_generic(Convolution3DBackwardData, pad_w), py_set_generic(Convolution3DBackwardData, pad_w), const_cast<char*>("pad_w"), NULL},
  5092. {const_cast<char*>("stride_d"), py_get_generic(Convolution3DBackwardData, stride_d), py_set_generic(Convolution3DBackwardData, stride_d), const_cast<char*>("stride_d"), NULL},
  5093. {const_cast<char*>("stride_h"), py_get_generic(Convolution3DBackwardData, stride_h), py_set_generic(Convolution3DBackwardData, stride_h), const_cast<char*>("stride_h"), NULL},
  5094. {const_cast<char*>("stride_w"), py_get_generic(Convolution3DBackwardData, stride_w), py_set_generic(Convolution3DBackwardData, stride_w), const_cast<char*>("stride_w"), NULL},
  5095. {const_cast<char*>("dilate_d"), py_get_generic(Convolution3DBackwardData, dilate_d), py_set_generic(Convolution3DBackwardData, dilate_d), const_cast<char*>("dilate_d"), NULL},
  5096. {const_cast<char*>("dilate_h"), py_get_generic(Convolution3DBackwardData, dilate_h), py_set_generic(Convolution3DBackwardData, dilate_h), const_cast<char*>("dilate_h"), NULL},
  5097. {const_cast<char*>("dilate_w"), py_get_generic(Convolution3DBackwardData, dilate_w), py_set_generic(Convolution3DBackwardData, dilate_w), const_cast<char*>("dilate_w"), NULL},
  5098. {const_cast<char*>("sparse"), py_get_generic(Convolution3DBackwardData, sparse), py_set_generic(Convolution3DBackwardData, sparse), const_cast<char*>("sparse"), NULL},
  5099. {const_cast<char*>("data_type"), py_get_generic(Convolution3DBackwardData, data_type), py_set_generic(Convolution3DBackwardData, data_type), const_cast<char*>("data_type"), NULL},
  5100. {const_cast<char*>("format"), py_get_generic(Convolution3DBackwardData, format), py_set_generic(Convolution3DBackwardData, format), const_cast<char*>("format"), NULL},
  5101. {const_cast<char*>("strategy"), py_get_generic(Convolution3DBackwardData, strategy), py_set_generic(Convolution3DBackwardData, strategy), const_cast<char*>("strategy"), NULL},
  5102. {const_cast<char*>("workspace_limit"), py_get_generic(Convolution3DBackwardData, workspace_limit), py_set_generic(Convolution3DBackwardData, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  5103. {NULL} /* Sentinel */
  5104. };
  5105. PyMethodDef PyOp(Convolution3DBackwardData)::tp_methods[] = {
  5106. {const_cast<char*>("__getstate__"), PyOp(Convolution3DBackwardData)::getstate, METH_NOARGS, "Convolution3DBackwardData getstate"},
  5107. {const_cast<char*>("__setstate__"), PyOp(Convolution3DBackwardData)::setstate, METH_VARARGS, "Convolution3DBackwardData setstate"},
  5108. {NULL} /* Sentinel */
  5109. };
  5110. void _init_py_Convolution3DBackwardData(py::module m) {
  5111. using py_op = PyOp(Convolution3DBackwardData);
  5112. auto& py_type = PyOpType(Convolution3DBackwardData);
  5113. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5114. py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution3DBackwardData";
  5115. py_type.tp_basicsize = sizeof(PyOp(Convolution3DBackwardData));
  5116. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5117. py_type.tp_doc = "Convolution3DBackwardData";
  5118. py_type.tp_base = &PyOpType(OpDef);
  5119. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5120. py_type.tp_new = py_new_generic<py_op>;
  5121. py_type.tp_init = py_op::py_init;
  5122. py_type.tp_methods = py_op::tp_methods;
  5123. py_type.tp_getset = py_op::py_getsetters;
  5124. mgb_assert(PyType_Ready(&py_type) >= 0);
  5125. _init_py_Convolution3DBackwardData_Mode(py_type);
  5126. _init_py_Convolution3DBackwardData_Sparse(py_type);
  5127. _init_py_Convolution3DBackwardData_DataType(py_type);
  5128. _init_py_Convolution3DBackwardData_Format(py_type);
  5129. _init_py_Convolution3DBackwardData_Strategy(py_type);
  5130. PyType_Modified(&py_type);
  5131. m.add_object("Convolution3DBackwardData", reinterpret_cast<PyObject*>(&py_type));
  5132. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution3DBackwardData::typeinfo(), &py_type).second);
  5133. }
  5134. void _init_py_ConvolutionBackwardData_Mode(PyTypeObject& py_type) {
  5135. auto& e_type = EnumWrapper<ConvolutionBackwardData::Mode>::type;
  5136. Py_INCREF(e_type);
  5137. mgb_assert(PyDict_SetItemString(
  5138. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5139. }
  5140. void _init_py_ConvolutionBackwardData_Sparse(PyTypeObject& py_type) {
  5141. auto& e_type = EnumWrapper<ConvolutionBackwardData::Sparse>::type;
  5142. Py_INCREF(e_type);
  5143. mgb_assert(PyDict_SetItemString(
  5144. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5145. }
  5146. void _init_py_ConvolutionBackwardData_Format(PyTypeObject& py_type) {
  5147. auto& e_type = EnumWrapper<ConvolutionBackwardData::Format>::type;
  5148. Py_INCREF(e_type);
  5149. mgb_assert(PyDict_SetItemString(
  5150. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5151. }
  5152. void _init_py_ConvolutionBackwardData_ComputeMode(PyTypeObject& py_type) {
  5153. auto& e_type = EnumWrapper<ConvolutionBackwardData::ComputeMode>::type;
  5154. Py_INCREF(e_type);
  5155. mgb_assert(PyDict_SetItemString(
  5156. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5157. }
  5158. void _init_py_ConvolutionBackwardData_Strategy(PyTypeObject& py_type) {
  5159. auto& e_type = BitCombinedEnumWrapper<ConvolutionBackwardData::Strategy>::type;
  5160. Py_INCREF(e_type);
  5161. mgb_assert(PyDict_SetItemString(
  5162. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5163. }
  5164. PyOpDefBegin(ConvolutionBackwardData) // {
  5165. static PyGetSetDef py_getsetters[];
  5166. static PyMethodDef tp_methods[];
  5167. static PyObject* getstate(PyObject* self, PyObject*) {
  5168. auto& opdef = reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst();
  5169. static_cast<void>(opdef);
  5170. std::unordered_map<std::string, py::object> state {
  5171. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  5172. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  5173. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  5174. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  5175. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  5176. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  5177. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  5178. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  5179. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  5180. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  5181. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  5182. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  5183. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  5184. };
  5185. return py::cast(state).release().ptr();
  5186. }
  5187. static PyObject* setstate(PyObject* self, PyObject* args) {
  5188. PyObject* dict = PyTuple_GetItem(args, 0);
  5189. if (!dict) return NULL;
  5190. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5191. auto& opdef = reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst();
  5192. static_cast<void>(opdef);
  5193. {
  5194. auto&& iter = state.find("mode");
  5195. if (iter != state.end()) {
  5196. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  5197. }
  5198. }
  5199. {
  5200. auto&& iter = state.find("pad_h");
  5201. if (iter != state.end()) {
  5202. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  5203. }
  5204. }
  5205. {
  5206. auto&& iter = state.find("pad_w");
  5207. if (iter != state.end()) {
  5208. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  5209. }
  5210. }
  5211. {
  5212. auto&& iter = state.find("stride_h");
  5213. if (iter != state.end()) {
  5214. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  5215. }
  5216. }
  5217. {
  5218. auto&& iter = state.find("stride_w");
  5219. if (iter != state.end()) {
  5220. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  5221. }
  5222. }
  5223. {
  5224. auto&& iter = state.find("dilate_h");
  5225. if (iter != state.end()) {
  5226. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  5227. }
  5228. }
  5229. {
  5230. auto&& iter = state.find("dilate_w");
  5231. if (iter != state.end()) {
  5232. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  5233. }
  5234. }
  5235. {
  5236. auto&& iter = state.find("sparse");
  5237. if (iter != state.end()) {
  5238. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  5239. }
  5240. }
  5241. {
  5242. auto&& iter = state.find("format");
  5243. if (iter != state.end()) {
  5244. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  5245. }
  5246. }
  5247. {
  5248. auto&& iter = state.find("compute_mode");
  5249. if (iter != state.end()) {
  5250. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  5251. }
  5252. }
  5253. {
  5254. auto&& iter = state.find("strategy");
  5255. if (iter != state.end()) {
  5256. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  5257. }
  5258. }
  5259. {
  5260. auto&& iter = state.find("workspace_limit");
  5261. if (iter != state.end()) {
  5262. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  5263. }
  5264. }
  5265. {
  5266. auto&& iter = state.find("dtype");
  5267. if (iter != state.end()) {
  5268. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  5269. }
  5270. }
  5271. Py_RETURN_NONE;
  5272. }
  5273. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5274. // };
  5275. PyOpDefEnd(ConvolutionBackwardData)
  5276. int PyOp(ConvolutionBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5277. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL};
  5278. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL;
  5279. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &dtype, &scope))
  5280. return -1;
  5281. if (mode) {
  5282. try {
  5283. // TODO: remove this guard which is used for pybind11 implicit conversion
  5284. py::detail::loader_life_support guard{};
  5285. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().mode =
  5286. py::cast<decltype(ConvolutionBackwardData::mode)>(py::handle(mode));
  5287. } CATCH_ALL(-1)
  5288. }
  5289. if (pad_h) {
  5290. try {
  5291. // TODO: remove this guard which is used for pybind11 implicit conversion
  5292. py::detail::loader_life_support guard{};
  5293. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().pad_h =
  5294. py::cast<decltype(ConvolutionBackwardData::pad_h)>(py::handle(pad_h));
  5295. } CATCH_ALL(-1)
  5296. }
  5297. if (pad_w) {
  5298. try {
  5299. // TODO: remove this guard which is used for pybind11 implicit conversion
  5300. py::detail::loader_life_support guard{};
  5301. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().pad_w =
  5302. py::cast<decltype(ConvolutionBackwardData::pad_w)>(py::handle(pad_w));
  5303. } CATCH_ALL(-1)
  5304. }
  5305. if (stride_h) {
  5306. try {
  5307. // TODO: remove this guard which is used for pybind11 implicit conversion
  5308. py::detail::loader_life_support guard{};
  5309. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().stride_h =
  5310. py::cast<decltype(ConvolutionBackwardData::stride_h)>(py::handle(stride_h));
  5311. } CATCH_ALL(-1)
  5312. }
  5313. if (stride_w) {
  5314. try {
  5315. // TODO: remove this guard which is used for pybind11 implicit conversion
  5316. py::detail::loader_life_support guard{};
  5317. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().stride_w =
  5318. py::cast<decltype(ConvolutionBackwardData::stride_w)>(py::handle(stride_w));
  5319. } CATCH_ALL(-1)
  5320. }
  5321. if (dilate_h) {
  5322. try {
  5323. // TODO: remove this guard which is used for pybind11 implicit conversion
  5324. py::detail::loader_life_support guard{};
  5325. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().dilate_h =
  5326. py::cast<decltype(ConvolutionBackwardData::dilate_h)>(py::handle(dilate_h));
  5327. } CATCH_ALL(-1)
  5328. }
  5329. if (dilate_w) {
  5330. try {
  5331. // TODO: remove this guard which is used for pybind11 implicit conversion
  5332. py::detail::loader_life_support guard{};
  5333. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().dilate_w =
  5334. py::cast<decltype(ConvolutionBackwardData::dilate_w)>(py::handle(dilate_w));
  5335. } CATCH_ALL(-1)
  5336. }
  5337. if (sparse) {
  5338. try {
  5339. // TODO: remove this guard which is used for pybind11 implicit conversion
  5340. py::detail::loader_life_support guard{};
  5341. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().sparse =
  5342. py::cast<decltype(ConvolutionBackwardData::sparse)>(py::handle(sparse));
  5343. } CATCH_ALL(-1)
  5344. }
  5345. if (format) {
  5346. try {
  5347. // TODO: remove this guard which is used for pybind11 implicit conversion
  5348. py::detail::loader_life_support guard{};
  5349. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().format =
  5350. py::cast<decltype(ConvolutionBackwardData::format)>(py::handle(format));
  5351. } CATCH_ALL(-1)
  5352. }
  5353. if (compute_mode) {
  5354. try {
  5355. // TODO: remove this guard which is used for pybind11 implicit conversion
  5356. py::detail::loader_life_support guard{};
  5357. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().compute_mode =
  5358. py::cast<decltype(ConvolutionBackwardData::compute_mode)>(py::handle(compute_mode));
  5359. } CATCH_ALL(-1)
  5360. }
  5361. if (strategy) {
  5362. try {
  5363. // TODO: remove this guard which is used for pybind11 implicit conversion
  5364. py::detail::loader_life_support guard{};
  5365. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().strategy =
  5366. py::cast<decltype(ConvolutionBackwardData::strategy)>(py::handle(strategy));
  5367. } CATCH_ALL(-1)
  5368. }
  5369. if (workspace_limit) {
  5370. try {
  5371. // TODO: remove this guard which is used for pybind11 implicit conversion
  5372. py::detail::loader_life_support guard{};
  5373. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().workspace_limit =
  5374. py::cast<decltype(ConvolutionBackwardData::workspace_limit)>(py::handle(workspace_limit));
  5375. } CATCH_ALL(-1)
  5376. }
  5377. if (dtype) {
  5378. try {
  5379. // TODO: remove this guard which is used for pybind11 implicit conversion
  5380. py::detail::loader_life_support guard{};
  5381. reinterpret_cast<PyOp(ConvolutionBackwardData)*>(self)->inst().dtype =
  5382. py::cast<decltype(ConvolutionBackwardData::dtype)>(py::handle(dtype));
  5383. } CATCH_ALL(-1)
  5384. }
  5385. if (scope) {
  5386. try {
  5387. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5388. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5389. } CATCH_ALL(-1)
  5390. }
  5391. return 0;
  5392. }
  5393. PyGetSetDef PyOp(ConvolutionBackwardData)::py_getsetters[] = {
  5394. {const_cast<char*>("mode"), py_get_generic(ConvolutionBackwardData, mode), py_set_generic(ConvolutionBackwardData, mode), const_cast<char*>("mode"), NULL},
  5395. {const_cast<char*>("pad_h"), py_get_generic(ConvolutionBackwardData, pad_h), py_set_generic(ConvolutionBackwardData, pad_h), const_cast<char*>("pad_h"), NULL},
  5396. {const_cast<char*>("pad_w"), py_get_generic(ConvolutionBackwardData, pad_w), py_set_generic(ConvolutionBackwardData, pad_w), const_cast<char*>("pad_w"), NULL},
  5397. {const_cast<char*>("stride_h"), py_get_generic(ConvolutionBackwardData, stride_h), py_set_generic(ConvolutionBackwardData, stride_h), const_cast<char*>("stride_h"), NULL},
  5398. {const_cast<char*>("stride_w"), py_get_generic(ConvolutionBackwardData, stride_w), py_set_generic(ConvolutionBackwardData, stride_w), const_cast<char*>("stride_w"), NULL},
  5399. {const_cast<char*>("dilate_h"), py_get_generic(ConvolutionBackwardData, dilate_h), py_set_generic(ConvolutionBackwardData, dilate_h), const_cast<char*>("dilate_h"), NULL},
  5400. {const_cast<char*>("dilate_w"), py_get_generic(ConvolutionBackwardData, dilate_w), py_set_generic(ConvolutionBackwardData, dilate_w), const_cast<char*>("dilate_w"), NULL},
  5401. {const_cast<char*>("sparse"), py_get_generic(ConvolutionBackwardData, sparse), py_set_generic(ConvolutionBackwardData, sparse), const_cast<char*>("sparse"), NULL},
  5402. {const_cast<char*>("format"), py_get_generic(ConvolutionBackwardData, format), py_set_generic(ConvolutionBackwardData, format), const_cast<char*>("format"), NULL},
  5403. {const_cast<char*>("compute_mode"), py_get_generic(ConvolutionBackwardData, compute_mode), py_set_generic(ConvolutionBackwardData, compute_mode), const_cast<char*>("compute_mode"), NULL},
  5404. {const_cast<char*>("strategy"), py_get_generic(ConvolutionBackwardData, strategy), py_set_generic(ConvolutionBackwardData, strategy), const_cast<char*>("strategy"), NULL},
  5405. {const_cast<char*>("workspace_limit"), py_get_generic(ConvolutionBackwardData, workspace_limit), py_set_generic(ConvolutionBackwardData, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  5406. {const_cast<char*>("dtype"), py_get_generic(ConvolutionBackwardData, dtype), py_set_generic(ConvolutionBackwardData, dtype), const_cast<char*>("dtype"), NULL},
  5407. {NULL} /* Sentinel */
  5408. };
  5409. PyMethodDef PyOp(ConvolutionBackwardData)::tp_methods[] = {
  5410. {const_cast<char*>("__getstate__"), PyOp(ConvolutionBackwardData)::getstate, METH_NOARGS, "ConvolutionBackwardData getstate"},
  5411. {const_cast<char*>("__setstate__"), PyOp(ConvolutionBackwardData)::setstate, METH_VARARGS, "ConvolutionBackwardData setstate"},
  5412. {NULL} /* Sentinel */
  5413. };
  5414. void _init_py_ConvolutionBackwardData(py::module m) {
  5415. using py_op = PyOp(ConvolutionBackwardData);
  5416. auto& py_type = PyOpType(ConvolutionBackwardData);
  5417. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5418. py_type.tp_name = "megengine.core._imperative_rt.ops.ConvolutionBackwardData";
  5419. py_type.tp_basicsize = sizeof(PyOp(ConvolutionBackwardData));
  5420. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5421. py_type.tp_doc = "ConvolutionBackwardData";
  5422. py_type.tp_base = &PyOpType(OpDef);
  5423. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5424. py_type.tp_new = py_new_generic<py_op>;
  5425. py_type.tp_init = py_op::py_init;
  5426. py_type.tp_methods = py_op::tp_methods;
  5427. py_type.tp_getset = py_op::py_getsetters;
  5428. mgb_assert(PyType_Ready(&py_type) >= 0);
  5429. _init_py_ConvolutionBackwardData_Mode(py_type);
  5430. _init_py_ConvolutionBackwardData_Sparse(py_type);
  5431. _init_py_ConvolutionBackwardData_Format(py_type);
  5432. _init_py_ConvolutionBackwardData_ComputeMode(py_type);
  5433. _init_py_ConvolutionBackwardData_Strategy(py_type);
  5434. PyType_Modified(&py_type);
  5435. m.add_object("ConvolutionBackwardData", reinterpret_cast<PyObject*>(&py_type));
  5436. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ConvolutionBackwardData::typeinfo(), &py_type).second);
  5437. }
  5438. PyOpDefBegin(Copy) // {
  5439. static PyGetSetDef py_getsetters[];
  5440. static PyMethodDef tp_methods[];
  5441. static PyObject* getstate(PyObject* self, PyObject*) {
  5442. auto& opdef = reinterpret_cast<PyOp(Copy)*>(self)->inst();
  5443. static_cast<void>(opdef);
  5444. std::unordered_map<std::string, py::object> state {
  5445. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  5446. };
  5447. return py::cast(state).release().ptr();
  5448. }
  5449. static PyObject* setstate(PyObject* self, PyObject* args) {
  5450. PyObject* dict = PyTuple_GetItem(args, 0);
  5451. if (!dict) return NULL;
  5452. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5453. auto& opdef = reinterpret_cast<PyOp(Copy)*>(self)->inst();
  5454. static_cast<void>(opdef);
  5455. {
  5456. auto&& iter = state.find("comp_node");
  5457. if (iter != state.end()) {
  5458. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  5459. }
  5460. }
  5461. Py_RETURN_NONE;
  5462. }
  5463. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5464. // };
  5465. PyOpDefEnd(Copy)
  5466. int PyOp(Copy)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5467. static const char* kwlist[] = {"comp_node", "scope", NULL};
  5468. PyObject *comp_node = NULL, *scope = NULL;
  5469. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &comp_node, &scope))
  5470. return -1;
  5471. if (comp_node) {
  5472. try {
  5473. // TODO: remove this guard which is used for pybind11 implicit conversion
  5474. py::detail::loader_life_support guard{};
  5475. reinterpret_cast<PyOp(Copy)*>(self)->inst().comp_node =
  5476. py::cast<decltype(Copy::comp_node)>(py::handle(comp_node));
  5477. } CATCH_ALL(-1)
  5478. }
  5479. if (scope) {
  5480. try {
  5481. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5482. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5483. } CATCH_ALL(-1)
  5484. }
  5485. return 0;
  5486. }
  5487. PyGetSetDef PyOp(Copy)::py_getsetters[] = {
  5488. {const_cast<char*>("comp_node"), py_get_generic(Copy, comp_node), py_set_generic(Copy, comp_node), const_cast<char*>("comp_node"), NULL},
  5489. {NULL} /* Sentinel */
  5490. };
  5491. PyMethodDef PyOp(Copy)::tp_methods[] = {
  5492. {const_cast<char*>("__getstate__"), PyOp(Copy)::getstate, METH_NOARGS, "Copy getstate"},
  5493. {const_cast<char*>("__setstate__"), PyOp(Copy)::setstate, METH_VARARGS, "Copy setstate"},
  5494. {NULL} /* Sentinel */
  5495. };
  5496. void _init_py_Copy(py::module m) {
  5497. using py_op = PyOp(Copy);
  5498. auto& py_type = PyOpType(Copy);
  5499. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5500. py_type.tp_name = "megengine.core._imperative_rt.ops.Copy";
  5501. py_type.tp_basicsize = sizeof(PyOp(Copy));
  5502. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5503. py_type.tp_doc = "Copy";
  5504. py_type.tp_base = &PyOpType(OpDef);
  5505. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5506. py_type.tp_new = py_new_generic<py_op>;
  5507. py_type.tp_init = py_op::py_init;
  5508. py_type.tp_methods = py_op::tp_methods;
  5509. py_type.tp_getset = py_op::py_getsetters;
  5510. mgb_assert(PyType_Ready(&py_type) >= 0);
  5511. PyType_Modified(&py_type);
  5512. m.add_object("Copy", reinterpret_cast<PyObject*>(&py_type));
  5513. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Copy::typeinfo(), &py_type).second);
  5514. }
  5515. template<> struct EnumTrait<Correlation::Format> {
  5516. static constexpr const char *name = "Correlation.Format";
  5517. static constexpr std::underlying_type_t<Correlation::Format> max = 20 - 1;
  5518. };
  5519. template<> PyTypeObject* EnumWrapper<Correlation::Format>::type = nullptr;
  5520. template<> const char*
  5521. EnumWrapper<Correlation::Format>::members[] = {"NCHW", "NHWC", "NHWCD4", "NCHW4", "NCHW8", "NCHW32", "NCHW88", "NCHW44", "NCHW44_DOT", "NCHW_WINOGRAD", "NCHW88_WINOGRAD", "NCHW44_WINOGRAD", "NCHW4_NCHW32", "NCHW32_NCHW4", "NCHW4_NCHW", "NHWC_NCHW", "NHWC_NCHW4_IC_SMALL", "NCHW_NCHW4_IC_SMALL", "CHWN4", "NCHW4_NHWC"};
  5522. template<> std::unordered_map<std::string, Correlation::Format>
  5523. EnumWrapper<Correlation::Format>::mem2value = {{normalize_enum("NCHW"), Correlation::Format::NCHW}, {normalize_enum("NHWC"), Correlation::Format::NHWC}, {normalize_enum("NHWCD4"), Correlation::Format::NHWCD4}, {normalize_enum("NCHW4"), Correlation::Format::NCHW4}, {normalize_enum("NCHW8"), Correlation::Format::NCHW8}, {normalize_enum("NCHW32"), Correlation::Format::NCHW32}, {normalize_enum("NCHW88"), Correlation::Format::NCHW88}, {normalize_enum("NCHW44"), Correlation::Format::NCHW44}, {normalize_enum("NCHW44_DOT"), Correlation::Format::NCHW44_DOT}, {normalize_enum("NCHW_WINOGRAD"), Correlation::Format::NCHW_WINOGRAD}, {normalize_enum("NCHW88_WINOGRAD"), Correlation::Format::NCHW88_WINOGRAD}, {normalize_enum("NCHW44_WINOGRAD"), Correlation::Format::NCHW44_WINOGRAD}, {normalize_enum("NCHW4_NCHW32"), Correlation::Format::NCHW4_NCHW32}, {normalize_enum("NCHW32_NCHW4"), Correlation::Format::NCHW32_NCHW4}, {normalize_enum("NCHW4_NCHW"), Correlation::Format::NCHW4_NCHW}, {normalize_enum("NHWC_NCHW"), Correlation::Format::NHWC_NCHW}, {normalize_enum("NHWC_NCHW4_IC_SMALL"), Correlation::Format::NHWC_NCHW4_IC_SMALL}, {normalize_enum("NCHW_NCHW4_IC_SMALL"), Correlation::Format::NCHW_NCHW4_IC_SMALL}, {normalize_enum("CHWN4"), Correlation::Format::CHWN4}, {normalize_enum("NCHW4_NHWC"), Correlation::Format::NCHW4_NHWC}};
  5524. template<> PyObject* EnumWrapper<Correlation::Format>::pyobj_insts[20] = {nullptr};
  5525. void _init_py_Correlation_Format(PyTypeObject& py_type) {
  5526. auto& e_type = EnumWrapper<Correlation::Format>::type;
  5527. static PyMethodDef tp_methods[] = {
  5528. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Correlation::Format>::py_dump, METH_NOARGS, NULL},
  5529. {NULL} /* Sentinel */
  5530. };
  5531. static PyType_Slot slots[] = {
  5532. {Py_tp_repr, (void*)EnumWrapper<Correlation::Format>::py_repr},
  5533. {Py_tp_richcompare, (void*)EnumWrapper<Correlation::Format>::tp_richcompare},
  5534. {Py_tp_methods, tp_methods},
  5535. {0, NULL}
  5536. };
  5537. static PyType_Spec spec = {
  5538. // name
  5539. "megengine.core._imperative_rt.ops.Correlation.Format",
  5540. // basicsize
  5541. sizeof(EnumWrapper<Correlation::Format>),
  5542. // itemsize
  5543. 0,
  5544. // flags
  5545. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  5546. // slots
  5547. slots
  5548. };
  5549. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  5550. mgb_assert(
  5551. e_type->tp_setattro(
  5552. reinterpret_cast<PyObject*>(e_type),
  5553. py::cast("__name__").release().ptr(),
  5554. py::cast("Format").release().ptr()) >= 0);
  5555. mgb_assert(
  5556. e_type->tp_setattro(
  5557. reinterpret_cast<PyObject*>(e_type),
  5558. py::cast("__module__").release().ptr(),
  5559. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  5560. mgb_assert(
  5561. e_type->tp_setattro(
  5562. reinterpret_cast<PyObject*>(e_type),
  5563. py::cast("__qualname__").release().ptr(),
  5564. py::cast("Correlation.Format").release().ptr()) >= 0);
  5565. {
  5566. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5567. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW;
  5568. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW", inst) >= 0);
  5569. EnumWrapper<Correlation::Format>::pyobj_insts[0] = inst;
  5570. }{
  5571. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5572. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWC;
  5573. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC", inst) >= 0);
  5574. EnumWrapper<Correlation::Format>::pyobj_insts[1] = inst;
  5575. }{
  5576. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5577. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWCD4;
  5578. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWCD4", inst) >= 0);
  5579. EnumWrapper<Correlation::Format>::pyobj_insts[2] = inst;
  5580. }{
  5581. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5582. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4;
  5583. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4", inst) >= 0);
  5584. EnumWrapper<Correlation::Format>::pyobj_insts[3] = inst;
  5585. }{
  5586. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5587. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW8;
  5588. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW8", inst) >= 0);
  5589. EnumWrapper<Correlation::Format>::pyobj_insts[4] = inst;
  5590. }{
  5591. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5592. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW32;
  5593. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32", inst) >= 0);
  5594. EnumWrapper<Correlation::Format>::pyobj_insts[5] = inst;
  5595. }{
  5596. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5597. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW88;
  5598. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88", inst) >= 0);
  5599. EnumWrapper<Correlation::Format>::pyobj_insts[6] = inst;
  5600. }{
  5601. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5602. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW44;
  5603. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44", inst) >= 0);
  5604. EnumWrapper<Correlation::Format>::pyobj_insts[7] = inst;
  5605. }{
  5606. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5607. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW44_DOT;
  5608. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_DOT", inst) >= 0);
  5609. EnumWrapper<Correlation::Format>::pyobj_insts[8] = inst;
  5610. }{
  5611. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5612. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW_WINOGRAD;
  5613. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_WINOGRAD", inst) >= 0);
  5614. EnumWrapper<Correlation::Format>::pyobj_insts[9] = inst;
  5615. }{
  5616. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5617. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW88_WINOGRAD;
  5618. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88_WINOGRAD", inst) >= 0);
  5619. EnumWrapper<Correlation::Format>::pyobj_insts[10] = inst;
  5620. }{
  5621. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5622. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW44_WINOGRAD;
  5623. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_WINOGRAD", inst) >= 0);
  5624. EnumWrapper<Correlation::Format>::pyobj_insts[11] = inst;
  5625. }{
  5626. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5627. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4_NCHW32;
  5628. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW32", inst) >= 0);
  5629. EnumWrapper<Correlation::Format>::pyobj_insts[12] = inst;
  5630. }{
  5631. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5632. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW32_NCHW4;
  5633. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32_NCHW4", inst) >= 0);
  5634. EnumWrapper<Correlation::Format>::pyobj_insts[13] = inst;
  5635. }{
  5636. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5637. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4_NCHW;
  5638. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW", inst) >= 0);
  5639. EnumWrapper<Correlation::Format>::pyobj_insts[14] = inst;
  5640. }{
  5641. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5642. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWC_NCHW;
  5643. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW", inst) >= 0);
  5644. EnumWrapper<Correlation::Format>::pyobj_insts[15] = inst;
  5645. }{
  5646. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5647. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NHWC_NCHW4_IC_SMALL;
  5648. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW4_IC_SMALL", inst) >= 0);
  5649. EnumWrapper<Correlation::Format>::pyobj_insts[16] = inst;
  5650. }{
  5651. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5652. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW_NCHW4_IC_SMALL;
  5653. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_NCHW4_IC_SMALL", inst) >= 0);
  5654. EnumWrapper<Correlation::Format>::pyobj_insts[17] = inst;
  5655. }{
  5656. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5657. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::CHWN4;
  5658. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CHWN4", inst) >= 0);
  5659. EnumWrapper<Correlation::Format>::pyobj_insts[18] = inst;
  5660. }{
  5661. PyObject* inst = e_type->tp_alloc(e_type, 0);
  5662. reinterpret_cast<EnumWrapper<Correlation::Format>*>(inst)->value = Correlation::Format::NCHW4_NHWC;
  5663. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NHWC", inst) >= 0);
  5664. EnumWrapper<Correlation::Format>::pyobj_insts[19] = inst;
  5665. }
  5666. Py_INCREF(e_type);
  5667. mgb_assert(PyDict_SetItemString(
  5668. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  5669. }
  5670. PyOpDefBegin(Correlation) // {
  5671. static PyGetSetDef py_getsetters[];
  5672. static PyMethodDef tp_methods[];
  5673. static PyObject* getstate(PyObject* self, PyObject*) {
  5674. auto& opdef = reinterpret_cast<PyOp(Correlation)*>(self)->inst();
  5675. static_cast<void>(opdef);
  5676. std::unordered_map<std::string, py::object> state {
  5677. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  5678. {"kernel_size", serialization<decltype(opdef.kernel_size)>::dump(opdef.kernel_size)},
  5679. {"max_displacement", serialization<decltype(opdef.max_displacement)>::dump(opdef.max_displacement)},
  5680. {"stride1", serialization<decltype(opdef.stride1)>::dump(opdef.stride1)},
  5681. {"stride2", serialization<decltype(opdef.stride2)>::dump(opdef.stride2)},
  5682. {"pad_size", serialization<decltype(opdef.pad_size)>::dump(opdef.pad_size)},
  5683. {"is_multiply", serialization<decltype(opdef.is_multiply)>::dump(opdef.is_multiply)}
  5684. };
  5685. return py::cast(state).release().ptr();
  5686. }
  5687. static PyObject* setstate(PyObject* self, PyObject* args) {
  5688. PyObject* dict = PyTuple_GetItem(args, 0);
  5689. if (!dict) return NULL;
  5690. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5691. auto& opdef = reinterpret_cast<PyOp(Correlation)*>(self)->inst();
  5692. static_cast<void>(opdef);
  5693. {
  5694. auto&& iter = state.find("format");
  5695. if (iter != state.end()) {
  5696. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  5697. }
  5698. }
  5699. {
  5700. auto&& iter = state.find("kernel_size");
  5701. if (iter != state.end()) {
  5702. opdef.kernel_size = serialization<decltype(opdef.kernel_size)>::load(iter->second);
  5703. }
  5704. }
  5705. {
  5706. auto&& iter = state.find("max_displacement");
  5707. if (iter != state.end()) {
  5708. opdef.max_displacement = serialization<decltype(opdef.max_displacement)>::load(iter->second);
  5709. }
  5710. }
  5711. {
  5712. auto&& iter = state.find("stride1");
  5713. if (iter != state.end()) {
  5714. opdef.stride1 = serialization<decltype(opdef.stride1)>::load(iter->second);
  5715. }
  5716. }
  5717. {
  5718. auto&& iter = state.find("stride2");
  5719. if (iter != state.end()) {
  5720. opdef.stride2 = serialization<decltype(opdef.stride2)>::load(iter->second);
  5721. }
  5722. }
  5723. {
  5724. auto&& iter = state.find("pad_size");
  5725. if (iter != state.end()) {
  5726. opdef.pad_size = serialization<decltype(opdef.pad_size)>::load(iter->second);
  5727. }
  5728. }
  5729. {
  5730. auto&& iter = state.find("is_multiply");
  5731. if (iter != state.end()) {
  5732. opdef.is_multiply = serialization<decltype(opdef.is_multiply)>::load(iter->second);
  5733. }
  5734. }
  5735. Py_RETURN_NONE;
  5736. }
  5737. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5738. // };
  5739. PyOpDefEnd(Correlation)
  5740. int PyOp(Correlation)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5741. static const char* kwlist[] = {"format", "kernel_size", "max_displacement", "stride1", "stride2", "pad_size", "is_multiply", "scope", NULL};
  5742. PyObject *format = NULL, *kernel_size = NULL, *max_displacement = NULL, *stride1 = NULL, *stride2 = NULL, *pad_size = NULL, *is_multiply = NULL, *scope = NULL;
  5743. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &format, &kernel_size, &max_displacement, &stride1, &stride2, &pad_size, &is_multiply, &scope))
  5744. return -1;
  5745. if (format) {
  5746. try {
  5747. // TODO: remove this guard which is used for pybind11 implicit conversion
  5748. py::detail::loader_life_support guard{};
  5749. reinterpret_cast<PyOp(Correlation)*>(self)->inst().format =
  5750. py::cast<decltype(Correlation::format)>(py::handle(format));
  5751. } CATCH_ALL(-1)
  5752. }
  5753. if (kernel_size) {
  5754. try {
  5755. // TODO: remove this guard which is used for pybind11 implicit conversion
  5756. py::detail::loader_life_support guard{};
  5757. reinterpret_cast<PyOp(Correlation)*>(self)->inst().kernel_size =
  5758. py::cast<decltype(Correlation::kernel_size)>(py::handle(kernel_size));
  5759. } CATCH_ALL(-1)
  5760. }
  5761. if (max_displacement) {
  5762. try {
  5763. // TODO: remove this guard which is used for pybind11 implicit conversion
  5764. py::detail::loader_life_support guard{};
  5765. reinterpret_cast<PyOp(Correlation)*>(self)->inst().max_displacement =
  5766. py::cast<decltype(Correlation::max_displacement)>(py::handle(max_displacement));
  5767. } CATCH_ALL(-1)
  5768. }
  5769. if (stride1) {
  5770. try {
  5771. // TODO: remove this guard which is used for pybind11 implicit conversion
  5772. py::detail::loader_life_support guard{};
  5773. reinterpret_cast<PyOp(Correlation)*>(self)->inst().stride1 =
  5774. py::cast<decltype(Correlation::stride1)>(py::handle(stride1));
  5775. } CATCH_ALL(-1)
  5776. }
  5777. if (stride2) {
  5778. try {
  5779. // TODO: remove this guard which is used for pybind11 implicit conversion
  5780. py::detail::loader_life_support guard{};
  5781. reinterpret_cast<PyOp(Correlation)*>(self)->inst().stride2 =
  5782. py::cast<decltype(Correlation::stride2)>(py::handle(stride2));
  5783. } CATCH_ALL(-1)
  5784. }
  5785. if (pad_size) {
  5786. try {
  5787. // TODO: remove this guard which is used for pybind11 implicit conversion
  5788. py::detail::loader_life_support guard{};
  5789. reinterpret_cast<PyOp(Correlation)*>(self)->inst().pad_size =
  5790. py::cast<decltype(Correlation::pad_size)>(py::handle(pad_size));
  5791. } CATCH_ALL(-1)
  5792. }
  5793. if (is_multiply) {
  5794. try {
  5795. // TODO: remove this guard which is used for pybind11 implicit conversion
  5796. py::detail::loader_life_support guard{};
  5797. reinterpret_cast<PyOp(Correlation)*>(self)->inst().is_multiply =
  5798. py::cast<decltype(Correlation::is_multiply)>(py::handle(is_multiply));
  5799. } CATCH_ALL(-1)
  5800. }
  5801. if (scope) {
  5802. try {
  5803. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5804. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5805. } CATCH_ALL(-1)
  5806. }
  5807. return 0;
  5808. }
  5809. PyGetSetDef PyOp(Correlation)::py_getsetters[] = {
  5810. {const_cast<char*>("format"), py_get_generic(Correlation, format), py_set_generic(Correlation, format), const_cast<char*>("format"), NULL},
  5811. {const_cast<char*>("kernel_size"), py_get_generic(Correlation, kernel_size), py_set_generic(Correlation, kernel_size), const_cast<char*>("kernel_size"), NULL},
  5812. {const_cast<char*>("max_displacement"), py_get_generic(Correlation, max_displacement), py_set_generic(Correlation, max_displacement), const_cast<char*>("max_displacement"), NULL},
  5813. {const_cast<char*>("stride1"), py_get_generic(Correlation, stride1), py_set_generic(Correlation, stride1), const_cast<char*>("stride1"), NULL},
  5814. {const_cast<char*>("stride2"), py_get_generic(Correlation, stride2), py_set_generic(Correlation, stride2), const_cast<char*>("stride2"), NULL},
  5815. {const_cast<char*>("pad_size"), py_get_generic(Correlation, pad_size), py_set_generic(Correlation, pad_size), const_cast<char*>("pad_size"), NULL},
  5816. {const_cast<char*>("is_multiply"), py_get_generic(Correlation, is_multiply), py_set_generic(Correlation, is_multiply), const_cast<char*>("is_multiply"), NULL},
  5817. {NULL} /* Sentinel */
  5818. };
  5819. PyMethodDef PyOp(Correlation)::tp_methods[] = {
  5820. {const_cast<char*>("__getstate__"), PyOp(Correlation)::getstate, METH_NOARGS, "Correlation getstate"},
  5821. {const_cast<char*>("__setstate__"), PyOp(Correlation)::setstate, METH_VARARGS, "Correlation setstate"},
  5822. {NULL} /* Sentinel */
  5823. };
  5824. void _init_py_Correlation(py::module m) {
  5825. using py_op = PyOp(Correlation);
  5826. auto& py_type = PyOpType(Correlation);
  5827. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5828. py_type.tp_name = "megengine.core._imperative_rt.ops.Correlation";
  5829. py_type.tp_basicsize = sizeof(PyOp(Correlation));
  5830. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5831. py_type.tp_doc = "Correlation";
  5832. py_type.tp_base = &PyOpType(OpDef);
  5833. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5834. py_type.tp_new = py_new_generic<py_op>;
  5835. py_type.tp_init = py_op::py_init;
  5836. py_type.tp_methods = py_op::tp_methods;
  5837. py_type.tp_getset = py_op::py_getsetters;
  5838. mgb_assert(PyType_Ready(&py_type) >= 0);
  5839. _init_py_Correlation_Format(py_type);
  5840. PyType_Modified(&py_type);
  5841. m.add_object("Correlation", reinterpret_cast<PyObject*>(&py_type));
  5842. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Correlation::typeinfo(), &py_type).second);
  5843. }
  5844. PyOpDefBegin(Cumprod) // {
  5845. static PyGetSetDef py_getsetters[];
  5846. static PyMethodDef tp_methods[];
  5847. static PyObject* getstate(PyObject* self, PyObject*) {
  5848. auto& opdef = reinterpret_cast<PyOp(Cumprod)*>(self)->inst();
  5849. static_cast<void>(opdef);
  5850. std::unordered_map<std::string, py::object> state {
  5851. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  5852. {"exclusive", serialization<decltype(opdef.exclusive)>::dump(opdef.exclusive)},
  5853. {"reverse", serialization<decltype(opdef.reverse)>::dump(opdef.reverse)}
  5854. };
  5855. return py::cast(state).release().ptr();
  5856. }
  5857. static PyObject* setstate(PyObject* self, PyObject* args) {
  5858. PyObject* dict = PyTuple_GetItem(args, 0);
  5859. if (!dict) return NULL;
  5860. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5861. auto& opdef = reinterpret_cast<PyOp(Cumprod)*>(self)->inst();
  5862. static_cast<void>(opdef);
  5863. {
  5864. auto&& iter = state.find("axis");
  5865. if (iter != state.end()) {
  5866. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  5867. }
  5868. }
  5869. {
  5870. auto&& iter = state.find("exclusive");
  5871. if (iter != state.end()) {
  5872. opdef.exclusive = serialization<decltype(opdef.exclusive)>::load(iter->second);
  5873. }
  5874. }
  5875. {
  5876. auto&& iter = state.find("reverse");
  5877. if (iter != state.end()) {
  5878. opdef.reverse = serialization<decltype(opdef.reverse)>::load(iter->second);
  5879. }
  5880. }
  5881. Py_RETURN_NONE;
  5882. }
  5883. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5884. // };
  5885. PyOpDefEnd(Cumprod)
  5886. int PyOp(Cumprod)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5887. static const char* kwlist[] = {"axis", "exclusive", "reverse", "scope", NULL};
  5888. PyObject *axis = NULL, *exclusive = NULL, *reverse = NULL, *scope = NULL;
  5889. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &axis, &exclusive, &reverse, &scope))
  5890. return -1;
  5891. if (axis) {
  5892. try {
  5893. // TODO: remove this guard which is used for pybind11 implicit conversion
  5894. py::detail::loader_life_support guard{};
  5895. reinterpret_cast<PyOp(Cumprod)*>(self)->inst().axis =
  5896. py::cast<decltype(Cumprod::axis)>(py::handle(axis));
  5897. } CATCH_ALL(-1)
  5898. }
  5899. if (exclusive) {
  5900. try {
  5901. // TODO: remove this guard which is used for pybind11 implicit conversion
  5902. py::detail::loader_life_support guard{};
  5903. reinterpret_cast<PyOp(Cumprod)*>(self)->inst().exclusive =
  5904. py::cast<decltype(Cumprod::exclusive)>(py::handle(exclusive));
  5905. } CATCH_ALL(-1)
  5906. }
  5907. if (reverse) {
  5908. try {
  5909. // TODO: remove this guard which is used for pybind11 implicit conversion
  5910. py::detail::loader_life_support guard{};
  5911. reinterpret_cast<PyOp(Cumprod)*>(self)->inst().reverse =
  5912. py::cast<decltype(Cumprod::reverse)>(py::handle(reverse));
  5913. } CATCH_ALL(-1)
  5914. }
  5915. if (scope) {
  5916. try {
  5917. reinterpret_cast<PyOp(OpDef)*>(self)->op
  5918. ->set_scope(py::cast<std::string>(py::handle(scope)));
  5919. } CATCH_ALL(-1)
  5920. }
  5921. return 0;
  5922. }
  5923. PyGetSetDef PyOp(Cumprod)::py_getsetters[] = {
  5924. {const_cast<char*>("axis"), py_get_generic(Cumprod, axis), py_set_generic(Cumprod, axis), const_cast<char*>("axis"), NULL},
  5925. {const_cast<char*>("exclusive"), py_get_generic(Cumprod, exclusive), py_set_generic(Cumprod, exclusive), const_cast<char*>("exclusive"), NULL},
  5926. {const_cast<char*>("reverse"), py_get_generic(Cumprod, reverse), py_set_generic(Cumprod, reverse), const_cast<char*>("reverse"), NULL},
  5927. {NULL} /* Sentinel */
  5928. };
  5929. PyMethodDef PyOp(Cumprod)::tp_methods[] = {
  5930. {const_cast<char*>("__getstate__"), PyOp(Cumprod)::getstate, METH_NOARGS, "Cumprod getstate"},
  5931. {const_cast<char*>("__setstate__"), PyOp(Cumprod)::setstate, METH_VARARGS, "Cumprod setstate"},
  5932. {NULL} /* Sentinel */
  5933. };
  5934. void _init_py_Cumprod(py::module m) {
  5935. using py_op = PyOp(Cumprod);
  5936. auto& py_type = PyOpType(Cumprod);
  5937. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5938. py_type.tp_name = "megengine.core._imperative_rt.ops.Cumprod";
  5939. py_type.tp_basicsize = sizeof(PyOp(Cumprod));
  5940. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5941. py_type.tp_doc = "Cumprod";
  5942. py_type.tp_base = &PyOpType(OpDef);
  5943. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  5944. py_type.tp_new = py_new_generic<py_op>;
  5945. py_type.tp_init = py_op::py_init;
  5946. py_type.tp_methods = py_op::tp_methods;
  5947. py_type.tp_getset = py_op::py_getsetters;
  5948. mgb_assert(PyType_Ready(&py_type) >= 0);
  5949. PyType_Modified(&py_type);
  5950. m.add_object("Cumprod", reinterpret_cast<PyObject*>(&py_type));
  5951. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Cumprod::typeinfo(), &py_type).second);
  5952. }
  5953. PyOpDefBegin(Cumsum) // {
  5954. static PyGetSetDef py_getsetters[];
  5955. static PyMethodDef tp_methods[];
  5956. static PyObject* getstate(PyObject* self, PyObject*) {
  5957. auto& opdef = reinterpret_cast<PyOp(Cumsum)*>(self)->inst();
  5958. static_cast<void>(opdef);
  5959. std::unordered_map<std::string, py::object> state {
  5960. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  5961. {"exclusive", serialization<decltype(opdef.exclusive)>::dump(opdef.exclusive)},
  5962. {"reverse", serialization<decltype(opdef.reverse)>::dump(opdef.reverse)}
  5963. };
  5964. return py::cast(state).release().ptr();
  5965. }
  5966. static PyObject* setstate(PyObject* self, PyObject* args) {
  5967. PyObject* dict = PyTuple_GetItem(args, 0);
  5968. if (!dict) return NULL;
  5969. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  5970. auto& opdef = reinterpret_cast<PyOp(Cumsum)*>(self)->inst();
  5971. static_cast<void>(opdef);
  5972. {
  5973. auto&& iter = state.find("axis");
  5974. if (iter != state.end()) {
  5975. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  5976. }
  5977. }
  5978. {
  5979. auto&& iter = state.find("exclusive");
  5980. if (iter != state.end()) {
  5981. opdef.exclusive = serialization<decltype(opdef.exclusive)>::load(iter->second);
  5982. }
  5983. }
  5984. {
  5985. auto&& iter = state.find("reverse");
  5986. if (iter != state.end()) {
  5987. opdef.reverse = serialization<decltype(opdef.reverse)>::load(iter->second);
  5988. }
  5989. }
  5990. Py_RETURN_NONE;
  5991. }
  5992. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  5993. // };
  5994. PyOpDefEnd(Cumsum)
  5995. int PyOp(Cumsum)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  5996. static const char* kwlist[] = {"axis", "exclusive", "reverse", "scope", NULL};
  5997. PyObject *axis = NULL, *exclusive = NULL, *reverse = NULL, *scope = NULL;
  5998. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &axis, &exclusive, &reverse, &scope))
  5999. return -1;
  6000. if (axis) {
  6001. try {
  6002. // TODO: remove this guard which is used for pybind11 implicit conversion
  6003. py::detail::loader_life_support guard{};
  6004. reinterpret_cast<PyOp(Cumsum)*>(self)->inst().axis =
  6005. py::cast<decltype(Cumsum::axis)>(py::handle(axis));
  6006. } CATCH_ALL(-1)
  6007. }
  6008. if (exclusive) {
  6009. try {
  6010. // TODO: remove this guard which is used for pybind11 implicit conversion
  6011. py::detail::loader_life_support guard{};
  6012. reinterpret_cast<PyOp(Cumsum)*>(self)->inst().exclusive =
  6013. py::cast<decltype(Cumsum::exclusive)>(py::handle(exclusive));
  6014. } CATCH_ALL(-1)
  6015. }
  6016. if (reverse) {
  6017. try {
  6018. // TODO: remove this guard which is used for pybind11 implicit conversion
  6019. py::detail::loader_life_support guard{};
  6020. reinterpret_cast<PyOp(Cumsum)*>(self)->inst().reverse =
  6021. py::cast<decltype(Cumsum::reverse)>(py::handle(reverse));
  6022. } CATCH_ALL(-1)
  6023. }
  6024. if (scope) {
  6025. try {
  6026. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6027. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6028. } CATCH_ALL(-1)
  6029. }
  6030. return 0;
  6031. }
  6032. PyGetSetDef PyOp(Cumsum)::py_getsetters[] = {
  6033. {const_cast<char*>("axis"), py_get_generic(Cumsum, axis), py_set_generic(Cumsum, axis), const_cast<char*>("axis"), NULL},
  6034. {const_cast<char*>("exclusive"), py_get_generic(Cumsum, exclusive), py_set_generic(Cumsum, exclusive), const_cast<char*>("exclusive"), NULL},
  6035. {const_cast<char*>("reverse"), py_get_generic(Cumsum, reverse), py_set_generic(Cumsum, reverse), const_cast<char*>("reverse"), NULL},
  6036. {NULL} /* Sentinel */
  6037. };
  6038. PyMethodDef PyOp(Cumsum)::tp_methods[] = {
  6039. {const_cast<char*>("__getstate__"), PyOp(Cumsum)::getstate, METH_NOARGS, "Cumsum getstate"},
  6040. {const_cast<char*>("__setstate__"), PyOp(Cumsum)::setstate, METH_VARARGS, "Cumsum setstate"},
  6041. {NULL} /* Sentinel */
  6042. };
  6043. void _init_py_Cumsum(py::module m) {
  6044. using py_op = PyOp(Cumsum);
  6045. auto& py_type = PyOpType(Cumsum);
  6046. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6047. py_type.tp_name = "megengine.core._imperative_rt.ops.Cumsum";
  6048. py_type.tp_basicsize = sizeof(PyOp(Cumsum));
  6049. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6050. py_type.tp_doc = "Cumsum";
  6051. py_type.tp_base = &PyOpType(OpDef);
  6052. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6053. py_type.tp_new = py_new_generic<py_op>;
  6054. py_type.tp_init = py_op::py_init;
  6055. py_type.tp_methods = py_op::tp_methods;
  6056. py_type.tp_getset = py_op::py_getsetters;
  6057. mgb_assert(PyType_Ready(&py_type) >= 0);
  6058. PyType_Modified(&py_type);
  6059. m.add_object("Cumsum", reinterpret_cast<PyObject*>(&py_type));
  6060. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Cumsum::typeinfo(), &py_type).second);
  6061. }
  6062. template<> struct EnumTrait<CvtColor::Mode> {
  6063. static constexpr const char *name = "CvtColor.Mode";
  6064. static constexpr std::underlying_type_t<CvtColor::Mode> max = 32 - 1;
  6065. };
  6066. template<> PyTypeObject* EnumWrapper<CvtColor::Mode>::type = nullptr;
  6067. template<> const char*
  6068. EnumWrapper<CvtColor::Mode>::members[] = {"RGB2GRAY", "RGB2YUV", "YUV2RGB", "GRAY2RGB", "RGBA2RGB", "RGBA2BGR", "RGBA2GRAY", "RGB2BGR", "BGR2GRAY", "BGR2RGB", "YUV2GRAY_NV21", "YUV2RGB_NV21", "YUV2BGR_NV21", "YUV2GRAY_NV12", "YUV2RGB_NV12", "YUV2BGR_NV12", "YUV2GRAY_YV12", "YUV2RGB_YV12", "YUV2BGR_YV12", "YUV2GRAY_YU12", "YUV2RGB_YU12", "YUV2BGR_YU12", "YCrCb2RGB", "YCrCb2BGR", "BT601_YUV2RGB_NV21", "BT601_YUV2BGR_NV21", "BT601_YUV2RGB_NV12", "BT601_YUV2BGR_NV12", "BT601_YUV2RGB_YV12", "BT601_YUV2BGR_YV12", "BT601_YUV2RGB_YU12", "BT601_YUV2BGR_YU12"};
  6069. template<> std::unordered_map<std::string, CvtColor::Mode>
  6070. EnumWrapper<CvtColor::Mode>::mem2value = {{normalize_enum("RGB2GRAY"), CvtColor::Mode::RGB2GRAY}, {normalize_enum("RGB2YUV"), CvtColor::Mode::RGB2YUV}, {normalize_enum("YUV2RGB"), CvtColor::Mode::YUV2RGB}, {normalize_enum("GRAY2RGB"), CvtColor::Mode::GRAY2RGB}, {normalize_enum("RGBA2RGB"), CvtColor::Mode::RGBA2RGB}, {normalize_enum("RGBA2BGR"), CvtColor::Mode::RGBA2BGR}, {normalize_enum("RGBA2GRAY"), CvtColor::Mode::RGBA2GRAY}, {normalize_enum("RGB2BGR"), CvtColor::Mode::RGB2BGR}, {normalize_enum("BGR2GRAY"), CvtColor::Mode::BGR2GRAY}, {normalize_enum("BGR2RGB"), CvtColor::Mode::BGR2RGB}, {normalize_enum("YUV2GRAY_NV21"), CvtColor::Mode::YUV2GRAY_NV21}, {normalize_enum("YUV2RGB_NV21"), CvtColor::Mode::YUV2RGB_NV21}, {normalize_enum("YUV2BGR_NV21"), CvtColor::Mode::YUV2BGR_NV21}, {normalize_enum("YUV2GRAY_NV12"), CvtColor::Mode::YUV2GRAY_NV12}, {normalize_enum("YUV2RGB_NV12"), CvtColor::Mode::YUV2RGB_NV12}, {normalize_enum("YUV2BGR_NV12"), CvtColor::Mode::YUV2BGR_NV12}, {normalize_enum("YUV2GRAY_YV12"), CvtColor::Mode::YUV2GRAY_YV12}, {normalize_enum("YUV2RGB_YV12"), CvtColor::Mode::YUV2RGB_YV12}, {normalize_enum("YUV2BGR_YV12"), CvtColor::Mode::YUV2BGR_YV12}, {normalize_enum("YUV2GRAY_YU12"), CvtColor::Mode::YUV2GRAY_YU12}, {normalize_enum("YUV2RGB_YU12"), CvtColor::Mode::YUV2RGB_YU12}, {normalize_enum("YUV2BGR_YU12"), CvtColor::Mode::YUV2BGR_YU12}, {normalize_enum("YCrCb2RGB"), CvtColor::Mode::YCrCb2RGB}, {normalize_enum("YCrCb2BGR"), CvtColor::Mode::YCrCb2BGR}, {normalize_enum("BT601_YUV2RGB_NV21"), CvtColor::Mode::BT601_YUV2RGB_NV21}, {normalize_enum("BT601_YUV2BGR_NV21"), CvtColor::Mode::BT601_YUV2BGR_NV21}, {normalize_enum("BT601_YUV2RGB_NV12"), CvtColor::Mode::BT601_YUV2RGB_NV12}, {normalize_enum("BT601_YUV2BGR_NV12"), CvtColor::Mode::BT601_YUV2BGR_NV12}, {normalize_enum("BT601_YUV2RGB_YV12"), CvtColor::Mode::BT601_YUV2RGB_YV12}, {normalize_enum("BT601_YUV2BGR_YV12"), CvtColor::Mode::BT601_YUV2BGR_YV12}, {normalize_enum("BT601_YUV2RGB_YU12"), CvtColor::Mode::BT601_YUV2RGB_YU12}, {normalize_enum("BT601_YUV2BGR_YU12"), CvtColor::Mode::BT601_YUV2BGR_YU12}};
  6071. template<> PyObject* EnumWrapper<CvtColor::Mode>::pyobj_insts[32] = {nullptr};
  6072. void _init_py_CvtColor_Mode(PyTypeObject& py_type) {
  6073. auto& e_type = EnumWrapper<CvtColor::Mode>::type;
  6074. static PyMethodDef tp_methods[] = {
  6075. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<CvtColor::Mode>::py_dump, METH_NOARGS, NULL},
  6076. {NULL} /* Sentinel */
  6077. };
  6078. static PyType_Slot slots[] = {
  6079. {Py_tp_repr, (void*)EnumWrapper<CvtColor::Mode>::py_repr},
  6080. {Py_tp_richcompare, (void*)EnumWrapper<CvtColor::Mode>::tp_richcompare},
  6081. {Py_tp_methods, tp_methods},
  6082. {0, NULL}
  6083. };
  6084. static PyType_Spec spec = {
  6085. // name
  6086. "megengine.core._imperative_rt.ops.CvtColor.Mode",
  6087. // basicsize
  6088. sizeof(EnumWrapper<CvtColor::Mode>),
  6089. // itemsize
  6090. 0,
  6091. // flags
  6092. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  6093. // slots
  6094. slots
  6095. };
  6096. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  6097. mgb_assert(
  6098. e_type->tp_setattro(
  6099. reinterpret_cast<PyObject*>(e_type),
  6100. py::cast("__name__").release().ptr(),
  6101. py::cast("Mode").release().ptr()) >= 0);
  6102. mgb_assert(
  6103. e_type->tp_setattro(
  6104. reinterpret_cast<PyObject*>(e_type),
  6105. py::cast("__module__").release().ptr(),
  6106. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  6107. mgb_assert(
  6108. e_type->tp_setattro(
  6109. reinterpret_cast<PyObject*>(e_type),
  6110. py::cast("__qualname__").release().ptr(),
  6111. py::cast("CvtColor.Mode").release().ptr()) >= 0);
  6112. {
  6113. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6114. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2GRAY;
  6115. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2GRAY", inst) >= 0);
  6116. EnumWrapper<CvtColor::Mode>::pyobj_insts[0] = inst;
  6117. }{
  6118. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6119. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2YUV;
  6120. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2YUV", inst) >= 0);
  6121. EnumWrapper<CvtColor::Mode>::pyobj_insts[1] = inst;
  6122. }{
  6123. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6124. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB;
  6125. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB", inst) >= 0);
  6126. EnumWrapper<CvtColor::Mode>::pyobj_insts[2] = inst;
  6127. }{
  6128. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6129. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::GRAY2RGB;
  6130. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GRAY2RGB", inst) >= 0);
  6131. EnumWrapper<CvtColor::Mode>::pyobj_insts[3] = inst;
  6132. }{
  6133. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6134. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2RGB;
  6135. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2RGB", inst) >= 0);
  6136. EnumWrapper<CvtColor::Mode>::pyobj_insts[4] = inst;
  6137. }{
  6138. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6139. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2BGR;
  6140. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2BGR", inst) >= 0);
  6141. EnumWrapper<CvtColor::Mode>::pyobj_insts[5] = inst;
  6142. }{
  6143. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6144. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2GRAY;
  6145. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2GRAY", inst) >= 0);
  6146. EnumWrapper<CvtColor::Mode>::pyobj_insts[6] = inst;
  6147. }{
  6148. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6149. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2BGR;
  6150. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2BGR", inst) >= 0);
  6151. EnumWrapper<CvtColor::Mode>::pyobj_insts[7] = inst;
  6152. }{
  6153. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6154. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BGR2GRAY;
  6155. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2GRAY", inst) >= 0);
  6156. EnumWrapper<CvtColor::Mode>::pyobj_insts[8] = inst;
  6157. }{
  6158. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6159. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BGR2RGB;
  6160. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2RGB", inst) >= 0);
  6161. EnumWrapper<CvtColor::Mode>::pyobj_insts[9] = inst;
  6162. }{
  6163. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6164. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV21;
  6165. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV21", inst) >= 0);
  6166. EnumWrapper<CvtColor::Mode>::pyobj_insts[10] = inst;
  6167. }{
  6168. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6169. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_NV21;
  6170. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV21", inst) >= 0);
  6171. EnumWrapper<CvtColor::Mode>::pyobj_insts[11] = inst;
  6172. }{
  6173. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6174. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_NV21;
  6175. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV21", inst) >= 0);
  6176. EnumWrapper<CvtColor::Mode>::pyobj_insts[12] = inst;
  6177. }{
  6178. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6179. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV12;
  6180. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV12", inst) >= 0);
  6181. EnumWrapper<CvtColor::Mode>::pyobj_insts[13] = inst;
  6182. }{
  6183. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6184. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_NV12;
  6185. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV12", inst) >= 0);
  6186. EnumWrapper<CvtColor::Mode>::pyobj_insts[14] = inst;
  6187. }{
  6188. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6189. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_NV12;
  6190. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV12", inst) >= 0);
  6191. EnumWrapper<CvtColor::Mode>::pyobj_insts[15] = inst;
  6192. }{
  6193. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6194. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_YV12;
  6195. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YV12", inst) >= 0);
  6196. EnumWrapper<CvtColor::Mode>::pyobj_insts[16] = inst;
  6197. }{
  6198. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6199. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_YV12;
  6200. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YV12", inst) >= 0);
  6201. EnumWrapper<CvtColor::Mode>::pyobj_insts[17] = inst;
  6202. }{
  6203. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6204. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_YV12;
  6205. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YV12", inst) >= 0);
  6206. EnumWrapper<CvtColor::Mode>::pyobj_insts[18] = inst;
  6207. }{
  6208. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6209. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_YU12;
  6210. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YU12", inst) >= 0);
  6211. EnumWrapper<CvtColor::Mode>::pyobj_insts[19] = inst;
  6212. }{
  6213. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6214. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_YU12;
  6215. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YU12", inst) >= 0);
  6216. EnumWrapper<CvtColor::Mode>::pyobj_insts[20] = inst;
  6217. }{
  6218. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6219. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_YU12;
  6220. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YU12", inst) >= 0);
  6221. EnumWrapper<CvtColor::Mode>::pyobj_insts[21] = inst;
  6222. }{
  6223. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6224. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YCrCb2RGB;
  6225. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2RGB", inst) >= 0);
  6226. EnumWrapper<CvtColor::Mode>::pyobj_insts[22] = inst;
  6227. }{
  6228. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6229. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YCrCb2BGR;
  6230. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2BGR", inst) >= 0);
  6231. EnumWrapper<CvtColor::Mode>::pyobj_insts[23] = inst;
  6232. }{
  6233. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6234. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV21;
  6235. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV21", inst) >= 0);
  6236. EnumWrapper<CvtColor::Mode>::pyobj_insts[24] = inst;
  6237. }{
  6238. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6239. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV21;
  6240. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV21", inst) >= 0);
  6241. EnumWrapper<CvtColor::Mode>::pyobj_insts[25] = inst;
  6242. }{
  6243. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6244. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV12;
  6245. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV12", inst) >= 0);
  6246. EnumWrapper<CvtColor::Mode>::pyobj_insts[26] = inst;
  6247. }{
  6248. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6249. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV12;
  6250. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV12", inst) >= 0);
  6251. EnumWrapper<CvtColor::Mode>::pyobj_insts[27] = inst;
  6252. }{
  6253. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6254. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YV12;
  6255. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YV12", inst) >= 0);
  6256. EnumWrapper<CvtColor::Mode>::pyobj_insts[28] = inst;
  6257. }{
  6258. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6259. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YV12;
  6260. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YV12", inst) >= 0);
  6261. EnumWrapper<CvtColor::Mode>::pyobj_insts[29] = inst;
  6262. }{
  6263. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6264. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YU12;
  6265. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YU12", inst) >= 0);
  6266. EnumWrapper<CvtColor::Mode>::pyobj_insts[30] = inst;
  6267. }{
  6268. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6269. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YU12;
  6270. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YU12", inst) >= 0);
  6271. EnumWrapper<CvtColor::Mode>::pyobj_insts[31] = inst;
  6272. }
  6273. Py_INCREF(e_type);
  6274. mgb_assert(PyDict_SetItemString(
  6275. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6276. }
  6277. PyOpDefBegin(CvtColor) // {
  6278. static PyGetSetDef py_getsetters[];
  6279. static PyMethodDef tp_methods[];
  6280. static PyObject* getstate(PyObject* self, PyObject*) {
  6281. auto& opdef = reinterpret_cast<PyOp(CvtColor)*>(self)->inst();
  6282. static_cast<void>(opdef);
  6283. std::unordered_map<std::string, py::object> state {
  6284. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  6285. };
  6286. return py::cast(state).release().ptr();
  6287. }
  6288. static PyObject* setstate(PyObject* self, PyObject* args) {
  6289. PyObject* dict = PyTuple_GetItem(args, 0);
  6290. if (!dict) return NULL;
  6291. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6292. auto& opdef = reinterpret_cast<PyOp(CvtColor)*>(self)->inst();
  6293. static_cast<void>(opdef);
  6294. {
  6295. auto&& iter = state.find("mode");
  6296. if (iter != state.end()) {
  6297. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  6298. }
  6299. }
  6300. Py_RETURN_NONE;
  6301. }
  6302. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6303. // };
  6304. PyOpDefEnd(CvtColor)
  6305. int PyOp(CvtColor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6306. static const char* kwlist[] = {"mode", "scope", NULL};
  6307. PyObject *mode = NULL, *scope = NULL;
  6308. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  6309. return -1;
  6310. if (mode) {
  6311. try {
  6312. // TODO: remove this guard which is used for pybind11 implicit conversion
  6313. py::detail::loader_life_support guard{};
  6314. reinterpret_cast<PyOp(CvtColor)*>(self)->inst().mode =
  6315. py::cast<decltype(CvtColor::mode)>(py::handle(mode));
  6316. } CATCH_ALL(-1)
  6317. }
  6318. if (scope) {
  6319. try {
  6320. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6321. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6322. } CATCH_ALL(-1)
  6323. }
  6324. return 0;
  6325. }
  6326. PyGetSetDef PyOp(CvtColor)::py_getsetters[] = {
  6327. {const_cast<char*>("mode"), py_get_generic(CvtColor, mode), py_set_generic(CvtColor, mode), const_cast<char*>("mode"), NULL},
  6328. {NULL} /* Sentinel */
  6329. };
  6330. PyMethodDef PyOp(CvtColor)::tp_methods[] = {
  6331. {const_cast<char*>("__getstate__"), PyOp(CvtColor)::getstate, METH_NOARGS, "CvtColor getstate"},
  6332. {const_cast<char*>("__setstate__"), PyOp(CvtColor)::setstate, METH_VARARGS, "CvtColor setstate"},
  6333. {NULL} /* Sentinel */
  6334. };
  6335. void _init_py_CvtColor(py::module m) {
  6336. using py_op = PyOp(CvtColor);
  6337. auto& py_type = PyOpType(CvtColor);
  6338. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6339. py_type.tp_name = "megengine.core._imperative_rt.ops.CvtColor";
  6340. py_type.tp_basicsize = sizeof(PyOp(CvtColor));
  6341. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6342. py_type.tp_doc = "CvtColor";
  6343. py_type.tp_base = &PyOpType(OpDef);
  6344. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6345. py_type.tp_new = py_new_generic<py_op>;
  6346. py_type.tp_init = py_op::py_init;
  6347. py_type.tp_methods = py_op::tp_methods;
  6348. py_type.tp_getset = py_op::py_getsetters;
  6349. mgb_assert(PyType_Ready(&py_type) >= 0);
  6350. _init_py_CvtColor_Mode(py_type);
  6351. PyType_Modified(&py_type);
  6352. m.add_object("CvtColor", reinterpret_cast<PyObject*>(&py_type));
  6353. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CvtColor::typeinfo(), &py_type).second);
  6354. }
  6355. void _init_py_DeformableConv_Mode(PyTypeObject& py_type) {
  6356. auto& e_type = EnumWrapper<DeformableConv::Mode>::type;
  6357. Py_INCREF(e_type);
  6358. mgb_assert(PyDict_SetItemString(
  6359. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6360. }
  6361. void _init_py_DeformableConv_Sparse(PyTypeObject& py_type) {
  6362. auto& e_type = EnumWrapper<DeformableConv::Sparse>::type;
  6363. Py_INCREF(e_type);
  6364. mgb_assert(PyDict_SetItemString(
  6365. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6366. }
  6367. void _init_py_DeformableConv_Format(PyTypeObject& py_type) {
  6368. auto& e_type = EnumWrapper<DeformableConv::Format>::type;
  6369. Py_INCREF(e_type);
  6370. mgb_assert(PyDict_SetItemString(
  6371. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6372. }
  6373. void _init_py_DeformableConv_ComputeMode(PyTypeObject& py_type) {
  6374. auto& e_type = EnumWrapper<DeformableConv::ComputeMode>::type;
  6375. Py_INCREF(e_type);
  6376. mgb_assert(PyDict_SetItemString(
  6377. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6378. }
  6379. void _init_py_DeformableConv_Strategy(PyTypeObject& py_type) {
  6380. auto& e_type = BitCombinedEnumWrapper<DeformableConv::Strategy>::type;
  6381. Py_INCREF(e_type);
  6382. mgb_assert(PyDict_SetItemString(
  6383. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6384. }
  6385. PyOpDefBegin(DeformableConv) // {
  6386. static PyGetSetDef py_getsetters[];
  6387. static PyMethodDef tp_methods[];
  6388. static PyObject* getstate(PyObject* self, PyObject*) {
  6389. auto& opdef = reinterpret_cast<PyOp(DeformableConv)*>(self)->inst();
  6390. static_cast<void>(opdef);
  6391. std::unordered_map<std::string, py::object> state {
  6392. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  6393. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  6394. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  6395. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  6396. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  6397. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  6398. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  6399. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  6400. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  6401. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  6402. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  6403. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  6404. };
  6405. return py::cast(state).release().ptr();
  6406. }
  6407. static PyObject* setstate(PyObject* self, PyObject* args) {
  6408. PyObject* dict = PyTuple_GetItem(args, 0);
  6409. if (!dict) return NULL;
  6410. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6411. auto& opdef = reinterpret_cast<PyOp(DeformableConv)*>(self)->inst();
  6412. static_cast<void>(opdef);
  6413. {
  6414. auto&& iter = state.find("mode");
  6415. if (iter != state.end()) {
  6416. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  6417. }
  6418. }
  6419. {
  6420. auto&& iter = state.find("pad_h");
  6421. if (iter != state.end()) {
  6422. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  6423. }
  6424. }
  6425. {
  6426. auto&& iter = state.find("pad_w");
  6427. if (iter != state.end()) {
  6428. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  6429. }
  6430. }
  6431. {
  6432. auto&& iter = state.find("stride_h");
  6433. if (iter != state.end()) {
  6434. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  6435. }
  6436. }
  6437. {
  6438. auto&& iter = state.find("stride_w");
  6439. if (iter != state.end()) {
  6440. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  6441. }
  6442. }
  6443. {
  6444. auto&& iter = state.find("dilate_h");
  6445. if (iter != state.end()) {
  6446. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  6447. }
  6448. }
  6449. {
  6450. auto&& iter = state.find("dilate_w");
  6451. if (iter != state.end()) {
  6452. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  6453. }
  6454. }
  6455. {
  6456. auto&& iter = state.find("sparse");
  6457. if (iter != state.end()) {
  6458. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  6459. }
  6460. }
  6461. {
  6462. auto&& iter = state.find("format");
  6463. if (iter != state.end()) {
  6464. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  6465. }
  6466. }
  6467. {
  6468. auto&& iter = state.find("compute_mode");
  6469. if (iter != state.end()) {
  6470. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  6471. }
  6472. }
  6473. {
  6474. auto&& iter = state.find("strategy");
  6475. if (iter != state.end()) {
  6476. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  6477. }
  6478. }
  6479. {
  6480. auto&& iter = state.find("workspace_limit");
  6481. if (iter != state.end()) {
  6482. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  6483. }
  6484. }
  6485. Py_RETURN_NONE;
  6486. }
  6487. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6488. // };
  6489. PyOpDefEnd(DeformableConv)
  6490. int PyOp(DeformableConv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6491. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "scope", NULL};
  6492. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  6493. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &scope))
  6494. return -1;
  6495. if (mode) {
  6496. try {
  6497. // TODO: remove this guard which is used for pybind11 implicit conversion
  6498. py::detail::loader_life_support guard{};
  6499. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().mode =
  6500. py::cast<decltype(DeformableConv::mode)>(py::handle(mode));
  6501. } CATCH_ALL(-1)
  6502. }
  6503. if (pad_h) {
  6504. try {
  6505. // TODO: remove this guard which is used for pybind11 implicit conversion
  6506. py::detail::loader_life_support guard{};
  6507. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().pad_h =
  6508. py::cast<decltype(DeformableConv::pad_h)>(py::handle(pad_h));
  6509. } CATCH_ALL(-1)
  6510. }
  6511. if (pad_w) {
  6512. try {
  6513. // TODO: remove this guard which is used for pybind11 implicit conversion
  6514. py::detail::loader_life_support guard{};
  6515. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().pad_w =
  6516. py::cast<decltype(DeformableConv::pad_w)>(py::handle(pad_w));
  6517. } CATCH_ALL(-1)
  6518. }
  6519. if (stride_h) {
  6520. try {
  6521. // TODO: remove this guard which is used for pybind11 implicit conversion
  6522. py::detail::loader_life_support guard{};
  6523. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().stride_h =
  6524. py::cast<decltype(DeformableConv::stride_h)>(py::handle(stride_h));
  6525. } CATCH_ALL(-1)
  6526. }
  6527. if (stride_w) {
  6528. try {
  6529. // TODO: remove this guard which is used for pybind11 implicit conversion
  6530. py::detail::loader_life_support guard{};
  6531. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().stride_w =
  6532. py::cast<decltype(DeformableConv::stride_w)>(py::handle(stride_w));
  6533. } CATCH_ALL(-1)
  6534. }
  6535. if (dilate_h) {
  6536. try {
  6537. // TODO: remove this guard which is used for pybind11 implicit conversion
  6538. py::detail::loader_life_support guard{};
  6539. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().dilate_h =
  6540. py::cast<decltype(DeformableConv::dilate_h)>(py::handle(dilate_h));
  6541. } CATCH_ALL(-1)
  6542. }
  6543. if (dilate_w) {
  6544. try {
  6545. // TODO: remove this guard which is used for pybind11 implicit conversion
  6546. py::detail::loader_life_support guard{};
  6547. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().dilate_w =
  6548. py::cast<decltype(DeformableConv::dilate_w)>(py::handle(dilate_w));
  6549. } CATCH_ALL(-1)
  6550. }
  6551. if (sparse) {
  6552. try {
  6553. // TODO: remove this guard which is used for pybind11 implicit conversion
  6554. py::detail::loader_life_support guard{};
  6555. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().sparse =
  6556. py::cast<decltype(DeformableConv::sparse)>(py::handle(sparse));
  6557. } CATCH_ALL(-1)
  6558. }
  6559. if (format) {
  6560. try {
  6561. // TODO: remove this guard which is used for pybind11 implicit conversion
  6562. py::detail::loader_life_support guard{};
  6563. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().format =
  6564. py::cast<decltype(DeformableConv::format)>(py::handle(format));
  6565. } CATCH_ALL(-1)
  6566. }
  6567. if (compute_mode) {
  6568. try {
  6569. // TODO: remove this guard which is used for pybind11 implicit conversion
  6570. py::detail::loader_life_support guard{};
  6571. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().compute_mode =
  6572. py::cast<decltype(DeformableConv::compute_mode)>(py::handle(compute_mode));
  6573. } CATCH_ALL(-1)
  6574. }
  6575. if (strategy) {
  6576. try {
  6577. // TODO: remove this guard which is used for pybind11 implicit conversion
  6578. py::detail::loader_life_support guard{};
  6579. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().strategy =
  6580. py::cast<decltype(DeformableConv::strategy)>(py::handle(strategy));
  6581. } CATCH_ALL(-1)
  6582. }
  6583. if (workspace_limit) {
  6584. try {
  6585. // TODO: remove this guard which is used for pybind11 implicit conversion
  6586. py::detail::loader_life_support guard{};
  6587. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().workspace_limit =
  6588. py::cast<decltype(DeformableConv::workspace_limit)>(py::handle(workspace_limit));
  6589. } CATCH_ALL(-1)
  6590. }
  6591. if (scope) {
  6592. try {
  6593. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6594. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6595. } CATCH_ALL(-1)
  6596. }
  6597. return 0;
  6598. }
  6599. PyGetSetDef PyOp(DeformableConv)::py_getsetters[] = {
  6600. {const_cast<char*>("mode"), py_get_generic(DeformableConv, mode), py_set_generic(DeformableConv, mode), const_cast<char*>("mode"), NULL},
  6601. {const_cast<char*>("pad_h"), py_get_generic(DeformableConv, pad_h), py_set_generic(DeformableConv, pad_h), const_cast<char*>("pad_h"), NULL},
  6602. {const_cast<char*>("pad_w"), py_get_generic(DeformableConv, pad_w), py_set_generic(DeformableConv, pad_w), const_cast<char*>("pad_w"), NULL},
  6603. {const_cast<char*>("stride_h"), py_get_generic(DeformableConv, stride_h), py_set_generic(DeformableConv, stride_h), const_cast<char*>("stride_h"), NULL},
  6604. {const_cast<char*>("stride_w"), py_get_generic(DeformableConv, stride_w), py_set_generic(DeformableConv, stride_w), const_cast<char*>("stride_w"), NULL},
  6605. {const_cast<char*>("dilate_h"), py_get_generic(DeformableConv, dilate_h), py_set_generic(DeformableConv, dilate_h), const_cast<char*>("dilate_h"), NULL},
  6606. {const_cast<char*>("dilate_w"), py_get_generic(DeformableConv, dilate_w), py_set_generic(DeformableConv, dilate_w), const_cast<char*>("dilate_w"), NULL},
  6607. {const_cast<char*>("sparse"), py_get_generic(DeformableConv, sparse), py_set_generic(DeformableConv, sparse), const_cast<char*>("sparse"), NULL},
  6608. {const_cast<char*>("format"), py_get_generic(DeformableConv, format), py_set_generic(DeformableConv, format), const_cast<char*>("format"), NULL},
  6609. {const_cast<char*>("compute_mode"), py_get_generic(DeformableConv, compute_mode), py_set_generic(DeformableConv, compute_mode), const_cast<char*>("compute_mode"), NULL},
  6610. {const_cast<char*>("strategy"), py_get_generic(DeformableConv, strategy), py_set_generic(DeformableConv, strategy), const_cast<char*>("strategy"), NULL},
  6611. {const_cast<char*>("workspace_limit"), py_get_generic(DeformableConv, workspace_limit), py_set_generic(DeformableConv, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  6612. {NULL} /* Sentinel */
  6613. };
  6614. PyMethodDef PyOp(DeformableConv)::tp_methods[] = {
  6615. {const_cast<char*>("__getstate__"), PyOp(DeformableConv)::getstate, METH_NOARGS, "DeformableConv getstate"},
  6616. {const_cast<char*>("__setstate__"), PyOp(DeformableConv)::setstate, METH_VARARGS, "DeformableConv setstate"},
  6617. {NULL} /* Sentinel */
  6618. };
  6619. void _init_py_DeformableConv(py::module m) {
  6620. using py_op = PyOp(DeformableConv);
  6621. auto& py_type = PyOpType(DeformableConv);
  6622. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6623. py_type.tp_name = "megengine.core._imperative_rt.ops.DeformableConv";
  6624. py_type.tp_basicsize = sizeof(PyOp(DeformableConv));
  6625. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6626. py_type.tp_doc = "DeformableConv";
  6627. py_type.tp_base = &PyOpType(OpDef);
  6628. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6629. py_type.tp_new = py_new_generic<py_op>;
  6630. py_type.tp_init = py_op::py_init;
  6631. py_type.tp_methods = py_op::tp_methods;
  6632. py_type.tp_getset = py_op::py_getsetters;
  6633. mgb_assert(PyType_Ready(&py_type) >= 0);
  6634. _init_py_DeformableConv_Mode(py_type);
  6635. _init_py_DeformableConv_Sparse(py_type);
  6636. _init_py_DeformableConv_Format(py_type);
  6637. _init_py_DeformableConv_ComputeMode(py_type);
  6638. _init_py_DeformableConv_Strategy(py_type);
  6639. PyType_Modified(&py_type);
  6640. m.add_object("DeformableConv", reinterpret_cast<PyObject*>(&py_type));
  6641. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformableConv::typeinfo(), &py_type).second);
  6642. }
  6643. PyOpDefBegin(DeformablePSROIPooling) // {
  6644. static PyGetSetDef py_getsetters[];
  6645. static PyMethodDef tp_methods[];
  6646. static PyObject* getstate(PyObject* self, PyObject*) {
  6647. auto& opdef = reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst();
  6648. static_cast<void>(opdef);
  6649. std::unordered_map<std::string, py::object> state {
  6650. {"no_trans", serialization<decltype(opdef.no_trans)>::dump(opdef.no_trans)},
  6651. {"spatial_scale", serialization<decltype(opdef.spatial_scale)>::dump(opdef.spatial_scale)},
  6652. {"trans_std", serialization<decltype(opdef.trans_std)>::dump(opdef.trans_std)},
  6653. {"pooled_h", serialization<decltype(opdef.pooled_h)>::dump(opdef.pooled_h)},
  6654. {"pooled_w", serialization<decltype(opdef.pooled_w)>::dump(opdef.pooled_w)},
  6655. {"part_size", serialization<decltype(opdef.part_size)>::dump(opdef.part_size)},
  6656. {"sample_per_part", serialization<decltype(opdef.sample_per_part)>::dump(opdef.sample_per_part)}
  6657. };
  6658. return py::cast(state).release().ptr();
  6659. }
  6660. static PyObject* setstate(PyObject* self, PyObject* args) {
  6661. PyObject* dict = PyTuple_GetItem(args, 0);
  6662. if (!dict) return NULL;
  6663. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6664. auto& opdef = reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst();
  6665. static_cast<void>(opdef);
  6666. {
  6667. auto&& iter = state.find("no_trans");
  6668. if (iter != state.end()) {
  6669. opdef.no_trans = serialization<decltype(opdef.no_trans)>::load(iter->second);
  6670. }
  6671. }
  6672. {
  6673. auto&& iter = state.find("spatial_scale");
  6674. if (iter != state.end()) {
  6675. opdef.spatial_scale = serialization<decltype(opdef.spatial_scale)>::load(iter->second);
  6676. }
  6677. }
  6678. {
  6679. auto&& iter = state.find("trans_std");
  6680. if (iter != state.end()) {
  6681. opdef.trans_std = serialization<decltype(opdef.trans_std)>::load(iter->second);
  6682. }
  6683. }
  6684. {
  6685. auto&& iter = state.find("pooled_h");
  6686. if (iter != state.end()) {
  6687. opdef.pooled_h = serialization<decltype(opdef.pooled_h)>::load(iter->second);
  6688. }
  6689. }
  6690. {
  6691. auto&& iter = state.find("pooled_w");
  6692. if (iter != state.end()) {
  6693. opdef.pooled_w = serialization<decltype(opdef.pooled_w)>::load(iter->second);
  6694. }
  6695. }
  6696. {
  6697. auto&& iter = state.find("part_size");
  6698. if (iter != state.end()) {
  6699. opdef.part_size = serialization<decltype(opdef.part_size)>::load(iter->second);
  6700. }
  6701. }
  6702. {
  6703. auto&& iter = state.find("sample_per_part");
  6704. if (iter != state.end()) {
  6705. opdef.sample_per_part = serialization<decltype(opdef.sample_per_part)>::load(iter->second);
  6706. }
  6707. }
  6708. Py_RETURN_NONE;
  6709. }
  6710. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6711. // };
  6712. PyOpDefEnd(DeformablePSROIPooling)
  6713. int PyOp(DeformablePSROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6714. static const char* kwlist[] = {"no_trans", "spatial_scale", "trans_std", "pooled_h", "pooled_w", "part_size", "sample_per_part", "scope", NULL};
  6715. PyObject *no_trans = NULL, *spatial_scale = NULL, *trans_std = NULL, *pooled_h = NULL, *pooled_w = NULL, *part_size = NULL, *sample_per_part = NULL, *scope = NULL;
  6716. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &no_trans, &spatial_scale, &trans_std, &pooled_h, &pooled_w, &part_size, &sample_per_part, &scope))
  6717. return -1;
  6718. if (no_trans) {
  6719. try {
  6720. // TODO: remove this guard which is used for pybind11 implicit conversion
  6721. py::detail::loader_life_support guard{};
  6722. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().no_trans =
  6723. py::cast<decltype(DeformablePSROIPooling::no_trans)>(py::handle(no_trans));
  6724. } CATCH_ALL(-1)
  6725. }
  6726. if (spatial_scale) {
  6727. try {
  6728. // TODO: remove this guard which is used for pybind11 implicit conversion
  6729. py::detail::loader_life_support guard{};
  6730. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().spatial_scale =
  6731. py::cast<decltype(DeformablePSROIPooling::spatial_scale)>(py::handle(spatial_scale));
  6732. } CATCH_ALL(-1)
  6733. }
  6734. if (trans_std) {
  6735. try {
  6736. // TODO: remove this guard which is used for pybind11 implicit conversion
  6737. py::detail::loader_life_support guard{};
  6738. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().trans_std =
  6739. py::cast<decltype(DeformablePSROIPooling::trans_std)>(py::handle(trans_std));
  6740. } CATCH_ALL(-1)
  6741. }
  6742. if (pooled_h) {
  6743. try {
  6744. // TODO: remove this guard which is used for pybind11 implicit conversion
  6745. py::detail::loader_life_support guard{};
  6746. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().pooled_h =
  6747. py::cast<decltype(DeformablePSROIPooling::pooled_h)>(py::handle(pooled_h));
  6748. } CATCH_ALL(-1)
  6749. }
  6750. if (pooled_w) {
  6751. try {
  6752. // TODO: remove this guard which is used for pybind11 implicit conversion
  6753. py::detail::loader_life_support guard{};
  6754. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().pooled_w =
  6755. py::cast<decltype(DeformablePSROIPooling::pooled_w)>(py::handle(pooled_w));
  6756. } CATCH_ALL(-1)
  6757. }
  6758. if (part_size) {
  6759. try {
  6760. // TODO: remove this guard which is used for pybind11 implicit conversion
  6761. py::detail::loader_life_support guard{};
  6762. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().part_size =
  6763. py::cast<decltype(DeformablePSROIPooling::part_size)>(py::handle(part_size));
  6764. } CATCH_ALL(-1)
  6765. }
  6766. if (sample_per_part) {
  6767. try {
  6768. // TODO: remove this guard which is used for pybind11 implicit conversion
  6769. py::detail::loader_life_support guard{};
  6770. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().sample_per_part =
  6771. py::cast<decltype(DeformablePSROIPooling::sample_per_part)>(py::handle(sample_per_part));
  6772. } CATCH_ALL(-1)
  6773. }
  6774. if (scope) {
  6775. try {
  6776. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6777. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6778. } CATCH_ALL(-1)
  6779. }
  6780. return 0;
  6781. }
  6782. PyGetSetDef PyOp(DeformablePSROIPooling)::py_getsetters[] = {
  6783. {const_cast<char*>("no_trans"), py_get_generic(DeformablePSROIPooling, no_trans), py_set_generic(DeformablePSROIPooling, no_trans), const_cast<char*>("no_trans"), NULL},
  6784. {const_cast<char*>("spatial_scale"), py_get_generic(DeformablePSROIPooling, spatial_scale), py_set_generic(DeformablePSROIPooling, spatial_scale), const_cast<char*>("spatial_scale"), NULL},
  6785. {const_cast<char*>("trans_std"), py_get_generic(DeformablePSROIPooling, trans_std), py_set_generic(DeformablePSROIPooling, trans_std), const_cast<char*>("trans_std"), NULL},
  6786. {const_cast<char*>("pooled_h"), py_get_generic(DeformablePSROIPooling, pooled_h), py_set_generic(DeformablePSROIPooling, pooled_h), const_cast<char*>("pooled_h"), NULL},
  6787. {const_cast<char*>("pooled_w"), py_get_generic(DeformablePSROIPooling, pooled_w), py_set_generic(DeformablePSROIPooling, pooled_w), const_cast<char*>("pooled_w"), NULL},
  6788. {const_cast<char*>("part_size"), py_get_generic(DeformablePSROIPooling, part_size), py_set_generic(DeformablePSROIPooling, part_size), const_cast<char*>("part_size"), NULL},
  6789. {const_cast<char*>("sample_per_part"), py_get_generic(DeformablePSROIPooling, sample_per_part), py_set_generic(DeformablePSROIPooling, sample_per_part), const_cast<char*>("sample_per_part"), NULL},
  6790. {NULL} /* Sentinel */
  6791. };
  6792. PyMethodDef PyOp(DeformablePSROIPooling)::tp_methods[] = {
  6793. {const_cast<char*>("__getstate__"), PyOp(DeformablePSROIPooling)::getstate, METH_NOARGS, "DeformablePSROIPooling getstate"},
  6794. {const_cast<char*>("__setstate__"), PyOp(DeformablePSROIPooling)::setstate, METH_VARARGS, "DeformablePSROIPooling setstate"},
  6795. {NULL} /* Sentinel */
  6796. };
  6797. void _init_py_DeformablePSROIPooling(py::module m) {
  6798. using py_op = PyOp(DeformablePSROIPooling);
  6799. auto& py_type = PyOpType(DeformablePSROIPooling);
  6800. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6801. py_type.tp_name = "megengine.core._imperative_rt.ops.DeformablePSROIPooling";
  6802. py_type.tp_basicsize = sizeof(PyOp(DeformablePSROIPooling));
  6803. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6804. py_type.tp_doc = "DeformablePSROIPooling";
  6805. py_type.tp_base = &PyOpType(OpDef);
  6806. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6807. py_type.tp_new = py_new_generic<py_op>;
  6808. py_type.tp_init = py_op::py_init;
  6809. py_type.tp_methods = py_op::tp_methods;
  6810. py_type.tp_getset = py_op::py_getsetters;
  6811. mgb_assert(PyType_Ready(&py_type) >= 0);
  6812. PyType_Modified(&py_type);
  6813. m.add_object("DeformablePSROIPooling", reinterpret_cast<PyObject*>(&py_type));
  6814. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformablePSROIPooling::typeinfo(), &py_type).second);
  6815. }
  6816. PyOpDefBegin(Diag) // {
  6817. static PyGetSetDef py_getsetters[];
  6818. static PyMethodDef tp_methods[];
  6819. static PyObject* getstate(PyObject* self, PyObject*) {
  6820. auto& opdef = reinterpret_cast<PyOp(Diag)*>(self)->inst();
  6821. static_cast<void>(opdef);
  6822. std::unordered_map<std::string, py::object> state {
  6823. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)}
  6824. };
  6825. return py::cast(state).release().ptr();
  6826. }
  6827. static PyObject* setstate(PyObject* self, PyObject* args) {
  6828. PyObject* dict = PyTuple_GetItem(args, 0);
  6829. if (!dict) return NULL;
  6830. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6831. auto& opdef = reinterpret_cast<PyOp(Diag)*>(self)->inst();
  6832. static_cast<void>(opdef);
  6833. {
  6834. auto&& iter = state.find("k");
  6835. if (iter != state.end()) {
  6836. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  6837. }
  6838. }
  6839. Py_RETURN_NONE;
  6840. }
  6841. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6842. // };
  6843. PyOpDefEnd(Diag)
  6844. int PyOp(Diag)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6845. static const char* kwlist[] = {"k", "scope", NULL};
  6846. PyObject *k = NULL, *scope = NULL;
  6847. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &k, &scope))
  6848. return -1;
  6849. if (k) {
  6850. try {
  6851. // TODO: remove this guard which is used for pybind11 implicit conversion
  6852. py::detail::loader_life_support guard{};
  6853. reinterpret_cast<PyOp(Diag)*>(self)->inst().k =
  6854. py::cast<decltype(Diag::k)>(py::handle(k));
  6855. } CATCH_ALL(-1)
  6856. }
  6857. if (scope) {
  6858. try {
  6859. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6860. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6861. } CATCH_ALL(-1)
  6862. }
  6863. return 0;
  6864. }
  6865. PyGetSetDef PyOp(Diag)::py_getsetters[] = {
  6866. {const_cast<char*>("k"), py_get_generic(Diag, k), py_set_generic(Diag, k), const_cast<char*>("k"), NULL},
  6867. {NULL} /* Sentinel */
  6868. };
  6869. PyMethodDef PyOp(Diag)::tp_methods[] = {
  6870. {const_cast<char*>("__getstate__"), PyOp(Diag)::getstate, METH_NOARGS, "Diag getstate"},
  6871. {const_cast<char*>("__setstate__"), PyOp(Diag)::setstate, METH_VARARGS, "Diag setstate"},
  6872. {NULL} /* Sentinel */
  6873. };
  6874. void _init_py_Diag(py::module m) {
  6875. using py_op = PyOp(Diag);
  6876. auto& py_type = PyOpType(Diag);
  6877. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6878. py_type.tp_name = "megengine.core._imperative_rt.ops.Diag";
  6879. py_type.tp_basicsize = sizeof(PyOp(Diag));
  6880. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6881. py_type.tp_doc = "Diag";
  6882. py_type.tp_base = &PyOpType(OpDef);
  6883. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6884. py_type.tp_new = py_new_generic<py_op>;
  6885. py_type.tp_init = py_op::py_init;
  6886. py_type.tp_methods = py_op::tp_methods;
  6887. py_type.tp_getset = py_op::py_getsetters;
  6888. mgb_assert(PyType_Ready(&py_type) >= 0);
  6889. PyType_Modified(&py_type);
  6890. m.add_object("Diag", reinterpret_cast<PyObject*>(&py_type));
  6891. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Diag::typeinfo(), &py_type).second);
  6892. }
  6893. PyOpDefBegin(Dimshuffle) // {
  6894. static PyGetSetDef py_getsetters[];
  6895. static PyMethodDef tp_methods[];
  6896. static PyObject* getstate(PyObject* self, PyObject*) {
  6897. auto& opdef = reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst();
  6898. static_cast<void>(opdef);
  6899. std::unordered_map<std::string, py::object> state {
  6900. {"pattern", serialization<decltype(opdef.pattern)>::dump(opdef.pattern)}
  6901. };
  6902. return py::cast(state).release().ptr();
  6903. }
  6904. static PyObject* setstate(PyObject* self, PyObject* args) {
  6905. PyObject* dict = PyTuple_GetItem(args, 0);
  6906. if (!dict) return NULL;
  6907. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6908. auto& opdef = reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst();
  6909. static_cast<void>(opdef);
  6910. {
  6911. auto&& iter = state.find("pattern");
  6912. if (iter != state.end()) {
  6913. opdef.pattern = serialization<decltype(opdef.pattern)>::load(iter->second);
  6914. }
  6915. }
  6916. Py_RETURN_NONE;
  6917. }
  6918. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6919. // };
  6920. PyOpDefEnd(Dimshuffle)
  6921. int PyOp(Dimshuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6922. static const char* kwlist[] = {"pattern", "scope", NULL};
  6923. PyObject *pattern = NULL, *scope = NULL;
  6924. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &pattern, &scope))
  6925. return -1;
  6926. if (pattern) {
  6927. try {
  6928. // TODO: remove this guard which is used for pybind11 implicit conversion
  6929. py::detail::loader_life_support guard{};
  6930. reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst().pattern =
  6931. py::cast<decltype(Dimshuffle::pattern)>(py::handle(pattern));
  6932. } CATCH_ALL(-1)
  6933. }
  6934. if (scope) {
  6935. try {
  6936. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6937. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6938. } CATCH_ALL(-1)
  6939. }
  6940. return 0;
  6941. }
  6942. PyGetSetDef PyOp(Dimshuffle)::py_getsetters[] = {
  6943. {const_cast<char*>("pattern"), py_get_generic(Dimshuffle, pattern), py_set_generic(Dimshuffle, pattern), const_cast<char*>("pattern"), NULL},
  6944. {NULL} /* Sentinel */
  6945. };
  6946. PyMethodDef PyOp(Dimshuffle)::tp_methods[] = {
  6947. {const_cast<char*>("__getstate__"), PyOp(Dimshuffle)::getstate, METH_NOARGS, "Dimshuffle getstate"},
  6948. {const_cast<char*>("__setstate__"), PyOp(Dimshuffle)::setstate, METH_VARARGS, "Dimshuffle setstate"},
  6949. {NULL} /* Sentinel */
  6950. };
  6951. void _init_py_Dimshuffle(py::module m) {
  6952. using py_op = PyOp(Dimshuffle);
  6953. auto& py_type = PyOpType(Dimshuffle);
  6954. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6955. py_type.tp_name = "megengine.core._imperative_rt.ops.Dimshuffle";
  6956. py_type.tp_basicsize = sizeof(PyOp(Dimshuffle));
  6957. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6958. py_type.tp_doc = "Dimshuffle";
  6959. py_type.tp_base = &PyOpType(OpDef);
  6960. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6961. py_type.tp_new = py_new_generic<py_op>;
  6962. py_type.tp_init = py_op::py_init;
  6963. py_type.tp_methods = py_op::tp_methods;
  6964. py_type.tp_getset = py_op::py_getsetters;
  6965. mgb_assert(PyType_Ready(&py_type) >= 0);
  6966. PyType_Modified(&py_type);
  6967. m.add_object("Dimshuffle", reinterpret_cast<PyObject*>(&py_type));
  6968. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dimshuffle::typeinfo(), &py_type).second);
  6969. }
  6970. PyOpDefBegin(Dot) // {
  6971. static PyGetSetDef py_getsetters[];
  6972. static PyMethodDef tp_methods[];
  6973. static PyObject* getstate(PyObject* self, PyObject*) {
  6974. auto& opdef = reinterpret_cast<PyOp(Dot)*>(self)->inst();
  6975. static_cast<void>(opdef);
  6976. std::unordered_map<std::string, py::object> state {
  6977. };
  6978. return py::cast(state).release().ptr();
  6979. }
  6980. static PyObject* setstate(PyObject* self, PyObject* args) {
  6981. PyObject* dict = PyTuple_GetItem(args, 0);
  6982. if (!dict) return NULL;
  6983. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6984. auto& opdef = reinterpret_cast<PyOp(Dot)*>(self)->inst();
  6985. static_cast<void>(opdef);
  6986. Py_RETURN_NONE;
  6987. }
  6988. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6989. // };
  6990. PyOpDefEnd(Dot)
  6991. int PyOp(Dot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6992. return 0;
  6993. }
  6994. PyGetSetDef PyOp(Dot)::py_getsetters[] = {
  6995. {NULL} /* Sentinel */
  6996. };
  6997. PyMethodDef PyOp(Dot)::tp_methods[] = {
  6998. {const_cast<char*>("__getstate__"), PyOp(Dot)::getstate, METH_NOARGS, "Dot getstate"},
  6999. {const_cast<char*>("__setstate__"), PyOp(Dot)::setstate, METH_VARARGS, "Dot setstate"},
  7000. {NULL} /* Sentinel */
  7001. };
  7002. void _init_py_Dot(py::module m) {
  7003. using py_op = PyOp(Dot);
  7004. auto& py_type = PyOpType(Dot);
  7005. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7006. py_type.tp_name = "megengine.core._imperative_rt.ops.Dot";
  7007. py_type.tp_basicsize = sizeof(PyOp(Dot));
  7008. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7009. py_type.tp_doc = "Dot";
  7010. py_type.tp_base = &PyOpType(OpDef);
  7011. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7012. py_type.tp_new = py_new_generic<py_op>;
  7013. py_type.tp_init = py_op::py_init;
  7014. py_type.tp_methods = py_op::tp_methods;
  7015. py_type.tp_getset = py_op::py_getsetters;
  7016. mgb_assert(PyType_Ready(&py_type) >= 0);
  7017. PyType_Modified(&py_type);
  7018. m.add_object("Dot", reinterpret_cast<PyObject*>(&py_type));
  7019. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dot::typeinfo(), &py_type).second);
  7020. }
  7021. PyOpDefBegin(Dropout) // {
  7022. static PyGetSetDef py_getsetters[];
  7023. static PyMethodDef tp_methods[];
  7024. static PyObject* getstate(PyObject* self, PyObject*) {
  7025. auto& opdef = reinterpret_cast<PyOp(Dropout)*>(self)->inst();
  7026. static_cast<void>(opdef);
  7027. std::unordered_map<std::string, py::object> state {
  7028. {"drop_prob", serialization<decltype(opdef.drop_prob)>::dump(opdef.drop_prob)},
  7029. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  7030. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  7031. };
  7032. return py::cast(state).release().ptr();
  7033. }
  7034. static PyObject* setstate(PyObject* self, PyObject* args) {
  7035. PyObject* dict = PyTuple_GetItem(args, 0);
  7036. if (!dict) return NULL;
  7037. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7038. auto& opdef = reinterpret_cast<PyOp(Dropout)*>(self)->inst();
  7039. static_cast<void>(opdef);
  7040. {
  7041. auto&& iter = state.find("drop_prob");
  7042. if (iter != state.end()) {
  7043. opdef.drop_prob = serialization<decltype(opdef.drop_prob)>::load(iter->second);
  7044. }
  7045. }
  7046. {
  7047. auto&& iter = state.find("seed");
  7048. if (iter != state.end()) {
  7049. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  7050. }
  7051. }
  7052. {
  7053. auto&& iter = state.find("handle");
  7054. if (iter != state.end()) {
  7055. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  7056. }
  7057. }
  7058. Py_RETURN_NONE;
  7059. }
  7060. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7061. // };
  7062. PyOpDefEnd(Dropout)
  7063. int PyOp(Dropout)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7064. static const char* kwlist[] = {"drop_prob", "seed", "handle", "scope", NULL};
  7065. PyObject *drop_prob = NULL, *seed = NULL, *handle = NULL, *scope = NULL;
  7066. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &drop_prob, &seed, &handle, &scope))
  7067. return -1;
  7068. if (drop_prob) {
  7069. try {
  7070. // TODO: remove this guard which is used for pybind11 implicit conversion
  7071. py::detail::loader_life_support guard{};
  7072. reinterpret_cast<PyOp(Dropout)*>(self)->inst().drop_prob =
  7073. py::cast<decltype(Dropout::drop_prob)>(py::handle(drop_prob));
  7074. } CATCH_ALL(-1)
  7075. }
  7076. if (seed) {
  7077. try {
  7078. // TODO: remove this guard which is used for pybind11 implicit conversion
  7079. py::detail::loader_life_support guard{};
  7080. reinterpret_cast<PyOp(Dropout)*>(self)->inst().seed =
  7081. py::cast<decltype(Dropout::seed)>(py::handle(seed));
  7082. } CATCH_ALL(-1)
  7083. }
  7084. if (handle) {
  7085. try {
  7086. // TODO: remove this guard which is used for pybind11 implicit conversion
  7087. py::detail::loader_life_support guard{};
  7088. reinterpret_cast<PyOp(Dropout)*>(self)->inst().handle =
  7089. py::cast<decltype(Dropout::handle)>(py::handle(handle));
  7090. } CATCH_ALL(-1)
  7091. }
  7092. if (scope) {
  7093. try {
  7094. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7095. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7096. } CATCH_ALL(-1)
  7097. }
  7098. return 0;
  7099. }
  7100. PyGetSetDef PyOp(Dropout)::py_getsetters[] = {
  7101. {const_cast<char*>("drop_prob"), py_get_generic(Dropout, drop_prob), py_set_generic(Dropout, drop_prob), const_cast<char*>("drop_prob"), NULL},
  7102. {const_cast<char*>("seed"), py_get_generic(Dropout, seed), py_set_generic(Dropout, seed), const_cast<char*>("seed"), NULL},
  7103. {const_cast<char*>("handle"), py_get_generic(Dropout, handle), py_set_generic(Dropout, handle), const_cast<char*>("handle"), NULL},
  7104. {NULL} /* Sentinel */
  7105. };
  7106. PyMethodDef PyOp(Dropout)::tp_methods[] = {
  7107. {const_cast<char*>("__getstate__"), PyOp(Dropout)::getstate, METH_NOARGS, "Dropout getstate"},
  7108. {const_cast<char*>("__setstate__"), PyOp(Dropout)::setstate, METH_VARARGS, "Dropout setstate"},
  7109. {NULL} /* Sentinel */
  7110. };
  7111. void _init_py_Dropout(py::module m) {
  7112. using py_op = PyOp(Dropout);
  7113. auto& py_type = PyOpType(Dropout);
  7114. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7115. py_type.tp_name = "megengine.core._imperative_rt.ops.Dropout";
  7116. py_type.tp_basicsize = sizeof(PyOp(Dropout));
  7117. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7118. py_type.tp_doc = "Dropout";
  7119. py_type.tp_base = &PyOpType(OpDef);
  7120. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7121. py_type.tp_new = py_new_generic<py_op>;
  7122. py_type.tp_init = py_op::py_init;
  7123. py_type.tp_methods = py_op::tp_methods;
  7124. py_type.tp_getset = py_op::py_getsetters;
  7125. mgb_assert(PyType_Ready(&py_type) >= 0);
  7126. PyType_Modified(&py_type);
  7127. m.add_object("Dropout", reinterpret_cast<PyObject*>(&py_type));
  7128. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dropout::typeinfo(), &py_type).second);
  7129. }
  7130. template<> struct EnumTrait<Elemwise::Mode> {
  7131. static constexpr const char *name = "Elemwise.Mode";
  7132. static constexpr std::underlying_type_t<Elemwise::Mode> max = 87 - 1;
  7133. };
  7134. template<> PyTypeObject* EnumWrapper<Elemwise::Mode>::type = nullptr;
  7135. template<> const char*
  7136. EnumWrapper<Elemwise::Mode>::members[] = {"RELU", "ABS", "ACOS", "ASIN", "CEIL", "COS", "EXP", "EXPM1", "FLOOR", "LOG", "LOG1P", "NEGATE", "SIGMOID", "SIN", "TANH", "ABS_GRAD", "ADD", "FLOOR_DIV", "MAX", "MIN", "MOD", "MUL", "POW", "SIGMOID_GRAD", "SUB", "SWITCH_GT0", "TANH_GRAD", "TRUE_DIV", "LOG_SUM_EXP", "LT", "LEQ", "EQ", "SHL", "SHR", "COND_LEQ_MOV", "FUSE_MUL_ADD3", "FUSE_MUL_ADD4", "FUSE_ADD_RELU", "FUSE_ADD_SIGMOID", "FUSE_ADD_TANH", "FAST_TANH", "FAST_TANH_GRAD", "ROUND", "RMULH", "ATAN2", "ERF", "ERFINV", "ERFC", "ERFCINV", "H_SWISH", "H_SWISH_GRAD", "FUSE_ADD_H_SWISH", "NOT", "AND", "OR", "XOR", "SILU", "SILU_GRAD", "GELU", "GELU_GRAD", "COND_LT_MOV", "SINH", "COSH", "ASINH", "ACOSH", "ATANH", "TAN", "ASINH_GRAD", "ACOSH_GRAD", "ATANH_GRAD", "PRELU", "CLIP", "PRELU_GRAD", "SOFTPLUS", "SOFTPLUS_GRAD", "RELU6", "RELU6_GRAD", "HSIGMOID", "HSIGMOID_GRAD", "LOGSIGMOID", "SQRT", "SQUARE", "SIGN", "SAFE_DIV", "NEQ", "ISNAN", "ISINF"};
  7137. template<> std::unordered_map<std::string, Elemwise::Mode>
  7138. EnumWrapper<Elemwise::Mode>::mem2value = {{normalize_enum("RELU"), Elemwise::Mode::RELU}, {normalize_enum("ABS"), Elemwise::Mode::ABS}, {normalize_enum("ACOS"), Elemwise::Mode::ACOS}, {normalize_enum("ASIN"), Elemwise::Mode::ASIN}, {normalize_enum("CEIL"), Elemwise::Mode::CEIL}, {normalize_enum("COS"), Elemwise::Mode::COS}, {normalize_enum("EXP"), Elemwise::Mode::EXP}, {normalize_enum("EXPM1"), Elemwise::Mode::EXPM1}, {normalize_enum("FLOOR"), Elemwise::Mode::FLOOR}, {normalize_enum("LOG"), Elemwise::Mode::LOG}, {normalize_enum("LOG1P"), Elemwise::Mode::LOG1P}, {normalize_enum("NEGATE"), Elemwise::Mode::NEGATE}, {normalize_enum("SIGMOID"), Elemwise::Mode::SIGMOID}, {normalize_enum("SIN"), Elemwise::Mode::SIN}, {normalize_enum("TANH"), Elemwise::Mode::TANH}, {normalize_enum("ABS_GRAD"), Elemwise::Mode::ABS_GRAD}, {normalize_enum("ADD"), Elemwise::Mode::ADD}, {normalize_enum("FLOOR_DIV"), Elemwise::Mode::FLOOR_DIV}, {normalize_enum("MAX"), Elemwise::Mode::MAX}, {normalize_enum("MIN"), Elemwise::Mode::MIN}, {normalize_enum("MOD"), Elemwise::Mode::MOD}, {normalize_enum("MUL"), Elemwise::Mode::MUL}, {normalize_enum("POW"), Elemwise::Mode::POW}, {normalize_enum("SIGMOID_GRAD"), Elemwise::Mode::SIGMOID_GRAD}, {normalize_enum("SUB"), Elemwise::Mode::SUB}, {normalize_enum("SWITCH_GT0"), Elemwise::Mode::SWITCH_GT0}, {normalize_enum("TANH_GRAD"), Elemwise::Mode::TANH_GRAD}, {normalize_enum("TRUE_DIV"), Elemwise::Mode::TRUE_DIV}, {normalize_enum("LOG_SUM_EXP"), Elemwise::Mode::LOG_SUM_EXP}, {normalize_enum("LT"), Elemwise::Mode::LT}, {normalize_enum("LEQ"), Elemwise::Mode::LEQ}, {normalize_enum("EQ"), Elemwise::Mode::EQ}, {normalize_enum("SHL"), Elemwise::Mode::SHL}, {normalize_enum("SHR"), Elemwise::Mode::SHR}, {normalize_enum("COND_LEQ_MOV"), Elemwise::Mode::COND_LEQ_MOV}, {normalize_enum("FUSE_MUL_ADD3"), Elemwise::Mode::FUSE_MUL_ADD3}, {normalize_enum("FUSE_MUL_ADD4"), Elemwise::Mode::FUSE_MUL_ADD4}, {normalize_enum("FUSE_ADD_RELU"), Elemwise::Mode::FUSE_ADD_RELU}, {normalize_enum("FUSE_ADD_SIGMOID"), Elemwise::Mode::FUSE_ADD_SIGMOID}, {normalize_enum("FUSE_ADD_TANH"), Elemwise::Mode::FUSE_ADD_TANH}, {normalize_enum("FAST_TANH"), Elemwise::Mode::FAST_TANH}, {normalize_enum("FAST_TANH_GRAD"), Elemwise::Mode::FAST_TANH_GRAD}, {normalize_enum("ROUND"), Elemwise::Mode::ROUND}, {normalize_enum("RMULH"), Elemwise::Mode::RMULH}, {normalize_enum("ATAN2"), Elemwise::Mode::ATAN2}, {normalize_enum("ERF"), Elemwise::Mode::ERF}, {normalize_enum("ERFINV"), Elemwise::Mode::ERFINV}, {normalize_enum("ERFC"), Elemwise::Mode::ERFC}, {normalize_enum("ERFCINV"), Elemwise::Mode::ERFCINV}, {normalize_enum("H_SWISH"), Elemwise::Mode::H_SWISH}, {normalize_enum("H_SWISH_GRAD"), Elemwise::Mode::H_SWISH_GRAD}, {normalize_enum("FUSE_ADD_H_SWISH"), Elemwise::Mode::FUSE_ADD_H_SWISH}, {normalize_enum("NOT"), Elemwise::Mode::NOT}, {normalize_enum("AND"), Elemwise::Mode::AND}, {normalize_enum("OR"), Elemwise::Mode::OR}, {normalize_enum("XOR"), Elemwise::Mode::XOR}, {normalize_enum("SILU"), Elemwise::Mode::SILU}, {normalize_enum("SILU_GRAD"), Elemwise::Mode::SILU_GRAD}, {normalize_enum("GELU"), Elemwise::Mode::GELU}, {normalize_enum("GELU_GRAD"), Elemwise::Mode::GELU_GRAD}, {normalize_enum("COND_LT_MOV"), Elemwise::Mode::COND_LT_MOV}, {normalize_enum("SINH"), Elemwise::Mode::SINH}, {normalize_enum("COSH"), Elemwise::Mode::COSH}, {normalize_enum("ASINH"), Elemwise::Mode::ASINH}, {normalize_enum("ACOSH"), Elemwise::Mode::ACOSH}, {normalize_enum("ATANH"), Elemwise::Mode::ATANH}, {normalize_enum("TAN"), Elemwise::Mode::TAN}, {normalize_enum("ASINH_GRAD"), Elemwise::Mode::ASINH_GRAD}, {normalize_enum("ACOSH_GRAD"), Elemwise::Mode::ACOSH_GRAD}, {normalize_enum("ATANH_GRAD"), Elemwise::Mode::ATANH_GRAD}, {normalize_enum("PRELU"), Elemwise::Mode::PRELU}, {normalize_enum("CLIP"), Elemwise::Mode::CLIP}, {normalize_enum("PRELU_GRAD"), Elemwise::Mode::PRELU_GRAD}, {normalize_enum("SOFTPLUS"), Elemwise::Mode::SOFTPLUS}, {normalize_enum("SOFTPLUS_GRAD"), Elemwise::Mode::SOFTPLUS_GRAD}, {normalize_enum("RELU6"), Elemwise::Mode::RELU6}, {normalize_enum("RELU6_GRAD"), Elemwise::Mode::RELU6_GRAD}, {normalize_enum("HSIGMOID"), Elemwise::Mode::HSIGMOID}, {normalize_enum("HSIGMOID_GRAD"), Elemwise::Mode::HSIGMOID_GRAD}, {normalize_enum("LOGSIGMOID"), Elemwise::Mode::LOGSIGMOID}, {normalize_enum("SQRT"), Elemwise::Mode::SQRT}, {normalize_enum("SQUARE"), Elemwise::Mode::SQUARE}, {normalize_enum("SIGN"), Elemwise::Mode::SIGN}, {normalize_enum("SAFE_DIV"), Elemwise::Mode::SAFE_DIV}, {normalize_enum("NEQ"), Elemwise::Mode::NEQ}, {normalize_enum("ISNAN"), Elemwise::Mode::ISNAN}, {normalize_enum("ISINF"), Elemwise::Mode::ISINF}};
  7139. template<> PyObject* EnumWrapper<Elemwise::Mode>::pyobj_insts[87] = {nullptr};
  7140. void _init_py_Elemwise_Mode(PyTypeObject& py_type) {
  7141. auto& e_type = EnumWrapper<Elemwise::Mode>::type;
  7142. static PyMethodDef tp_methods[] = {
  7143. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Elemwise::Mode>::py_dump, METH_NOARGS, NULL},
  7144. {NULL} /* Sentinel */
  7145. };
  7146. static PyType_Slot slots[] = {
  7147. {Py_tp_repr, (void*)EnumWrapper<Elemwise::Mode>::py_repr},
  7148. {Py_tp_richcompare, (void*)EnumWrapper<Elemwise::Mode>::tp_richcompare},
  7149. {Py_tp_methods, tp_methods},
  7150. {0, NULL}
  7151. };
  7152. static PyType_Spec spec = {
  7153. // name
  7154. "megengine.core._imperative_rt.ops.Elemwise.Mode",
  7155. // basicsize
  7156. sizeof(EnumWrapper<Elemwise::Mode>),
  7157. // itemsize
  7158. 0,
  7159. // flags
  7160. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  7161. // slots
  7162. slots
  7163. };
  7164. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  7165. mgb_assert(
  7166. e_type->tp_setattro(
  7167. reinterpret_cast<PyObject*>(e_type),
  7168. py::cast("__name__").release().ptr(),
  7169. py::cast("Mode").release().ptr()) >= 0);
  7170. mgb_assert(
  7171. e_type->tp_setattro(
  7172. reinterpret_cast<PyObject*>(e_type),
  7173. py::cast("__module__").release().ptr(),
  7174. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  7175. mgb_assert(
  7176. e_type->tp_setattro(
  7177. reinterpret_cast<PyObject*>(e_type),
  7178. py::cast("__qualname__").release().ptr(),
  7179. py::cast("Elemwise.Mode").release().ptr()) >= 0);
  7180. {
  7181. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7182. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RELU;
  7183. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  7184. EnumWrapper<Elemwise::Mode>::pyobj_insts[0] = inst;
  7185. }{
  7186. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7187. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ABS;
  7188. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS", inst) >= 0);
  7189. EnumWrapper<Elemwise::Mode>::pyobj_insts[1] = inst;
  7190. }{
  7191. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7192. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ACOS;
  7193. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ACOS", inst) >= 0);
  7194. EnumWrapper<Elemwise::Mode>::pyobj_insts[2] = inst;
  7195. }{
  7196. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7197. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ASIN;
  7198. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASIN", inst) >= 0);
  7199. EnumWrapper<Elemwise::Mode>::pyobj_insts[3] = inst;
  7200. }{
  7201. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7202. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::CEIL;
  7203. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CEIL", inst) >= 0);
  7204. EnumWrapper<Elemwise::Mode>::pyobj_insts[4] = inst;
  7205. }{
  7206. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7207. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COS;
  7208. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COS", inst) >= 0);
  7209. EnumWrapper<Elemwise::Mode>::pyobj_insts[5] = inst;
  7210. }{
  7211. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7212. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EXP;
  7213. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXP", inst) >= 0);
  7214. EnumWrapper<Elemwise::Mode>::pyobj_insts[6] = inst;
  7215. }{
  7216. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7217. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EXPM1;
  7218. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXPM1", inst) >= 0);
  7219. EnumWrapper<Elemwise::Mode>::pyobj_insts[7] = inst;
  7220. }{
  7221. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7222. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FLOOR;
  7223. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR", inst) >= 0);
  7224. EnumWrapper<Elemwise::Mode>::pyobj_insts[8] = inst;
  7225. }{
  7226. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7227. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG;
  7228. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG", inst) >= 0);
  7229. EnumWrapper<Elemwise::Mode>::pyobj_insts[9] = inst;
  7230. }{
  7231. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7232. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG1P;
  7233. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG1P", inst) >= 0);
  7234. EnumWrapper<Elemwise::Mode>::pyobj_insts[10] = inst;
  7235. }{
  7236. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7237. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NEGATE;
  7238. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEGATE", inst) >= 0);
  7239. EnumWrapper<Elemwise::Mode>::pyobj_insts[11] = inst;
  7240. }{
  7241. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7242. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIGMOID;
  7243. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID", inst) >= 0);
  7244. EnumWrapper<Elemwise::Mode>::pyobj_insts[12] = inst;
  7245. }{
  7246. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7247. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIN;
  7248. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIN", inst) >= 0);
  7249. EnumWrapper<Elemwise::Mode>::pyobj_insts[13] = inst;
  7250. }{
  7251. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7252. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TANH;
  7253. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0);
  7254. EnumWrapper<Elemwise::Mode>::pyobj_insts[14] = inst;
  7255. }{
  7256. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7257. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ABS_GRAD;
  7258. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS_GRAD", inst) >= 0);
  7259. EnumWrapper<Elemwise::Mode>::pyobj_insts[15] = inst;
  7260. }{
  7261. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7262. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ADD;
  7263. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ADD", inst) >= 0);
  7264. EnumWrapper<Elemwise::Mode>::pyobj_insts[16] = inst;
  7265. }{
  7266. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7267. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FLOOR_DIV;
  7268. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR_DIV", inst) >= 0);
  7269. EnumWrapper<Elemwise::Mode>::pyobj_insts[17] = inst;
  7270. }{
  7271. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7272. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MAX;
  7273. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  7274. EnumWrapper<Elemwise::Mode>::pyobj_insts[18] = inst;
  7275. }{
  7276. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7277. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MIN;
  7278. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0);
  7279. EnumWrapper<Elemwise::Mode>::pyobj_insts[19] = inst;
  7280. }{
  7281. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7282. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MOD;
  7283. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MOD", inst) >= 0);
  7284. EnumWrapper<Elemwise::Mode>::pyobj_insts[20] = inst;
  7285. }{
  7286. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7287. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MUL;
  7288. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL", inst) >= 0);
  7289. EnumWrapper<Elemwise::Mode>::pyobj_insts[21] = inst;
  7290. }{
  7291. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7292. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::POW;
  7293. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "POW", inst) >= 0);
  7294. EnumWrapper<Elemwise::Mode>::pyobj_insts[22] = inst;
  7295. }{
  7296. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7297. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIGMOID_GRAD;
  7298. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID_GRAD", inst) >= 0);
  7299. EnumWrapper<Elemwise::Mode>::pyobj_insts[23] = inst;
  7300. }{
  7301. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7302. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SUB;
  7303. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUB", inst) >= 0);
  7304. EnumWrapper<Elemwise::Mode>::pyobj_insts[24] = inst;
  7305. }{
  7306. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7307. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SWITCH_GT0;
  7308. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SWITCH_GT0", inst) >= 0);
  7309. EnumWrapper<Elemwise::Mode>::pyobj_insts[25] = inst;
  7310. }{
  7311. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7312. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TANH_GRAD;
  7313. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH_GRAD", inst) >= 0);
  7314. EnumWrapper<Elemwise::Mode>::pyobj_insts[26] = inst;
  7315. }{
  7316. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7317. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TRUE_DIV;
  7318. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRUE_DIV", inst) >= 0);
  7319. EnumWrapper<Elemwise::Mode>::pyobj_insts[27] = inst;
  7320. }{
  7321. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7322. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG_SUM_EXP;
  7323. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG_SUM_EXP", inst) >= 0);
  7324. EnumWrapper<Elemwise::Mode>::pyobj_insts[28] = inst;
  7325. }{
  7326. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7327. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LT;
  7328. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LT", inst) >= 0);
  7329. EnumWrapper<Elemwise::Mode>::pyobj_insts[29] = inst;
  7330. }{
  7331. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7332. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LEQ;
  7333. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LEQ", inst) >= 0);
  7334. EnumWrapper<Elemwise::Mode>::pyobj_insts[30] = inst;
  7335. }{
  7336. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7337. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EQ;
  7338. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EQ", inst) >= 0);
  7339. EnumWrapper<Elemwise::Mode>::pyobj_insts[31] = inst;
  7340. }{
  7341. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7342. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SHL;
  7343. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHL", inst) >= 0);
  7344. EnumWrapper<Elemwise::Mode>::pyobj_insts[32] = inst;
  7345. }{
  7346. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7347. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SHR;
  7348. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHR", inst) >= 0);
  7349. EnumWrapper<Elemwise::Mode>::pyobj_insts[33] = inst;
  7350. }{
  7351. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7352. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COND_LEQ_MOV;
  7353. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LEQ_MOV", inst) >= 0);
  7354. EnumWrapper<Elemwise::Mode>::pyobj_insts[34] = inst;
  7355. }{
  7356. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7357. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD3;
  7358. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3", inst) >= 0);
  7359. EnumWrapper<Elemwise::Mode>::pyobj_insts[35] = inst;
  7360. }{
  7361. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7362. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD4;
  7363. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD4", inst) >= 0);
  7364. EnumWrapper<Elemwise::Mode>::pyobj_insts[36] = inst;
  7365. }{
  7366. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7367. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_RELU;
  7368. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RELU", inst) >= 0);
  7369. EnumWrapper<Elemwise::Mode>::pyobj_insts[37] = inst;
  7370. }{
  7371. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7372. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_SIGMOID;
  7373. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_SIGMOID", inst) >= 0);
  7374. EnumWrapper<Elemwise::Mode>::pyobj_insts[38] = inst;
  7375. }{
  7376. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7377. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_TANH;
  7378. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_TANH", inst) >= 0);
  7379. EnumWrapper<Elemwise::Mode>::pyobj_insts[39] = inst;
  7380. }{
  7381. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7382. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FAST_TANH;
  7383. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH", inst) >= 0);
  7384. EnumWrapper<Elemwise::Mode>::pyobj_insts[40] = inst;
  7385. }{
  7386. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7387. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FAST_TANH_GRAD;
  7388. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH_GRAD", inst) >= 0);
  7389. EnumWrapper<Elemwise::Mode>::pyobj_insts[41] = inst;
  7390. }{
  7391. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7392. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ROUND;
  7393. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND", inst) >= 0);
  7394. EnumWrapper<Elemwise::Mode>::pyobj_insts[42] = inst;
  7395. }{
  7396. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7397. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RMULH;
  7398. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RMULH", inst) >= 0);
  7399. EnumWrapper<Elemwise::Mode>::pyobj_insts[43] = inst;
  7400. }{
  7401. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7402. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ATAN2;
  7403. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ATAN2", inst) >= 0);
  7404. EnumWrapper<Elemwise::Mode>::pyobj_insts[44] = inst;
  7405. }{
  7406. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7407. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERF;
  7408. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERF", inst) >= 0);
  7409. EnumWrapper<Elemwise::Mode>::pyobj_insts[45] = inst;
  7410. }{
  7411. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7412. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFINV;
  7413. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFINV", inst) >= 0);
  7414. EnumWrapper<Elemwise::Mode>::pyobj_insts[46] = inst;
  7415. }{
  7416. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7417. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFC;
  7418. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFC", inst) >= 0);
  7419. EnumWrapper<Elemwise::Mode>::pyobj_insts[47] = inst;
  7420. }{
  7421. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7422. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFCINV;
  7423. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFCINV", inst) >= 0);
  7424. EnumWrapper<Elemwise::Mode>::pyobj_insts[48] = inst;
  7425. }{
  7426. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7427. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::H_SWISH;
  7428. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH", inst) >= 0);
  7429. EnumWrapper<Elemwise::Mode>::pyobj_insts[49] = inst;
  7430. }{
  7431. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7432. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::H_SWISH_GRAD;
  7433. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH_GRAD", inst) >= 0);
  7434. EnumWrapper<Elemwise::Mode>::pyobj_insts[50] = inst;
  7435. }{
  7436. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7437. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_H_SWISH;
  7438. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_H_SWISH", inst) >= 0);
  7439. EnumWrapper<Elemwise::Mode>::pyobj_insts[51] = inst;
  7440. }{
  7441. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7442. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NOT;
  7443. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NOT", inst) >= 0);
  7444. EnumWrapper<Elemwise::Mode>::pyobj_insts[52] = inst;
  7445. }{
  7446. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7447. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::AND;
  7448. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AND", inst) >= 0);
  7449. EnumWrapper<Elemwise::Mode>::pyobj_insts[53] = inst;
  7450. }{
  7451. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7452. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::OR;
  7453. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "OR", inst) >= 0);
  7454. EnumWrapper<Elemwise::Mode>::pyobj_insts[54] = inst;
  7455. }{
  7456. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7457. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::XOR;
  7458. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "XOR", inst) >= 0);
  7459. EnumWrapper<Elemwise::Mode>::pyobj_insts[55] = inst;
  7460. }{
  7461. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7462. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SILU;
  7463. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU", inst) >= 0);
  7464. EnumWrapper<Elemwise::Mode>::pyobj_insts[56] = inst;
  7465. }{
  7466. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7467. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SILU_GRAD;
  7468. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU_GRAD", inst) >= 0);
  7469. EnumWrapper<Elemwise::Mode>::pyobj_insts[57] = inst;
  7470. }{
  7471. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7472. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::GELU;
  7473. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU", inst) >= 0);
  7474. EnumWrapper<Elemwise::Mode>::pyobj_insts[58] = inst;
  7475. }{
  7476. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7477. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::GELU_GRAD;
  7478. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU_GRAD", inst) >= 0);
  7479. EnumWrapper<Elemwise::Mode>::pyobj_insts[59] = inst;
  7480. }{
  7481. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7482. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COND_LT_MOV;
  7483. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LT_MOV", inst) >= 0);
  7484. EnumWrapper<Elemwise::Mode>::pyobj_insts[60] = inst;
  7485. }{
  7486. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7487. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SINH;
  7488. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SINH", inst) >= 0);
  7489. EnumWrapper<Elemwise::Mode>::pyobj_insts[61] = inst;
  7490. }{
  7491. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7492. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COSH;
  7493. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COSH", inst) >= 0);
  7494. EnumWrapper<Elemwise::Mode>::pyobj_insts[62] = inst;
  7495. }{
  7496. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7497. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ASINH;
  7498. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASINH", inst) >= 0);
  7499. EnumWrapper<Elemwise::Mode>::pyobj_insts[63] = inst;
  7500. }{
  7501. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7502. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ACOSH;
  7503. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ACOSH", inst) >= 0);
  7504. EnumWrapper<Elemwise::Mode>::pyobj_insts[64] = inst;
  7505. }{
  7506. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7507. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ATANH;
  7508. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ATANH", inst) >= 0);
  7509. EnumWrapper<Elemwise::Mode>::pyobj_insts[65] = inst;
  7510. }{
  7511. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7512. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TAN;
  7513. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TAN", inst) >= 0);
  7514. EnumWrapper<Elemwise::Mode>::pyobj_insts[66] = inst;
  7515. }{
  7516. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7517. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ASINH_GRAD;
  7518. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASINH_GRAD", inst) >= 0);
  7519. EnumWrapper<Elemwise::Mode>::pyobj_insts[67] = inst;
  7520. }{
  7521. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7522. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ACOSH_GRAD;
  7523. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ACOSH_GRAD", inst) >= 0);
  7524. EnumWrapper<Elemwise::Mode>::pyobj_insts[68] = inst;
  7525. }{
  7526. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7527. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ATANH_GRAD;
  7528. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ATANH_GRAD", inst) >= 0);
  7529. EnumWrapper<Elemwise::Mode>::pyobj_insts[69] = inst;
  7530. }{
  7531. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7532. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::PRELU;
  7533. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PRELU", inst) >= 0);
  7534. EnumWrapper<Elemwise::Mode>::pyobj_insts[70] = inst;
  7535. }{
  7536. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7537. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::CLIP;
  7538. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CLIP", inst) >= 0);
  7539. EnumWrapper<Elemwise::Mode>::pyobj_insts[71] = inst;
  7540. }{
  7541. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7542. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::PRELU_GRAD;
  7543. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PRELU_GRAD", inst) >= 0);
  7544. EnumWrapper<Elemwise::Mode>::pyobj_insts[72] = inst;
  7545. }{
  7546. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7547. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SOFTPLUS;
  7548. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SOFTPLUS", inst) >= 0);
  7549. EnumWrapper<Elemwise::Mode>::pyobj_insts[73] = inst;
  7550. }{
  7551. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7552. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SOFTPLUS_GRAD;
  7553. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SOFTPLUS_GRAD", inst) >= 0);
  7554. EnumWrapper<Elemwise::Mode>::pyobj_insts[74] = inst;
  7555. }{
  7556. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7557. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RELU6;
  7558. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU6", inst) >= 0);
  7559. EnumWrapper<Elemwise::Mode>::pyobj_insts[75] = inst;
  7560. }{
  7561. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7562. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RELU6_GRAD;
  7563. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU6_GRAD", inst) >= 0);
  7564. EnumWrapper<Elemwise::Mode>::pyobj_insts[76] = inst;
  7565. }{
  7566. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7567. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::HSIGMOID;
  7568. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "HSIGMOID", inst) >= 0);
  7569. EnumWrapper<Elemwise::Mode>::pyobj_insts[77] = inst;
  7570. }{
  7571. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7572. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::HSIGMOID_GRAD;
  7573. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "HSIGMOID_GRAD", inst) >= 0);
  7574. EnumWrapper<Elemwise::Mode>::pyobj_insts[78] = inst;
  7575. }{
  7576. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7577. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOGSIGMOID;
  7578. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOGSIGMOID", inst) >= 0);
  7579. EnumWrapper<Elemwise::Mode>::pyobj_insts[79] = inst;
  7580. }{
  7581. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7582. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SQRT;
  7583. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SQRT", inst) >= 0);
  7584. EnumWrapper<Elemwise::Mode>::pyobj_insts[80] = inst;
  7585. }{
  7586. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7587. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SQUARE;
  7588. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SQUARE", inst) >= 0);
  7589. EnumWrapper<Elemwise::Mode>::pyobj_insts[81] = inst;
  7590. }{
  7591. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7592. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIGN;
  7593. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGN", inst) >= 0);
  7594. EnumWrapper<Elemwise::Mode>::pyobj_insts[82] = inst;
  7595. }{
  7596. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7597. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SAFE_DIV;
  7598. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SAFE_DIV", inst) >= 0);
  7599. EnumWrapper<Elemwise::Mode>::pyobj_insts[83] = inst;
  7600. }{
  7601. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7602. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NEQ;
  7603. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEQ", inst) >= 0);
  7604. EnumWrapper<Elemwise::Mode>::pyobj_insts[84] = inst;
  7605. }{
  7606. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7607. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ISNAN;
  7608. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISNAN", inst) >= 0);
  7609. EnumWrapper<Elemwise::Mode>::pyobj_insts[85] = inst;
  7610. }{
  7611. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7612. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ISINF;
  7613. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISINF", inst) >= 0);
  7614. EnumWrapper<Elemwise::Mode>::pyobj_insts[86] = inst;
  7615. }
  7616. Py_INCREF(e_type);
  7617. mgb_assert(PyDict_SetItemString(
  7618. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  7619. }
  7620. PyOpDefBegin(Elemwise) // {
  7621. static PyGetSetDef py_getsetters[];
  7622. static PyMethodDef tp_methods[];
  7623. static PyObject* getstate(PyObject* self, PyObject*) {
  7624. auto& opdef = reinterpret_cast<PyOp(Elemwise)*>(self)->inst();
  7625. static_cast<void>(opdef);
  7626. std::unordered_map<std::string, py::object> state {
  7627. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  7628. };
  7629. return py::cast(state).release().ptr();
  7630. }
  7631. static PyObject* setstate(PyObject* self, PyObject* args) {
  7632. PyObject* dict = PyTuple_GetItem(args, 0);
  7633. if (!dict) return NULL;
  7634. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7635. auto& opdef = reinterpret_cast<PyOp(Elemwise)*>(self)->inst();
  7636. static_cast<void>(opdef);
  7637. {
  7638. auto&& iter = state.find("mode");
  7639. if (iter != state.end()) {
  7640. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  7641. }
  7642. }
  7643. Py_RETURN_NONE;
  7644. }
  7645. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7646. // };
  7647. PyOpDefEnd(Elemwise)
  7648. int PyOp(Elemwise)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7649. static const char* kwlist[] = {"mode", "scope", NULL};
  7650. PyObject *mode = NULL, *scope = NULL;
  7651. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  7652. return -1;
  7653. if (mode) {
  7654. try {
  7655. // TODO: remove this guard which is used for pybind11 implicit conversion
  7656. py::detail::loader_life_support guard{};
  7657. reinterpret_cast<PyOp(Elemwise)*>(self)->inst().mode =
  7658. py::cast<decltype(Elemwise::mode)>(py::handle(mode));
  7659. } CATCH_ALL(-1)
  7660. }
  7661. if (scope) {
  7662. try {
  7663. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7664. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7665. } CATCH_ALL(-1)
  7666. }
  7667. return 0;
  7668. }
  7669. PyGetSetDef PyOp(Elemwise)::py_getsetters[] = {
  7670. {const_cast<char*>("mode"), py_get_generic(Elemwise, mode), py_set_generic(Elemwise, mode), const_cast<char*>("mode"), NULL},
  7671. {NULL} /* Sentinel */
  7672. };
  7673. PyMethodDef PyOp(Elemwise)::tp_methods[] = {
  7674. {const_cast<char*>("__getstate__"), PyOp(Elemwise)::getstate, METH_NOARGS, "Elemwise getstate"},
  7675. {const_cast<char*>("__setstate__"), PyOp(Elemwise)::setstate, METH_VARARGS, "Elemwise setstate"},
  7676. {NULL} /* Sentinel */
  7677. };
  7678. void _init_py_Elemwise(py::module m) {
  7679. using py_op = PyOp(Elemwise);
  7680. auto& py_type = PyOpType(Elemwise);
  7681. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7682. py_type.tp_name = "megengine.core._imperative_rt.ops.Elemwise";
  7683. py_type.tp_basicsize = sizeof(PyOp(Elemwise));
  7684. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7685. py_type.tp_doc = "Elemwise";
  7686. py_type.tp_base = &PyOpType(OpDef);
  7687. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7688. py_type.tp_new = py_new_generic<py_op>;
  7689. py_type.tp_init = py_op::py_init;
  7690. py_type.tp_methods = py_op::tp_methods;
  7691. py_type.tp_getset = py_op::py_getsetters;
  7692. mgb_assert(PyType_Ready(&py_type) >= 0);
  7693. _init_py_Elemwise_Mode(py_type);
  7694. PyType_Modified(&py_type);
  7695. m.add_object("Elemwise", reinterpret_cast<PyObject*>(&py_type));
  7696. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Elemwise::typeinfo(), &py_type).second);
  7697. }
  7698. template<> struct EnumTrait<ElemwiseMultiType::Mode> {
  7699. static constexpr const char *name = "ElemwiseMultiType.Mode";
  7700. static constexpr std::underlying_type_t<ElemwiseMultiType::Mode> max = 64 - 1;
  7701. };
  7702. template<> PyTypeObject* EnumWrapper<ElemwiseMultiType::Mode>::type = nullptr;
  7703. template<> const char*
  7704. EnumWrapper<ElemwiseMultiType::Mode>::members[] = {"FUSE_MUL_ADD3_INT16x32x32x32", "FUSE_MUL_ADD3_IXxF32xF32xI8", "ROUND_SHR_SATURATE_IXxI8xI8", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", "ROUND_SHR_SATURATE_IXxI8xI16", "QADD", "QFUSE_ADD_RELU", "QMUL", "QMIN", "QMAX", "QSUB", "QTRUE_DIV", "QFUSE_ADD_SIGMOID", "QFUSE_ADD_TANH", "QRELU", "QABS", "QSIGMOID", "QEXP", "QTANH", "QFUSE_MUL_ADD3", "QFAST_TANH", "QNEGATE", "QACOS", "QASIN", "QCEIL", "QCOS", "QEXPM1", "QFLOOR", "QLOG", "QLOG1P", "QSIN", "QROUND", "QERF", "QERFINV", "QERFC", "QERFCINV", "QABS_GRAD", "QFLOOR_DIV", "QMOD", "QSIGMOID_GRAD", "QSWITCH_GT0", "QTANH_GRAD", "QLT", "QLEQ", "QEQ", "QPOW", "QLOG_SUM_EXP", "QFAST_TANH_GRAD", "QATAN2", "QCOND_LEQ_MOV", "QH_SWISH", "QFUSE_ADD_H_SWISH", "QH_SWISH_GRAD", "FUSE_MUL_ADD3_INT16xF32xF32xF32", "MUL_INT16xF32xF32", "FUSE_MUL_ADD3_UINT8xF32xF32xF32", "QCOND_LT_MOV", "EQ", "NEQ", "LT", "LEQ", "ISNAN", "ISINF"};
  7705. template<> std::unordered_map<std::string, ElemwiseMultiType::Mode>
  7706. EnumWrapper<ElemwiseMultiType::Mode>::mem2value = {{normalize_enum("FUSE_MUL_ADD3_INT16x32x32x32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32}, {normalize_enum("FUSE_MUL_ADD3_IXxF32xF32xI8"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8}, {normalize_enum("ROUND_SHR_SATURATE_IXxI8xI8"), ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8}, {normalize_enum("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8"), ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8}, {normalize_enum("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8"), ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8}, {normalize_enum("ROUND_SHR_SATURATE_IXxI8xI16"), ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16}, {normalize_enum("QADD"), ElemwiseMultiType::Mode::QADD}, {normalize_enum("QFUSE_ADD_RELU"), ElemwiseMultiType::Mode::QFUSE_ADD_RELU}, {normalize_enum("QMUL"), ElemwiseMultiType::Mode::QMUL}, {normalize_enum("QMIN"), ElemwiseMultiType::Mode::QMIN}, {normalize_enum("QMAX"), ElemwiseMultiType::Mode::QMAX}, {normalize_enum("QSUB"), ElemwiseMultiType::Mode::QSUB}, {normalize_enum("QTRUE_DIV"), ElemwiseMultiType::Mode::QTRUE_DIV}, {normalize_enum("QFUSE_ADD_SIGMOID"), ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID}, {normalize_enum("QFUSE_ADD_TANH"), ElemwiseMultiType::Mode::QFUSE_ADD_TANH}, {normalize_enum("QRELU"), ElemwiseMultiType::Mode::QRELU}, {normalize_enum("QABS"), ElemwiseMultiType::Mode::QABS}, {normalize_enum("QSIGMOID"), ElemwiseMultiType::Mode::QSIGMOID}, {normalize_enum("QEXP"), ElemwiseMultiType::Mode::QEXP}, {normalize_enum("QTANH"), ElemwiseMultiType::Mode::QTANH}, {normalize_enum("QFUSE_MUL_ADD3"), ElemwiseMultiType::Mode::QFUSE_MUL_ADD3}, {normalize_enum("QFAST_TANH"), ElemwiseMultiType::Mode::QFAST_TANH}, {normalize_enum("QNEGATE"), ElemwiseMultiType::Mode::QNEGATE}, {normalize_enum("QACOS"), ElemwiseMultiType::Mode::QACOS}, {normalize_enum("QASIN"), ElemwiseMultiType::Mode::QASIN}, {normalize_enum("QCEIL"), ElemwiseMultiType::Mode::QCEIL}, {normalize_enum("QCOS"), ElemwiseMultiType::Mode::QCOS}, {normalize_enum("QEXPM1"), ElemwiseMultiType::Mode::QEXPM1}, {normalize_enum("QFLOOR"), ElemwiseMultiType::Mode::QFLOOR}, {normalize_enum("QLOG"), ElemwiseMultiType::Mode::QLOG}, {normalize_enum("QLOG1P"), ElemwiseMultiType::Mode::QLOG1P}, {normalize_enum("QSIN"), ElemwiseMultiType::Mode::QSIN}, {normalize_enum("QROUND"), ElemwiseMultiType::Mode::QROUND}, {normalize_enum("QERF"), ElemwiseMultiType::Mode::QERF}, {normalize_enum("QERFINV"), ElemwiseMultiType::Mode::QERFINV}, {normalize_enum("QERFC"), ElemwiseMultiType::Mode::QERFC}, {normalize_enum("QERFCINV"), ElemwiseMultiType::Mode::QERFCINV}, {normalize_enum("QABS_GRAD"), ElemwiseMultiType::Mode::QABS_GRAD}, {normalize_enum("QFLOOR_DIV"), ElemwiseMultiType::Mode::QFLOOR_DIV}, {normalize_enum("QMOD"), ElemwiseMultiType::Mode::QMOD}, {normalize_enum("QSIGMOID_GRAD"), ElemwiseMultiType::Mode::QSIGMOID_GRAD}, {normalize_enum("QSWITCH_GT0"), ElemwiseMultiType::Mode::QSWITCH_GT0}, {normalize_enum("QTANH_GRAD"), ElemwiseMultiType::Mode::QTANH_GRAD}, {normalize_enum("QLT"), ElemwiseMultiType::Mode::QLT}, {normalize_enum("QLEQ"), ElemwiseMultiType::Mode::QLEQ}, {normalize_enum("QEQ"), ElemwiseMultiType::Mode::QEQ}, {normalize_enum("QPOW"), ElemwiseMultiType::Mode::QPOW}, {normalize_enum("QLOG_SUM_EXP"), ElemwiseMultiType::Mode::QLOG_SUM_EXP}, {normalize_enum("QFAST_TANH_GRAD"), ElemwiseMultiType::Mode::QFAST_TANH_GRAD}, {normalize_enum("QATAN2"), ElemwiseMultiType::Mode::QATAN2}, {normalize_enum("QCOND_LEQ_MOV"), ElemwiseMultiType::Mode::QCOND_LEQ_MOV}, {normalize_enum("QH_SWISH"), ElemwiseMultiType::Mode::QH_SWISH}, {normalize_enum("QFUSE_ADD_H_SWISH"), ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH}, {normalize_enum("QH_SWISH_GRAD"), ElemwiseMultiType::Mode::QH_SWISH_GRAD}, {normalize_enum("FUSE_MUL_ADD3_INT16xF32xF32xF32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32}, {normalize_enum("MUL_INT16xF32xF32"), ElemwiseMultiType::Mode::MUL_INT16xF32xF32}, {normalize_enum("FUSE_MUL_ADD3_UINT8xF32xF32xF32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32}, {normalize_enum("QCOND_LT_MOV"), ElemwiseMultiType::Mode::QCOND_LT_MOV}, {normalize_enum("EQ"), ElemwiseMultiType::Mode::EQ}, {normalize_enum("NEQ"), ElemwiseMultiType::Mode::NEQ}, {normalize_enum("LT"), ElemwiseMultiType::Mode::LT}, {normalize_enum("LEQ"), ElemwiseMultiType::Mode::LEQ}, {normalize_enum("ISNAN"), ElemwiseMultiType::Mode::ISNAN}, {normalize_enum("ISINF"), ElemwiseMultiType::Mode::ISINF}};
  7707. template<> PyObject* EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[64] = {nullptr};
  7708. void _init_py_ElemwiseMultiType_Mode(PyTypeObject& py_type) {
  7709. auto& e_type = EnumWrapper<ElemwiseMultiType::Mode>::type;
  7710. static PyMethodDef tp_methods[] = {
  7711. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ElemwiseMultiType::Mode>::py_dump, METH_NOARGS, NULL},
  7712. {NULL} /* Sentinel */
  7713. };
  7714. static PyType_Slot slots[] = {
  7715. {Py_tp_repr, (void*)EnumWrapper<ElemwiseMultiType::Mode>::py_repr},
  7716. {Py_tp_richcompare, (void*)EnumWrapper<ElemwiseMultiType::Mode>::tp_richcompare},
  7717. {Py_tp_methods, tp_methods},
  7718. {0, NULL}
  7719. };
  7720. static PyType_Spec spec = {
  7721. // name
  7722. "megengine.core._imperative_rt.ops.ElemwiseMultiType.Mode",
  7723. // basicsize
  7724. sizeof(EnumWrapper<ElemwiseMultiType::Mode>),
  7725. // itemsize
  7726. 0,
  7727. // flags
  7728. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  7729. // slots
  7730. slots
  7731. };
  7732. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  7733. mgb_assert(
  7734. e_type->tp_setattro(
  7735. reinterpret_cast<PyObject*>(e_type),
  7736. py::cast("__name__").release().ptr(),
  7737. py::cast("Mode").release().ptr()) >= 0);
  7738. mgb_assert(
  7739. e_type->tp_setattro(
  7740. reinterpret_cast<PyObject*>(e_type),
  7741. py::cast("__module__").release().ptr(),
  7742. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  7743. mgb_assert(
  7744. e_type->tp_setattro(
  7745. reinterpret_cast<PyObject*>(e_type),
  7746. py::cast("__qualname__").release().ptr(),
  7747. py::cast("ElemwiseMultiType.Mode").release().ptr()) >= 0);
  7748. {
  7749. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7750. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32;
  7751. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16x32x32x32", inst) >= 0);
  7752. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[0] = inst;
  7753. }{
  7754. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7755. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8;
  7756. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_IXxF32xF32xI8", inst) >= 0);
  7757. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[1] = inst;
  7758. }{
  7759. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7760. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8;
  7761. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI8", inst) >= 0);
  7762. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[2] = inst;
  7763. }{
  7764. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7765. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8;
  7766. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", inst) >= 0);
  7767. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[3] = inst;
  7768. }{
  7769. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7770. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8;
  7771. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", inst) >= 0);
  7772. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[4] = inst;
  7773. }{
  7774. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7775. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16;
  7776. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI16", inst) >= 0);
  7777. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[5] = inst;
  7778. }{
  7779. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7780. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QADD;
  7781. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QADD", inst) >= 0);
  7782. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[6] = inst;
  7783. }{
  7784. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7785. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_RELU;
  7786. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_RELU", inst) >= 0);
  7787. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[7] = inst;
  7788. }{
  7789. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7790. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMUL;
  7791. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMUL", inst) >= 0);
  7792. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[8] = inst;
  7793. }{
  7794. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7795. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMIN;
  7796. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMIN", inst) >= 0);
  7797. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[9] = inst;
  7798. }{
  7799. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7800. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMAX;
  7801. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMAX", inst) >= 0);
  7802. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[10] = inst;
  7803. }{
  7804. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7805. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSUB;
  7806. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSUB", inst) >= 0);
  7807. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[11] = inst;
  7808. }{
  7809. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7810. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTRUE_DIV;
  7811. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTRUE_DIV", inst) >= 0);
  7812. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[12] = inst;
  7813. }{
  7814. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7815. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID;
  7816. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_SIGMOID", inst) >= 0);
  7817. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[13] = inst;
  7818. }{
  7819. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7820. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_TANH;
  7821. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_TANH", inst) >= 0);
  7822. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[14] = inst;
  7823. }{
  7824. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7825. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QRELU;
  7826. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QRELU", inst) >= 0);
  7827. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[15] = inst;
  7828. }{
  7829. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7830. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QABS;
  7831. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS", inst) >= 0);
  7832. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[16] = inst;
  7833. }{
  7834. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7835. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID;
  7836. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID", inst) >= 0);
  7837. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[17] = inst;
  7838. }{
  7839. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7840. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEXP;
  7841. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXP", inst) >= 0);
  7842. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[18] = inst;
  7843. }{
  7844. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7845. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTANH;
  7846. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH", inst) >= 0);
  7847. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[19] = inst;
  7848. }{
  7849. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7850. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_MUL_ADD3;
  7851. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_MUL_ADD3", inst) >= 0);
  7852. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[20] = inst;
  7853. }{
  7854. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7855. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH;
  7856. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH", inst) >= 0);
  7857. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[21] = inst;
  7858. }{
  7859. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7860. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QNEGATE;
  7861. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QNEGATE", inst) >= 0);
  7862. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[22] = inst;
  7863. }{
  7864. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7865. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QACOS;
  7866. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QACOS", inst) >= 0);
  7867. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[23] = inst;
  7868. }{
  7869. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7870. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QASIN;
  7871. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QASIN", inst) >= 0);
  7872. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[24] = inst;
  7873. }{
  7874. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7875. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCEIL;
  7876. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCEIL", inst) >= 0);
  7877. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[25] = inst;
  7878. }{
  7879. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7880. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOS;
  7881. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOS", inst) >= 0);
  7882. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[26] = inst;
  7883. }{
  7884. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7885. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEXPM1;
  7886. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXPM1", inst) >= 0);
  7887. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[27] = inst;
  7888. }{
  7889. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7890. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR;
  7891. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR", inst) >= 0);
  7892. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[28] = inst;
  7893. }{
  7894. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7895. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG;
  7896. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG", inst) >= 0);
  7897. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[29] = inst;
  7898. }{
  7899. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7900. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG1P;
  7901. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG1P", inst) >= 0);
  7902. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[30] = inst;
  7903. }{
  7904. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7905. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIN;
  7906. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIN", inst) >= 0);
  7907. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[31] = inst;
  7908. }{
  7909. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7910. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QROUND;
  7911. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QROUND", inst) >= 0);
  7912. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[32] = inst;
  7913. }{
  7914. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7915. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERF;
  7916. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERF", inst) >= 0);
  7917. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[33] = inst;
  7918. }{
  7919. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7920. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFINV;
  7921. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFINV", inst) >= 0);
  7922. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[34] = inst;
  7923. }{
  7924. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7925. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFC;
  7926. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFC", inst) >= 0);
  7927. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[35] = inst;
  7928. }{
  7929. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7930. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFCINV;
  7931. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFCINV", inst) >= 0);
  7932. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[36] = inst;
  7933. }{
  7934. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7935. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QABS_GRAD;
  7936. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS_GRAD", inst) >= 0);
  7937. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[37] = inst;
  7938. }{
  7939. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7940. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR_DIV;
  7941. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR_DIV", inst) >= 0);
  7942. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[38] = inst;
  7943. }{
  7944. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7945. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMOD;
  7946. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMOD", inst) >= 0);
  7947. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[39] = inst;
  7948. }{
  7949. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7950. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID_GRAD;
  7951. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID_GRAD", inst) >= 0);
  7952. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[40] = inst;
  7953. }{
  7954. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7955. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSWITCH_GT0;
  7956. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSWITCH_GT0", inst) >= 0);
  7957. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[41] = inst;
  7958. }{
  7959. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7960. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTANH_GRAD;
  7961. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH_GRAD", inst) >= 0);
  7962. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[42] = inst;
  7963. }{
  7964. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7965. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLT;
  7966. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLT", inst) >= 0);
  7967. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[43] = inst;
  7968. }{
  7969. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7970. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLEQ;
  7971. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLEQ", inst) >= 0);
  7972. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[44] = inst;
  7973. }{
  7974. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7975. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEQ;
  7976. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEQ", inst) >= 0);
  7977. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[45] = inst;
  7978. }{
  7979. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7980. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QPOW;
  7981. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QPOW", inst) >= 0);
  7982. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[46] = inst;
  7983. }{
  7984. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7985. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG_SUM_EXP;
  7986. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG_SUM_EXP", inst) >= 0);
  7987. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[47] = inst;
  7988. }{
  7989. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7990. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH_GRAD;
  7991. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH_GRAD", inst) >= 0);
  7992. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[48] = inst;
  7993. }{
  7994. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7995. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QATAN2;
  7996. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QATAN2", inst) >= 0);
  7997. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[49] = inst;
  7998. }{
  7999. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8000. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LEQ_MOV;
  8001. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LEQ_MOV", inst) >= 0);
  8002. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[50] = inst;
  8003. }{
  8004. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8005. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH;
  8006. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH", inst) >= 0);
  8007. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[51] = inst;
  8008. }{
  8009. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8010. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH;
  8011. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_H_SWISH", inst) >= 0);
  8012. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[52] = inst;
  8013. }{
  8014. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8015. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH_GRAD;
  8016. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH_GRAD", inst) >= 0);
  8017. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[53] = inst;
  8018. }{
  8019. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8020. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32;
  8021. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16xF32xF32xF32", inst) >= 0);
  8022. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[54] = inst;
  8023. }{
  8024. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8025. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::MUL_INT16xF32xF32;
  8026. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL_INT16xF32xF32", inst) >= 0);
  8027. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[55] = inst;
  8028. }{
  8029. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8030. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32;
  8031. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_UINT8xF32xF32xF32", inst) >= 0);
  8032. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[56] = inst;
  8033. }{
  8034. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8035. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LT_MOV;
  8036. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LT_MOV", inst) >= 0);
  8037. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[57] = inst;
  8038. }{
  8039. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8040. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::EQ;
  8041. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EQ", inst) >= 0);
  8042. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[58] = inst;
  8043. }{
  8044. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8045. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::NEQ;
  8046. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEQ", inst) >= 0);
  8047. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[59] = inst;
  8048. }{
  8049. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8050. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::LT;
  8051. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LT", inst) >= 0);
  8052. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[60] = inst;
  8053. }{
  8054. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8055. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::LEQ;
  8056. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LEQ", inst) >= 0);
  8057. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[61] = inst;
  8058. }{
  8059. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8060. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ISNAN;
  8061. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISNAN", inst) >= 0);
  8062. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[62] = inst;
  8063. }{
  8064. PyObject* inst = e_type->tp_alloc(e_type, 0);
  8065. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ISINF;
  8066. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISINF", inst) >= 0);
  8067. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[63] = inst;
  8068. }
  8069. Py_INCREF(e_type);
  8070. mgb_assert(PyDict_SetItemString(
  8071. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8072. }
  8073. PyOpDefBegin(ElemwiseMultiType) // {
  8074. static PyGetSetDef py_getsetters[];
  8075. static PyMethodDef tp_methods[];
  8076. static PyObject* getstate(PyObject* self, PyObject*) {
  8077. auto& opdef = reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst();
  8078. static_cast<void>(opdef);
  8079. std::unordered_map<std::string, py::object> state {
  8080. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  8081. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  8082. };
  8083. return py::cast(state).release().ptr();
  8084. }
  8085. static PyObject* setstate(PyObject* self, PyObject* args) {
  8086. PyObject* dict = PyTuple_GetItem(args, 0);
  8087. if (!dict) return NULL;
  8088. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8089. auto& opdef = reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst();
  8090. static_cast<void>(opdef);
  8091. {
  8092. auto&& iter = state.find("mode");
  8093. if (iter != state.end()) {
  8094. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  8095. }
  8096. }
  8097. {
  8098. auto&& iter = state.find("dtype");
  8099. if (iter != state.end()) {
  8100. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  8101. }
  8102. }
  8103. Py_RETURN_NONE;
  8104. }
  8105. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8106. // };
  8107. PyOpDefEnd(ElemwiseMultiType)
  8108. int PyOp(ElemwiseMultiType)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8109. static const char* kwlist[] = {"mode", "dtype", "scope", NULL};
  8110. PyObject *mode = NULL, *dtype = NULL, *scope = NULL;
  8111. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &mode, &dtype, &scope))
  8112. return -1;
  8113. if (mode) {
  8114. try {
  8115. // TODO: remove this guard which is used for pybind11 implicit conversion
  8116. py::detail::loader_life_support guard{};
  8117. reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst().mode =
  8118. py::cast<decltype(ElemwiseMultiType::mode)>(py::handle(mode));
  8119. } CATCH_ALL(-1)
  8120. }
  8121. if (dtype) {
  8122. try {
  8123. // TODO: remove this guard which is used for pybind11 implicit conversion
  8124. py::detail::loader_life_support guard{};
  8125. reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst().dtype =
  8126. py::cast<decltype(ElemwiseMultiType::dtype)>(py::handle(dtype));
  8127. } CATCH_ALL(-1)
  8128. }
  8129. if (scope) {
  8130. try {
  8131. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8132. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8133. } CATCH_ALL(-1)
  8134. }
  8135. return 0;
  8136. }
  8137. PyGetSetDef PyOp(ElemwiseMultiType)::py_getsetters[] = {
  8138. {const_cast<char*>("mode"), py_get_generic(ElemwiseMultiType, mode), py_set_generic(ElemwiseMultiType, mode), const_cast<char*>("mode"), NULL},
  8139. {const_cast<char*>("dtype"), py_get_generic(ElemwiseMultiType, dtype), py_set_generic(ElemwiseMultiType, dtype), const_cast<char*>("dtype"), NULL},
  8140. {NULL} /* Sentinel */
  8141. };
  8142. PyMethodDef PyOp(ElemwiseMultiType)::tp_methods[] = {
  8143. {const_cast<char*>("__getstate__"), PyOp(ElemwiseMultiType)::getstate, METH_NOARGS, "ElemwiseMultiType getstate"},
  8144. {const_cast<char*>("__setstate__"), PyOp(ElemwiseMultiType)::setstate, METH_VARARGS, "ElemwiseMultiType setstate"},
  8145. {NULL} /* Sentinel */
  8146. };
  8147. void _init_py_ElemwiseMultiType(py::module m) {
  8148. using py_op = PyOp(ElemwiseMultiType);
  8149. auto& py_type = PyOpType(ElemwiseMultiType);
  8150. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8151. py_type.tp_name = "megengine.core._imperative_rt.ops.ElemwiseMultiType";
  8152. py_type.tp_basicsize = sizeof(PyOp(ElemwiseMultiType));
  8153. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8154. py_type.tp_doc = "ElemwiseMultiType";
  8155. py_type.tp_base = &PyOpType(OpDef);
  8156. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8157. py_type.tp_new = py_new_generic<py_op>;
  8158. py_type.tp_init = py_op::py_init;
  8159. py_type.tp_methods = py_op::tp_methods;
  8160. py_type.tp_getset = py_op::py_getsetters;
  8161. mgb_assert(PyType_Ready(&py_type) >= 0);
  8162. _init_py_ElemwiseMultiType_Mode(py_type);
  8163. PyType_Modified(&py_type);
  8164. m.add_object("ElemwiseMultiType", reinterpret_cast<PyObject*>(&py_type));
  8165. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ElemwiseMultiType::typeinfo(), &py_type).second);
  8166. }
  8167. PyOpDefBegin(ExternOpr) // {
  8168. static PyGetSetDef py_getsetters[];
  8169. static PyMethodDef tp_methods[];
  8170. static PyObject* getstate(PyObject* self, PyObject*) {
  8171. auto& opdef = reinterpret_cast<PyOp(ExternOpr)*>(self)->inst();
  8172. static_cast<void>(opdef);
  8173. std::unordered_map<std::string, py::object> state {
  8174. {"output_shapes", serialization<decltype(opdef.output_shapes)>::dump(opdef.output_shapes)},
  8175. {"name", serialization<decltype(opdef.name)>::dump(opdef.name)},
  8176. {"data", serialization<decltype(opdef.data)>::dump(opdef.data)},
  8177. {"data_len", serialization<decltype(opdef.data_len)>::dump(opdef.data_len)},
  8178. {"output_dtypes", serialization<decltype(opdef.output_dtypes)>::dump(opdef.output_dtypes)}
  8179. };
  8180. return py::cast(state).release().ptr();
  8181. }
  8182. static PyObject* setstate(PyObject* self, PyObject* args) {
  8183. PyObject* dict = PyTuple_GetItem(args, 0);
  8184. if (!dict) return NULL;
  8185. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8186. auto& opdef = reinterpret_cast<PyOp(ExternOpr)*>(self)->inst();
  8187. static_cast<void>(opdef);
  8188. {
  8189. auto&& iter = state.find("output_shapes");
  8190. if (iter != state.end()) {
  8191. opdef.output_shapes = serialization<decltype(opdef.output_shapes)>::load(iter->second);
  8192. }
  8193. }
  8194. {
  8195. auto&& iter = state.find("name");
  8196. if (iter != state.end()) {
  8197. opdef.name = serialization<decltype(opdef.name)>::load(iter->second);
  8198. }
  8199. }
  8200. {
  8201. auto&& iter = state.find("data");
  8202. if (iter != state.end()) {
  8203. opdef.data = serialization<decltype(opdef.data)>::load(iter->second);
  8204. }
  8205. }
  8206. {
  8207. auto&& iter = state.find("data_len");
  8208. if (iter != state.end()) {
  8209. opdef.data_len = serialization<decltype(opdef.data_len)>::load(iter->second);
  8210. }
  8211. }
  8212. {
  8213. auto&& iter = state.find("output_dtypes");
  8214. if (iter != state.end()) {
  8215. opdef.output_dtypes = serialization<decltype(opdef.output_dtypes)>::load(iter->second);
  8216. }
  8217. }
  8218. Py_RETURN_NONE;
  8219. }
  8220. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8221. // };
  8222. PyOpDefEnd(ExternOpr)
  8223. int PyOp(ExternOpr)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8224. static const char* kwlist[] = {"output_shapes", "name", "data", "data_len", "output_dtypes", "scope", NULL};
  8225. PyObject *output_shapes = NULL, *name = NULL, *data = NULL, *data_len = NULL, *output_dtypes = NULL, *scope = NULL;
  8226. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &output_shapes, &name, &data, &data_len, &output_dtypes, &scope))
  8227. return -1;
  8228. if (output_shapes) {
  8229. try {
  8230. // TODO: remove this guard which is used for pybind11 implicit conversion
  8231. py::detail::loader_life_support guard{};
  8232. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().output_shapes =
  8233. py::cast<decltype(ExternOpr::output_shapes)>(py::handle(output_shapes));
  8234. } CATCH_ALL(-1)
  8235. }
  8236. if (name) {
  8237. try {
  8238. // TODO: remove this guard which is used for pybind11 implicit conversion
  8239. py::detail::loader_life_support guard{};
  8240. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().name =
  8241. py::cast<decltype(ExternOpr::name)>(py::handle(name));
  8242. } CATCH_ALL(-1)
  8243. }
  8244. if (data) {
  8245. try {
  8246. // TODO: remove this guard which is used for pybind11 implicit conversion
  8247. py::detail::loader_life_support guard{};
  8248. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().data =
  8249. py::cast<decltype(ExternOpr::data)>(py::handle(data));
  8250. } CATCH_ALL(-1)
  8251. }
  8252. if (data_len) {
  8253. try {
  8254. // TODO: remove this guard which is used for pybind11 implicit conversion
  8255. py::detail::loader_life_support guard{};
  8256. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().data_len =
  8257. py::cast<decltype(ExternOpr::data_len)>(py::handle(data_len));
  8258. } CATCH_ALL(-1)
  8259. }
  8260. if (output_dtypes) {
  8261. try {
  8262. // TODO: remove this guard which is used for pybind11 implicit conversion
  8263. py::detail::loader_life_support guard{};
  8264. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().output_dtypes =
  8265. py::cast<decltype(ExternOpr::output_dtypes)>(py::handle(output_dtypes));
  8266. } CATCH_ALL(-1)
  8267. }
  8268. if (scope) {
  8269. try {
  8270. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8271. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8272. } CATCH_ALL(-1)
  8273. }
  8274. return 0;
  8275. }
  8276. PyGetSetDef PyOp(ExternOpr)::py_getsetters[] = {
  8277. {const_cast<char*>("output_shapes"), py_get_generic(ExternOpr, output_shapes), py_set_generic(ExternOpr, output_shapes), const_cast<char*>("output_shapes"), NULL},
  8278. {const_cast<char*>("name"), py_get_generic(ExternOpr, name), py_set_generic(ExternOpr, name), const_cast<char*>("name"), NULL},
  8279. {const_cast<char*>("data"), py_get_generic(ExternOpr, data), py_set_generic(ExternOpr, data), const_cast<char*>("data"), NULL},
  8280. {const_cast<char*>("data_len"), py_get_generic(ExternOpr, data_len), py_set_generic(ExternOpr, data_len), const_cast<char*>("data_len"), NULL},
  8281. {const_cast<char*>("output_dtypes"), py_get_generic(ExternOpr, output_dtypes), py_set_generic(ExternOpr, output_dtypes), const_cast<char*>("output_dtypes"), NULL},
  8282. {NULL} /* Sentinel */
  8283. };
  8284. PyMethodDef PyOp(ExternOpr)::tp_methods[] = {
  8285. {const_cast<char*>("__getstate__"), PyOp(ExternOpr)::getstate, METH_NOARGS, "ExternOpr getstate"},
  8286. {const_cast<char*>("__setstate__"), PyOp(ExternOpr)::setstate, METH_VARARGS, "ExternOpr setstate"},
  8287. {NULL} /* Sentinel */
  8288. };
  8289. void _init_py_ExternOpr(py::module m) {
  8290. using py_op = PyOp(ExternOpr);
  8291. auto& py_type = PyOpType(ExternOpr);
  8292. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8293. py_type.tp_name = "megengine.core._imperative_rt.ops.ExternOpr";
  8294. py_type.tp_basicsize = sizeof(PyOp(ExternOpr));
  8295. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8296. py_type.tp_doc = "ExternOpr";
  8297. py_type.tp_base = &PyOpType(OpDef);
  8298. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8299. py_type.tp_new = py_new_generic<py_op>;
  8300. py_type.tp_init = py_op::py_init;
  8301. py_type.tp_methods = py_op::tp_methods;
  8302. py_type.tp_getset = py_op::py_getsetters;
  8303. mgb_assert(PyType_Ready(&py_type) >= 0);
  8304. PyType_Modified(&py_type);
  8305. m.add_object("ExternOpr", reinterpret_cast<PyObject*>(&py_type));
  8306. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ExternOpr::typeinfo(), &py_type).second);
  8307. }
  8308. PyOpDefBegin(Eye) // {
  8309. static PyGetSetDef py_getsetters[];
  8310. static PyMethodDef tp_methods[];
  8311. static PyObject* getstate(PyObject* self, PyObject*) {
  8312. auto& opdef = reinterpret_cast<PyOp(Eye)*>(self)->inst();
  8313. static_cast<void>(opdef);
  8314. std::unordered_map<std::string, py::object> state {
  8315. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)},
  8316. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  8317. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  8318. };
  8319. return py::cast(state).release().ptr();
  8320. }
  8321. static PyObject* setstate(PyObject* self, PyObject* args) {
  8322. PyObject* dict = PyTuple_GetItem(args, 0);
  8323. if (!dict) return NULL;
  8324. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8325. auto& opdef = reinterpret_cast<PyOp(Eye)*>(self)->inst();
  8326. static_cast<void>(opdef);
  8327. {
  8328. auto&& iter = state.find("k");
  8329. if (iter != state.end()) {
  8330. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  8331. }
  8332. }
  8333. {
  8334. auto&& iter = state.find("dtype");
  8335. if (iter != state.end()) {
  8336. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  8337. }
  8338. }
  8339. {
  8340. auto&& iter = state.find("comp_node");
  8341. if (iter != state.end()) {
  8342. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  8343. }
  8344. }
  8345. Py_RETURN_NONE;
  8346. }
  8347. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8348. // };
  8349. PyOpDefEnd(Eye)
  8350. int PyOp(Eye)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8351. static const char* kwlist[] = {"k", "dtype", "comp_node", "scope", NULL};
  8352. PyObject *k = NULL, *dtype = NULL, *comp_node = NULL, *scope = NULL;
  8353. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &k, &dtype, &comp_node, &scope))
  8354. return -1;
  8355. if (k) {
  8356. try {
  8357. // TODO: remove this guard which is used for pybind11 implicit conversion
  8358. py::detail::loader_life_support guard{};
  8359. reinterpret_cast<PyOp(Eye)*>(self)->inst().k =
  8360. py::cast<decltype(Eye::k)>(py::handle(k));
  8361. } CATCH_ALL(-1)
  8362. }
  8363. if (dtype) {
  8364. try {
  8365. // TODO: remove this guard which is used for pybind11 implicit conversion
  8366. py::detail::loader_life_support guard{};
  8367. reinterpret_cast<PyOp(Eye)*>(self)->inst().dtype =
  8368. py::cast<decltype(Eye::dtype)>(py::handle(dtype));
  8369. } CATCH_ALL(-1)
  8370. }
  8371. if (comp_node) {
  8372. try {
  8373. // TODO: remove this guard which is used for pybind11 implicit conversion
  8374. py::detail::loader_life_support guard{};
  8375. reinterpret_cast<PyOp(Eye)*>(self)->inst().comp_node =
  8376. py::cast<decltype(Eye::comp_node)>(py::handle(comp_node));
  8377. } CATCH_ALL(-1)
  8378. }
  8379. if (scope) {
  8380. try {
  8381. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8382. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8383. } CATCH_ALL(-1)
  8384. }
  8385. return 0;
  8386. }
  8387. PyGetSetDef PyOp(Eye)::py_getsetters[] = {
  8388. {const_cast<char*>("k"), py_get_generic(Eye, k), py_set_generic(Eye, k), const_cast<char*>("k"), NULL},
  8389. {const_cast<char*>("dtype"), py_get_generic(Eye, dtype), py_set_generic(Eye, dtype), const_cast<char*>("dtype"), NULL},
  8390. {const_cast<char*>("comp_node"), py_get_generic(Eye, comp_node), py_set_generic(Eye, comp_node), const_cast<char*>("comp_node"), NULL},
  8391. {NULL} /* Sentinel */
  8392. };
  8393. PyMethodDef PyOp(Eye)::tp_methods[] = {
  8394. {const_cast<char*>("__getstate__"), PyOp(Eye)::getstate, METH_NOARGS, "Eye getstate"},
  8395. {const_cast<char*>("__setstate__"), PyOp(Eye)::setstate, METH_VARARGS, "Eye setstate"},
  8396. {NULL} /* Sentinel */
  8397. };
  8398. void _init_py_Eye(py::module m) {
  8399. using py_op = PyOp(Eye);
  8400. auto& py_type = PyOpType(Eye);
  8401. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8402. py_type.tp_name = "megengine.core._imperative_rt.ops.Eye";
  8403. py_type.tp_basicsize = sizeof(PyOp(Eye));
  8404. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8405. py_type.tp_doc = "Eye";
  8406. py_type.tp_base = &PyOpType(OpDef);
  8407. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8408. py_type.tp_new = py_new_generic<py_op>;
  8409. py_type.tp_init = py_op::py_init;
  8410. py_type.tp_methods = py_op::tp_methods;
  8411. py_type.tp_getset = py_op::py_getsetters;
  8412. mgb_assert(PyType_Ready(&py_type) >= 0);
  8413. PyType_Modified(&py_type);
  8414. m.add_object("Eye", reinterpret_cast<PyObject*>(&py_type));
  8415. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Eye::typeinfo(), &py_type).second);
  8416. }
  8417. PyOpDefBegin(FakeQuant) // {
  8418. static PyGetSetDef py_getsetters[];
  8419. static PyMethodDef tp_methods[];
  8420. static PyObject* getstate(PyObject* self, PyObject*) {
  8421. auto& opdef = reinterpret_cast<PyOp(FakeQuant)*>(self)->inst();
  8422. static_cast<void>(opdef);
  8423. std::unordered_map<std::string, py::object> state {
  8424. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  8425. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  8426. };
  8427. return py::cast(state).release().ptr();
  8428. }
  8429. static PyObject* setstate(PyObject* self, PyObject* args) {
  8430. PyObject* dict = PyTuple_GetItem(args, 0);
  8431. if (!dict) return NULL;
  8432. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8433. auto& opdef = reinterpret_cast<PyOp(FakeQuant)*>(self)->inst();
  8434. static_cast<void>(opdef);
  8435. {
  8436. auto&& iter = state.find("qmin");
  8437. if (iter != state.end()) {
  8438. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  8439. }
  8440. }
  8441. {
  8442. auto&& iter = state.find("qmax");
  8443. if (iter != state.end()) {
  8444. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  8445. }
  8446. }
  8447. Py_RETURN_NONE;
  8448. }
  8449. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8450. // };
  8451. PyOpDefEnd(FakeQuant)
  8452. int PyOp(FakeQuant)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8453. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  8454. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  8455. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  8456. return -1;
  8457. if (qmin) {
  8458. try {
  8459. // TODO: remove this guard which is used for pybind11 implicit conversion
  8460. py::detail::loader_life_support guard{};
  8461. reinterpret_cast<PyOp(FakeQuant)*>(self)->inst().qmin =
  8462. py::cast<decltype(FakeQuant::qmin)>(py::handle(qmin));
  8463. } CATCH_ALL(-1)
  8464. }
  8465. if (qmax) {
  8466. try {
  8467. // TODO: remove this guard which is used for pybind11 implicit conversion
  8468. py::detail::loader_life_support guard{};
  8469. reinterpret_cast<PyOp(FakeQuant)*>(self)->inst().qmax =
  8470. py::cast<decltype(FakeQuant::qmax)>(py::handle(qmax));
  8471. } CATCH_ALL(-1)
  8472. }
  8473. if (scope) {
  8474. try {
  8475. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8476. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8477. } CATCH_ALL(-1)
  8478. }
  8479. return 0;
  8480. }
  8481. PyGetSetDef PyOp(FakeQuant)::py_getsetters[] = {
  8482. {const_cast<char*>("qmin"), py_get_generic(FakeQuant, qmin), py_set_generic(FakeQuant, qmin), const_cast<char*>("qmin"), NULL},
  8483. {const_cast<char*>("qmax"), py_get_generic(FakeQuant, qmax), py_set_generic(FakeQuant, qmax), const_cast<char*>("qmax"), NULL},
  8484. {NULL} /* Sentinel */
  8485. };
  8486. PyMethodDef PyOp(FakeQuant)::tp_methods[] = {
  8487. {const_cast<char*>("__getstate__"), PyOp(FakeQuant)::getstate, METH_NOARGS, "FakeQuant getstate"},
  8488. {const_cast<char*>("__setstate__"), PyOp(FakeQuant)::setstate, METH_VARARGS, "FakeQuant setstate"},
  8489. {NULL} /* Sentinel */
  8490. };
  8491. void _init_py_FakeQuant(py::module m) {
  8492. using py_op = PyOp(FakeQuant);
  8493. auto& py_type = PyOpType(FakeQuant);
  8494. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8495. py_type.tp_name = "megengine.core._imperative_rt.ops.FakeQuant";
  8496. py_type.tp_basicsize = sizeof(PyOp(FakeQuant));
  8497. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8498. py_type.tp_doc = "FakeQuant";
  8499. py_type.tp_base = &PyOpType(OpDef);
  8500. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8501. py_type.tp_new = py_new_generic<py_op>;
  8502. py_type.tp_init = py_op::py_init;
  8503. py_type.tp_methods = py_op::tp_methods;
  8504. py_type.tp_getset = py_op::py_getsetters;
  8505. mgb_assert(PyType_Ready(&py_type) >= 0);
  8506. PyType_Modified(&py_type);
  8507. m.add_object("FakeQuant", reinterpret_cast<PyObject*>(&py_type));
  8508. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FakeQuant::typeinfo(), &py_type).second);
  8509. }
  8510. PyOpDefBegin(FastpathCopy) // {
  8511. static PyGetSetDef py_getsetters[];
  8512. static PyMethodDef tp_methods[];
  8513. static PyObject* getstate(PyObject* self, PyObject*) {
  8514. auto& opdef = reinterpret_cast<PyOp(FastpathCopy)*>(self)->inst();
  8515. static_cast<void>(opdef);
  8516. std::unordered_map<std::string, py::object> state {
  8517. };
  8518. return py::cast(state).release().ptr();
  8519. }
  8520. static PyObject* setstate(PyObject* self, PyObject* args) {
  8521. PyObject* dict = PyTuple_GetItem(args, 0);
  8522. if (!dict) return NULL;
  8523. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8524. auto& opdef = reinterpret_cast<PyOp(FastpathCopy)*>(self)->inst();
  8525. static_cast<void>(opdef);
  8526. Py_RETURN_NONE;
  8527. }
  8528. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8529. // };
  8530. PyOpDefEnd(FastpathCopy)
  8531. int PyOp(FastpathCopy)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8532. return 0;
  8533. }
  8534. PyGetSetDef PyOp(FastpathCopy)::py_getsetters[] = {
  8535. {NULL} /* Sentinel */
  8536. };
  8537. PyMethodDef PyOp(FastpathCopy)::tp_methods[] = {
  8538. {const_cast<char*>("__getstate__"), PyOp(FastpathCopy)::getstate, METH_NOARGS, "FastpathCopy getstate"},
  8539. {const_cast<char*>("__setstate__"), PyOp(FastpathCopy)::setstate, METH_VARARGS, "FastpathCopy setstate"},
  8540. {NULL} /* Sentinel */
  8541. };
  8542. void _init_py_FastpathCopy(py::module m) {
  8543. using py_op = PyOp(FastpathCopy);
  8544. auto& py_type = PyOpType(FastpathCopy);
  8545. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8546. py_type.tp_name = "megengine.core._imperative_rt.ops.FastpathCopy";
  8547. py_type.tp_basicsize = sizeof(PyOp(FastpathCopy));
  8548. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8549. py_type.tp_doc = "FastpathCopy";
  8550. py_type.tp_base = &PyOpType(OpDef);
  8551. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8552. py_type.tp_new = py_new_generic<py_op>;
  8553. py_type.tp_init = py_op::py_init;
  8554. py_type.tp_methods = py_op::tp_methods;
  8555. py_type.tp_getset = py_op::py_getsetters;
  8556. mgb_assert(PyType_Ready(&py_type) >= 0);
  8557. PyType_Modified(&py_type);
  8558. m.add_object("FastpathCopy", reinterpret_cast<PyObject*>(&py_type));
  8559. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FastpathCopy::typeinfo(), &py_type).second);
  8560. }
  8561. PyOpDefBegin(GammaRNG) // {
  8562. static PyGetSetDef py_getsetters[];
  8563. static PyMethodDef tp_methods[];
  8564. static PyObject* getstate(PyObject* self, PyObject*) {
  8565. auto& opdef = reinterpret_cast<PyOp(GammaRNG)*>(self)->inst();
  8566. static_cast<void>(opdef);
  8567. std::unordered_map<std::string, py::object> state {
  8568. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  8569. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  8570. };
  8571. return py::cast(state).release().ptr();
  8572. }
  8573. static PyObject* setstate(PyObject* self, PyObject* args) {
  8574. PyObject* dict = PyTuple_GetItem(args, 0);
  8575. if (!dict) return NULL;
  8576. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8577. auto& opdef = reinterpret_cast<PyOp(GammaRNG)*>(self)->inst();
  8578. static_cast<void>(opdef);
  8579. {
  8580. auto&& iter = state.find("seed");
  8581. if (iter != state.end()) {
  8582. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  8583. }
  8584. }
  8585. {
  8586. auto&& iter = state.find("handle");
  8587. if (iter != state.end()) {
  8588. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  8589. }
  8590. }
  8591. Py_RETURN_NONE;
  8592. }
  8593. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8594. // };
  8595. PyOpDefEnd(GammaRNG)
  8596. int PyOp(GammaRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8597. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  8598. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  8599. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  8600. return -1;
  8601. if (seed) {
  8602. try {
  8603. // TODO: remove this guard which is used for pybind11 implicit conversion
  8604. py::detail::loader_life_support guard{};
  8605. reinterpret_cast<PyOp(GammaRNG)*>(self)->inst().seed =
  8606. py::cast<decltype(GammaRNG::seed)>(py::handle(seed));
  8607. } CATCH_ALL(-1)
  8608. }
  8609. if (handle) {
  8610. try {
  8611. // TODO: remove this guard which is used for pybind11 implicit conversion
  8612. py::detail::loader_life_support guard{};
  8613. reinterpret_cast<PyOp(GammaRNG)*>(self)->inst().handle =
  8614. py::cast<decltype(GammaRNG::handle)>(py::handle(handle));
  8615. } CATCH_ALL(-1)
  8616. }
  8617. if (scope) {
  8618. try {
  8619. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8620. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8621. } CATCH_ALL(-1)
  8622. }
  8623. return 0;
  8624. }
  8625. PyGetSetDef PyOp(GammaRNG)::py_getsetters[] = {
  8626. {const_cast<char*>("seed"), py_get_generic(GammaRNG, seed), py_set_generic(GammaRNG, seed), const_cast<char*>("seed"), NULL},
  8627. {const_cast<char*>("handle"), py_get_generic(GammaRNG, handle), py_set_generic(GammaRNG, handle), const_cast<char*>("handle"), NULL},
  8628. {NULL} /* Sentinel */
  8629. };
  8630. PyMethodDef PyOp(GammaRNG)::tp_methods[] = {
  8631. {const_cast<char*>("__getstate__"), PyOp(GammaRNG)::getstate, METH_NOARGS, "GammaRNG getstate"},
  8632. {const_cast<char*>("__setstate__"), PyOp(GammaRNG)::setstate, METH_VARARGS, "GammaRNG setstate"},
  8633. {NULL} /* Sentinel */
  8634. };
  8635. void _init_py_GammaRNG(py::module m) {
  8636. using py_op = PyOp(GammaRNG);
  8637. auto& py_type = PyOpType(GammaRNG);
  8638. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8639. py_type.tp_name = "megengine.core._imperative_rt.ops.GammaRNG";
  8640. py_type.tp_basicsize = sizeof(PyOp(GammaRNG));
  8641. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8642. py_type.tp_doc = "GammaRNG";
  8643. py_type.tp_base = &PyOpType(OpDef);
  8644. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8645. py_type.tp_new = py_new_generic<py_op>;
  8646. py_type.tp_init = py_op::py_init;
  8647. py_type.tp_methods = py_op::tp_methods;
  8648. py_type.tp_getset = py_op::py_getsetters;
  8649. mgb_assert(PyType_Ready(&py_type) >= 0);
  8650. PyType_Modified(&py_type);
  8651. m.add_object("GammaRNG", reinterpret_cast<PyObject*>(&py_type));
  8652. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GammaRNG::typeinfo(), &py_type).second);
  8653. }
  8654. PyOpDefBegin(GaussianRNG) // {
  8655. static PyGetSetDef py_getsetters[];
  8656. static PyMethodDef tp_methods[];
  8657. static PyObject* getstate(PyObject* self, PyObject*) {
  8658. auto& opdef = reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst();
  8659. static_cast<void>(opdef);
  8660. std::unordered_map<std::string, py::object> state {
  8661. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  8662. {"mean", serialization<decltype(opdef.mean)>::dump(opdef.mean)},
  8663. {"std", serialization<decltype(opdef.std)>::dump(opdef.std)},
  8664. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  8665. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  8666. };
  8667. return py::cast(state).release().ptr();
  8668. }
  8669. static PyObject* setstate(PyObject* self, PyObject* args) {
  8670. PyObject* dict = PyTuple_GetItem(args, 0);
  8671. if (!dict) return NULL;
  8672. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8673. auto& opdef = reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst();
  8674. static_cast<void>(opdef);
  8675. {
  8676. auto&& iter = state.find("seed");
  8677. if (iter != state.end()) {
  8678. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  8679. }
  8680. }
  8681. {
  8682. auto&& iter = state.find("mean");
  8683. if (iter != state.end()) {
  8684. opdef.mean = serialization<decltype(opdef.mean)>::load(iter->second);
  8685. }
  8686. }
  8687. {
  8688. auto&& iter = state.find("std");
  8689. if (iter != state.end()) {
  8690. opdef.std = serialization<decltype(opdef.std)>::load(iter->second);
  8691. }
  8692. }
  8693. {
  8694. auto&& iter = state.find("dtype");
  8695. if (iter != state.end()) {
  8696. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  8697. }
  8698. }
  8699. {
  8700. auto&& iter = state.find("handle");
  8701. if (iter != state.end()) {
  8702. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  8703. }
  8704. }
  8705. Py_RETURN_NONE;
  8706. }
  8707. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8708. // };
  8709. PyOpDefEnd(GaussianRNG)
  8710. int PyOp(GaussianRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8711. static const char* kwlist[] = {"seed", "mean", "std", "dtype", "handle", "scope", NULL};
  8712. PyObject *seed = NULL, *mean = NULL, *std = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  8713. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &seed, &mean, &std, &dtype, &handle, &scope))
  8714. return -1;
  8715. if (seed) {
  8716. try {
  8717. // TODO: remove this guard which is used for pybind11 implicit conversion
  8718. py::detail::loader_life_support guard{};
  8719. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().seed =
  8720. py::cast<decltype(GaussianRNG::seed)>(py::handle(seed));
  8721. } CATCH_ALL(-1)
  8722. }
  8723. if (mean) {
  8724. try {
  8725. // TODO: remove this guard which is used for pybind11 implicit conversion
  8726. py::detail::loader_life_support guard{};
  8727. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().mean =
  8728. py::cast<decltype(GaussianRNG::mean)>(py::handle(mean));
  8729. } CATCH_ALL(-1)
  8730. }
  8731. if (std) {
  8732. try {
  8733. // TODO: remove this guard which is used for pybind11 implicit conversion
  8734. py::detail::loader_life_support guard{};
  8735. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().std =
  8736. py::cast<decltype(GaussianRNG::std)>(py::handle(std));
  8737. } CATCH_ALL(-1)
  8738. }
  8739. if (dtype) {
  8740. try {
  8741. // TODO: remove this guard which is used for pybind11 implicit conversion
  8742. py::detail::loader_life_support guard{};
  8743. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().dtype =
  8744. py::cast<decltype(GaussianRNG::dtype)>(py::handle(dtype));
  8745. } CATCH_ALL(-1)
  8746. }
  8747. if (handle) {
  8748. try {
  8749. // TODO: remove this guard which is used for pybind11 implicit conversion
  8750. py::detail::loader_life_support guard{};
  8751. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().handle =
  8752. py::cast<decltype(GaussianRNG::handle)>(py::handle(handle));
  8753. } CATCH_ALL(-1)
  8754. }
  8755. if (scope) {
  8756. try {
  8757. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8758. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8759. } CATCH_ALL(-1)
  8760. }
  8761. return 0;
  8762. }
  8763. PyGetSetDef PyOp(GaussianRNG)::py_getsetters[] = {
  8764. {const_cast<char*>("seed"), py_get_generic(GaussianRNG, seed), py_set_generic(GaussianRNG, seed), const_cast<char*>("seed"), NULL},
  8765. {const_cast<char*>("mean"), py_get_generic(GaussianRNG, mean), py_set_generic(GaussianRNG, mean), const_cast<char*>("mean"), NULL},
  8766. {const_cast<char*>("std"), py_get_generic(GaussianRNG, std), py_set_generic(GaussianRNG, std), const_cast<char*>("std"), NULL},
  8767. {const_cast<char*>("dtype"), py_get_generic(GaussianRNG, dtype), py_set_generic(GaussianRNG, dtype), const_cast<char*>("dtype"), NULL},
  8768. {const_cast<char*>("handle"), py_get_generic(GaussianRNG, handle), py_set_generic(GaussianRNG, handle), const_cast<char*>("handle"), NULL},
  8769. {NULL} /* Sentinel */
  8770. };
  8771. PyMethodDef PyOp(GaussianRNG)::tp_methods[] = {
  8772. {const_cast<char*>("__getstate__"), PyOp(GaussianRNG)::getstate, METH_NOARGS, "GaussianRNG getstate"},
  8773. {const_cast<char*>("__setstate__"), PyOp(GaussianRNG)::setstate, METH_VARARGS, "GaussianRNG setstate"},
  8774. {NULL} /* Sentinel */
  8775. };
  8776. void _init_py_GaussianRNG(py::module m) {
  8777. using py_op = PyOp(GaussianRNG);
  8778. auto& py_type = PyOpType(GaussianRNG);
  8779. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8780. py_type.tp_name = "megengine.core._imperative_rt.ops.GaussianRNG";
  8781. py_type.tp_basicsize = sizeof(PyOp(GaussianRNG));
  8782. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8783. py_type.tp_doc = "GaussianRNG";
  8784. py_type.tp_base = &PyOpType(OpDef);
  8785. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8786. py_type.tp_new = py_new_generic<py_op>;
  8787. py_type.tp_init = py_op::py_init;
  8788. py_type.tp_methods = py_op::tp_methods;
  8789. py_type.tp_getset = py_op::py_getsetters;
  8790. mgb_assert(PyType_Ready(&py_type) >= 0);
  8791. PyType_Modified(&py_type);
  8792. m.add_object("GaussianRNG", reinterpret_cast<PyObject*>(&py_type));
  8793. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GaussianRNG::typeinfo(), &py_type).second);
  8794. }
  8795. PyOpDefBegin(GetVarShape) // {
  8796. static PyGetSetDef py_getsetters[];
  8797. static PyMethodDef tp_methods[];
  8798. static PyObject* getstate(PyObject* self, PyObject*) {
  8799. auto& opdef = reinterpret_cast<PyOp(GetVarShape)*>(self)->inst();
  8800. static_cast<void>(opdef);
  8801. std::unordered_map<std::string, py::object> state {
  8802. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  8803. };
  8804. return py::cast(state).release().ptr();
  8805. }
  8806. static PyObject* setstate(PyObject* self, PyObject* args) {
  8807. PyObject* dict = PyTuple_GetItem(args, 0);
  8808. if (!dict) return NULL;
  8809. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8810. auto& opdef = reinterpret_cast<PyOp(GetVarShape)*>(self)->inst();
  8811. static_cast<void>(opdef);
  8812. {
  8813. auto&& iter = state.find("axis");
  8814. if (iter != state.end()) {
  8815. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  8816. }
  8817. }
  8818. Py_RETURN_NONE;
  8819. }
  8820. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8821. // };
  8822. PyOpDefEnd(GetVarShape)
  8823. int PyOp(GetVarShape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8824. static const char* kwlist[] = {"axis", "scope", NULL};
  8825. PyObject *axis = NULL, *scope = NULL;
  8826. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  8827. return -1;
  8828. if (axis) {
  8829. try {
  8830. // TODO: remove this guard which is used for pybind11 implicit conversion
  8831. py::detail::loader_life_support guard{};
  8832. reinterpret_cast<PyOp(GetVarShape)*>(self)->inst().axis =
  8833. py::cast<decltype(GetVarShape::axis)>(py::handle(axis));
  8834. } CATCH_ALL(-1)
  8835. }
  8836. if (scope) {
  8837. try {
  8838. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8839. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8840. } CATCH_ALL(-1)
  8841. }
  8842. return 0;
  8843. }
  8844. PyGetSetDef PyOp(GetVarShape)::py_getsetters[] = {
  8845. {const_cast<char*>("axis"), py_get_generic(GetVarShape, axis), py_set_generic(GetVarShape, axis), const_cast<char*>("axis"), NULL},
  8846. {NULL} /* Sentinel */
  8847. };
  8848. PyMethodDef PyOp(GetVarShape)::tp_methods[] = {
  8849. {const_cast<char*>("__getstate__"), PyOp(GetVarShape)::getstate, METH_NOARGS, "GetVarShape getstate"},
  8850. {const_cast<char*>("__setstate__"), PyOp(GetVarShape)::setstate, METH_VARARGS, "GetVarShape setstate"},
  8851. {NULL} /* Sentinel */
  8852. };
  8853. void _init_py_GetVarShape(py::module m) {
  8854. using py_op = PyOp(GetVarShape);
  8855. auto& py_type = PyOpType(GetVarShape);
  8856. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8857. py_type.tp_name = "megengine.core._imperative_rt.ops.GetVarShape";
  8858. py_type.tp_basicsize = sizeof(PyOp(GetVarShape));
  8859. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8860. py_type.tp_doc = "GetVarShape";
  8861. py_type.tp_base = &PyOpType(OpDef);
  8862. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8863. py_type.tp_new = py_new_generic<py_op>;
  8864. py_type.tp_init = py_op::py_init;
  8865. py_type.tp_methods = py_op::tp_methods;
  8866. py_type.tp_getset = py_op::py_getsetters;
  8867. mgb_assert(PyType_Ready(&py_type) >= 0);
  8868. PyType_Modified(&py_type);
  8869. m.add_object("GetVarShape", reinterpret_cast<PyObject*>(&py_type));
  8870. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GetVarShape::typeinfo(), &py_type).second);
  8871. }
  8872. void _init_py_GroupLocal_Mode(PyTypeObject& py_type) {
  8873. auto& e_type = EnumWrapper<GroupLocal::Mode>::type;
  8874. Py_INCREF(e_type);
  8875. mgb_assert(PyDict_SetItemString(
  8876. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8877. }
  8878. void _init_py_GroupLocal_Sparse(PyTypeObject& py_type) {
  8879. auto& e_type = EnumWrapper<GroupLocal::Sparse>::type;
  8880. Py_INCREF(e_type);
  8881. mgb_assert(PyDict_SetItemString(
  8882. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8883. }
  8884. void _init_py_GroupLocal_Format(PyTypeObject& py_type) {
  8885. auto& e_type = EnumWrapper<GroupLocal::Format>::type;
  8886. Py_INCREF(e_type);
  8887. mgb_assert(PyDict_SetItemString(
  8888. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8889. }
  8890. void _init_py_GroupLocal_ComputeMode(PyTypeObject& py_type) {
  8891. auto& e_type = EnumWrapper<GroupLocal::ComputeMode>::type;
  8892. Py_INCREF(e_type);
  8893. mgb_assert(PyDict_SetItemString(
  8894. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8895. }
  8896. PyOpDefBegin(GroupLocal) // {
  8897. static PyGetSetDef py_getsetters[];
  8898. static PyMethodDef tp_methods[];
  8899. static PyObject* getstate(PyObject* self, PyObject*) {
  8900. auto& opdef = reinterpret_cast<PyOp(GroupLocal)*>(self)->inst();
  8901. static_cast<void>(opdef);
  8902. std::unordered_map<std::string, py::object> state {
  8903. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  8904. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  8905. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  8906. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  8907. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  8908. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  8909. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  8910. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  8911. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  8912. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)}
  8913. };
  8914. return py::cast(state).release().ptr();
  8915. }
  8916. static PyObject* setstate(PyObject* self, PyObject* args) {
  8917. PyObject* dict = PyTuple_GetItem(args, 0);
  8918. if (!dict) return NULL;
  8919. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8920. auto& opdef = reinterpret_cast<PyOp(GroupLocal)*>(self)->inst();
  8921. static_cast<void>(opdef);
  8922. {
  8923. auto&& iter = state.find("mode");
  8924. if (iter != state.end()) {
  8925. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  8926. }
  8927. }
  8928. {
  8929. auto&& iter = state.find("pad_h");
  8930. if (iter != state.end()) {
  8931. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  8932. }
  8933. }
  8934. {
  8935. auto&& iter = state.find("pad_w");
  8936. if (iter != state.end()) {
  8937. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  8938. }
  8939. }
  8940. {
  8941. auto&& iter = state.find("stride_h");
  8942. if (iter != state.end()) {
  8943. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  8944. }
  8945. }
  8946. {
  8947. auto&& iter = state.find("stride_w");
  8948. if (iter != state.end()) {
  8949. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  8950. }
  8951. }
  8952. {
  8953. auto&& iter = state.find("dilate_h");
  8954. if (iter != state.end()) {
  8955. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  8956. }
  8957. }
  8958. {
  8959. auto&& iter = state.find("dilate_w");
  8960. if (iter != state.end()) {
  8961. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  8962. }
  8963. }
  8964. {
  8965. auto&& iter = state.find("sparse");
  8966. if (iter != state.end()) {
  8967. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  8968. }
  8969. }
  8970. {
  8971. auto&& iter = state.find("format");
  8972. if (iter != state.end()) {
  8973. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  8974. }
  8975. }
  8976. {
  8977. auto&& iter = state.find("compute_mode");
  8978. if (iter != state.end()) {
  8979. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  8980. }
  8981. }
  8982. Py_RETURN_NONE;
  8983. }
  8984. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8985. // };
  8986. PyOpDefEnd(GroupLocal)
  8987. int PyOp(GroupLocal)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8988. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL};
  8989. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *scope = NULL;
  8990. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &scope))
  8991. return -1;
  8992. if (mode) {
  8993. try {
  8994. // TODO: remove this guard which is used for pybind11 implicit conversion
  8995. py::detail::loader_life_support guard{};
  8996. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().mode =
  8997. py::cast<decltype(GroupLocal::mode)>(py::handle(mode));
  8998. } CATCH_ALL(-1)
  8999. }
  9000. if (pad_h) {
  9001. try {
  9002. // TODO: remove this guard which is used for pybind11 implicit conversion
  9003. py::detail::loader_life_support guard{};
  9004. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().pad_h =
  9005. py::cast<decltype(GroupLocal::pad_h)>(py::handle(pad_h));
  9006. } CATCH_ALL(-1)
  9007. }
  9008. if (pad_w) {
  9009. try {
  9010. // TODO: remove this guard which is used for pybind11 implicit conversion
  9011. py::detail::loader_life_support guard{};
  9012. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().pad_w =
  9013. py::cast<decltype(GroupLocal::pad_w)>(py::handle(pad_w));
  9014. } CATCH_ALL(-1)
  9015. }
  9016. if (stride_h) {
  9017. try {
  9018. // TODO: remove this guard which is used for pybind11 implicit conversion
  9019. py::detail::loader_life_support guard{};
  9020. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().stride_h =
  9021. py::cast<decltype(GroupLocal::stride_h)>(py::handle(stride_h));
  9022. } CATCH_ALL(-1)
  9023. }
  9024. if (stride_w) {
  9025. try {
  9026. // TODO: remove this guard which is used for pybind11 implicit conversion
  9027. py::detail::loader_life_support guard{};
  9028. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().stride_w =
  9029. py::cast<decltype(GroupLocal::stride_w)>(py::handle(stride_w));
  9030. } CATCH_ALL(-1)
  9031. }
  9032. if (dilate_h) {
  9033. try {
  9034. // TODO: remove this guard which is used for pybind11 implicit conversion
  9035. py::detail::loader_life_support guard{};
  9036. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().dilate_h =
  9037. py::cast<decltype(GroupLocal::dilate_h)>(py::handle(dilate_h));
  9038. } CATCH_ALL(-1)
  9039. }
  9040. if (dilate_w) {
  9041. try {
  9042. // TODO: remove this guard which is used for pybind11 implicit conversion
  9043. py::detail::loader_life_support guard{};
  9044. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().dilate_w =
  9045. py::cast<decltype(GroupLocal::dilate_w)>(py::handle(dilate_w));
  9046. } CATCH_ALL(-1)
  9047. }
  9048. if (sparse) {
  9049. try {
  9050. // TODO: remove this guard which is used for pybind11 implicit conversion
  9051. py::detail::loader_life_support guard{};
  9052. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().sparse =
  9053. py::cast<decltype(GroupLocal::sparse)>(py::handle(sparse));
  9054. } CATCH_ALL(-1)
  9055. }
  9056. if (format) {
  9057. try {
  9058. // TODO: remove this guard which is used for pybind11 implicit conversion
  9059. py::detail::loader_life_support guard{};
  9060. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().format =
  9061. py::cast<decltype(GroupLocal::format)>(py::handle(format));
  9062. } CATCH_ALL(-1)
  9063. }
  9064. if (compute_mode) {
  9065. try {
  9066. // TODO: remove this guard which is used for pybind11 implicit conversion
  9067. py::detail::loader_life_support guard{};
  9068. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().compute_mode =
  9069. py::cast<decltype(GroupLocal::compute_mode)>(py::handle(compute_mode));
  9070. } CATCH_ALL(-1)
  9071. }
  9072. if (scope) {
  9073. try {
  9074. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9075. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9076. } CATCH_ALL(-1)
  9077. }
  9078. return 0;
  9079. }
  9080. PyGetSetDef PyOp(GroupLocal)::py_getsetters[] = {
  9081. {const_cast<char*>("mode"), py_get_generic(GroupLocal, mode), py_set_generic(GroupLocal, mode), const_cast<char*>("mode"), NULL},
  9082. {const_cast<char*>("pad_h"), py_get_generic(GroupLocal, pad_h), py_set_generic(GroupLocal, pad_h), const_cast<char*>("pad_h"), NULL},
  9083. {const_cast<char*>("pad_w"), py_get_generic(GroupLocal, pad_w), py_set_generic(GroupLocal, pad_w), const_cast<char*>("pad_w"), NULL},
  9084. {const_cast<char*>("stride_h"), py_get_generic(GroupLocal, stride_h), py_set_generic(GroupLocal, stride_h), const_cast<char*>("stride_h"), NULL},
  9085. {const_cast<char*>("stride_w"), py_get_generic(GroupLocal, stride_w), py_set_generic(GroupLocal, stride_w), const_cast<char*>("stride_w"), NULL},
  9086. {const_cast<char*>("dilate_h"), py_get_generic(GroupLocal, dilate_h), py_set_generic(GroupLocal, dilate_h), const_cast<char*>("dilate_h"), NULL},
  9087. {const_cast<char*>("dilate_w"), py_get_generic(GroupLocal, dilate_w), py_set_generic(GroupLocal, dilate_w), const_cast<char*>("dilate_w"), NULL},
  9088. {const_cast<char*>("sparse"), py_get_generic(GroupLocal, sparse), py_set_generic(GroupLocal, sparse), const_cast<char*>("sparse"), NULL},
  9089. {const_cast<char*>("format"), py_get_generic(GroupLocal, format), py_set_generic(GroupLocal, format), const_cast<char*>("format"), NULL},
  9090. {const_cast<char*>("compute_mode"), py_get_generic(GroupLocal, compute_mode), py_set_generic(GroupLocal, compute_mode), const_cast<char*>("compute_mode"), NULL},
  9091. {NULL} /* Sentinel */
  9092. };
  9093. PyMethodDef PyOp(GroupLocal)::tp_methods[] = {
  9094. {const_cast<char*>("__getstate__"), PyOp(GroupLocal)::getstate, METH_NOARGS, "GroupLocal getstate"},
  9095. {const_cast<char*>("__setstate__"), PyOp(GroupLocal)::setstate, METH_VARARGS, "GroupLocal setstate"},
  9096. {NULL} /* Sentinel */
  9097. };
  9098. void _init_py_GroupLocal(py::module m) {
  9099. using py_op = PyOp(GroupLocal);
  9100. auto& py_type = PyOpType(GroupLocal);
  9101. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9102. py_type.tp_name = "megengine.core._imperative_rt.ops.GroupLocal";
  9103. py_type.tp_basicsize = sizeof(PyOp(GroupLocal));
  9104. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9105. py_type.tp_doc = "GroupLocal";
  9106. py_type.tp_base = &PyOpType(OpDef);
  9107. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9108. py_type.tp_new = py_new_generic<py_op>;
  9109. py_type.tp_init = py_op::py_init;
  9110. py_type.tp_methods = py_op::tp_methods;
  9111. py_type.tp_getset = py_op::py_getsetters;
  9112. mgb_assert(PyType_Ready(&py_type) >= 0);
  9113. _init_py_GroupLocal_Mode(py_type);
  9114. _init_py_GroupLocal_Sparse(py_type);
  9115. _init_py_GroupLocal_Format(py_type);
  9116. _init_py_GroupLocal_ComputeMode(py_type);
  9117. PyType_Modified(&py_type);
  9118. m.add_object("GroupLocal", reinterpret_cast<PyObject*>(&py_type));
  9119. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GroupLocal::typeinfo(), &py_type).second);
  9120. }
  9121. PyOpDefBegin(Identity) // {
  9122. static PyGetSetDef py_getsetters[];
  9123. static PyMethodDef tp_methods[];
  9124. static PyObject* getstate(PyObject* self, PyObject*) {
  9125. auto& opdef = reinterpret_cast<PyOp(Identity)*>(self)->inst();
  9126. static_cast<void>(opdef);
  9127. std::unordered_map<std::string, py::object> state {
  9128. };
  9129. return py::cast(state).release().ptr();
  9130. }
  9131. static PyObject* setstate(PyObject* self, PyObject* args) {
  9132. PyObject* dict = PyTuple_GetItem(args, 0);
  9133. if (!dict) return NULL;
  9134. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9135. auto& opdef = reinterpret_cast<PyOp(Identity)*>(self)->inst();
  9136. static_cast<void>(opdef);
  9137. Py_RETURN_NONE;
  9138. }
  9139. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9140. // };
  9141. PyOpDefEnd(Identity)
  9142. int PyOp(Identity)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9143. return 0;
  9144. }
  9145. PyGetSetDef PyOp(Identity)::py_getsetters[] = {
  9146. {NULL} /* Sentinel */
  9147. };
  9148. PyMethodDef PyOp(Identity)::tp_methods[] = {
  9149. {const_cast<char*>("__getstate__"), PyOp(Identity)::getstate, METH_NOARGS, "Identity getstate"},
  9150. {const_cast<char*>("__setstate__"), PyOp(Identity)::setstate, METH_VARARGS, "Identity setstate"},
  9151. {NULL} /* Sentinel */
  9152. };
  9153. void _init_py_Identity(py::module m) {
  9154. using py_op = PyOp(Identity);
  9155. auto& py_type = PyOpType(Identity);
  9156. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9157. py_type.tp_name = "megengine.core._imperative_rt.ops.Identity";
  9158. py_type.tp_basicsize = sizeof(PyOp(Identity));
  9159. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9160. py_type.tp_doc = "Identity";
  9161. py_type.tp_base = &PyOpType(OpDef);
  9162. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9163. py_type.tp_new = py_new_generic<py_op>;
  9164. py_type.tp_init = py_op::py_init;
  9165. py_type.tp_methods = py_op::tp_methods;
  9166. py_type.tp_getset = py_op::py_getsetters;
  9167. mgb_assert(PyType_Ready(&py_type) >= 0);
  9168. PyType_Modified(&py_type);
  9169. m.add_object("Identity", reinterpret_cast<PyObject*>(&py_type));
  9170. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Identity::typeinfo(), &py_type).second);
  9171. }
  9172. PyOpDefBegin(Images2Neibs) // {
  9173. static PyGetSetDef py_getsetters[];
  9174. static PyMethodDef tp_methods[];
  9175. static PyObject* getstate(PyObject* self, PyObject*) {
  9176. auto& opdef = reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst();
  9177. static_cast<void>(opdef);
  9178. std::unordered_map<std::string, py::object> state {
  9179. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  9180. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  9181. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  9182. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  9183. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  9184. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  9185. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  9186. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)}
  9187. };
  9188. return py::cast(state).release().ptr();
  9189. }
  9190. static PyObject* setstate(PyObject* self, PyObject* args) {
  9191. PyObject* dict = PyTuple_GetItem(args, 0);
  9192. if (!dict) return NULL;
  9193. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9194. auto& opdef = reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst();
  9195. static_cast<void>(opdef);
  9196. {
  9197. auto&& iter = state.find("pad_h");
  9198. if (iter != state.end()) {
  9199. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  9200. }
  9201. }
  9202. {
  9203. auto&& iter = state.find("pad_w");
  9204. if (iter != state.end()) {
  9205. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  9206. }
  9207. }
  9208. {
  9209. auto&& iter = state.find("stride_h");
  9210. if (iter != state.end()) {
  9211. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  9212. }
  9213. }
  9214. {
  9215. auto&& iter = state.find("stride_w");
  9216. if (iter != state.end()) {
  9217. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  9218. }
  9219. }
  9220. {
  9221. auto&& iter = state.find("dilate_h");
  9222. if (iter != state.end()) {
  9223. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  9224. }
  9225. }
  9226. {
  9227. auto&& iter = state.find("dilate_w");
  9228. if (iter != state.end()) {
  9229. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  9230. }
  9231. }
  9232. {
  9233. auto&& iter = state.find("window_h");
  9234. if (iter != state.end()) {
  9235. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  9236. }
  9237. }
  9238. {
  9239. auto&& iter = state.find("window_w");
  9240. if (iter != state.end()) {
  9241. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  9242. }
  9243. }
  9244. Py_RETURN_NONE;
  9245. }
  9246. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9247. // };
  9248. PyOpDefEnd(Images2Neibs)
  9249. int PyOp(Images2Neibs)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9250. static const char* kwlist[] = {"pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "window_h", "window_w", "scope", NULL};
  9251. PyObject *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *window_h = NULL, *window_w = NULL, *scope = NULL;
  9252. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &window_h, &window_w, &scope))
  9253. return -1;
  9254. if (pad_h) {
  9255. try {
  9256. // TODO: remove this guard which is used for pybind11 implicit conversion
  9257. py::detail::loader_life_support guard{};
  9258. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().pad_h =
  9259. py::cast<decltype(Images2Neibs::pad_h)>(py::handle(pad_h));
  9260. } CATCH_ALL(-1)
  9261. }
  9262. if (pad_w) {
  9263. try {
  9264. // TODO: remove this guard which is used for pybind11 implicit conversion
  9265. py::detail::loader_life_support guard{};
  9266. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().pad_w =
  9267. py::cast<decltype(Images2Neibs::pad_w)>(py::handle(pad_w));
  9268. } CATCH_ALL(-1)
  9269. }
  9270. if (stride_h) {
  9271. try {
  9272. // TODO: remove this guard which is used for pybind11 implicit conversion
  9273. py::detail::loader_life_support guard{};
  9274. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().stride_h =
  9275. py::cast<decltype(Images2Neibs::stride_h)>(py::handle(stride_h));
  9276. } CATCH_ALL(-1)
  9277. }
  9278. if (stride_w) {
  9279. try {
  9280. // TODO: remove this guard which is used for pybind11 implicit conversion
  9281. py::detail::loader_life_support guard{};
  9282. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().stride_w =
  9283. py::cast<decltype(Images2Neibs::stride_w)>(py::handle(stride_w));
  9284. } CATCH_ALL(-1)
  9285. }
  9286. if (dilate_h) {
  9287. try {
  9288. // TODO: remove this guard which is used for pybind11 implicit conversion
  9289. py::detail::loader_life_support guard{};
  9290. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().dilate_h =
  9291. py::cast<decltype(Images2Neibs::dilate_h)>(py::handle(dilate_h));
  9292. } CATCH_ALL(-1)
  9293. }
  9294. if (dilate_w) {
  9295. try {
  9296. // TODO: remove this guard which is used for pybind11 implicit conversion
  9297. py::detail::loader_life_support guard{};
  9298. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().dilate_w =
  9299. py::cast<decltype(Images2Neibs::dilate_w)>(py::handle(dilate_w));
  9300. } CATCH_ALL(-1)
  9301. }
  9302. if (window_h) {
  9303. try {
  9304. // TODO: remove this guard which is used for pybind11 implicit conversion
  9305. py::detail::loader_life_support guard{};
  9306. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().window_h =
  9307. py::cast<decltype(Images2Neibs::window_h)>(py::handle(window_h));
  9308. } CATCH_ALL(-1)
  9309. }
  9310. if (window_w) {
  9311. try {
  9312. // TODO: remove this guard which is used for pybind11 implicit conversion
  9313. py::detail::loader_life_support guard{};
  9314. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().window_w =
  9315. py::cast<decltype(Images2Neibs::window_w)>(py::handle(window_w));
  9316. } CATCH_ALL(-1)
  9317. }
  9318. if (scope) {
  9319. try {
  9320. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9321. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9322. } CATCH_ALL(-1)
  9323. }
  9324. return 0;
  9325. }
  9326. PyGetSetDef PyOp(Images2Neibs)::py_getsetters[] = {
  9327. {const_cast<char*>("pad_h"), py_get_generic(Images2Neibs, pad_h), py_set_generic(Images2Neibs, pad_h), const_cast<char*>("pad_h"), NULL},
  9328. {const_cast<char*>("pad_w"), py_get_generic(Images2Neibs, pad_w), py_set_generic(Images2Neibs, pad_w), const_cast<char*>("pad_w"), NULL},
  9329. {const_cast<char*>("stride_h"), py_get_generic(Images2Neibs, stride_h), py_set_generic(Images2Neibs, stride_h), const_cast<char*>("stride_h"), NULL},
  9330. {const_cast<char*>("stride_w"), py_get_generic(Images2Neibs, stride_w), py_set_generic(Images2Neibs, stride_w), const_cast<char*>("stride_w"), NULL},
  9331. {const_cast<char*>("dilate_h"), py_get_generic(Images2Neibs, dilate_h), py_set_generic(Images2Neibs, dilate_h), const_cast<char*>("dilate_h"), NULL},
  9332. {const_cast<char*>("dilate_w"), py_get_generic(Images2Neibs, dilate_w), py_set_generic(Images2Neibs, dilate_w), const_cast<char*>("dilate_w"), NULL},
  9333. {const_cast<char*>("window_h"), py_get_generic(Images2Neibs, window_h), py_set_generic(Images2Neibs, window_h), const_cast<char*>("window_h"), NULL},
  9334. {const_cast<char*>("window_w"), py_get_generic(Images2Neibs, window_w), py_set_generic(Images2Neibs, window_w), const_cast<char*>("window_w"), NULL},
  9335. {NULL} /* Sentinel */
  9336. };
  9337. PyMethodDef PyOp(Images2Neibs)::tp_methods[] = {
  9338. {const_cast<char*>("__getstate__"), PyOp(Images2Neibs)::getstate, METH_NOARGS, "Images2Neibs getstate"},
  9339. {const_cast<char*>("__setstate__"), PyOp(Images2Neibs)::setstate, METH_VARARGS, "Images2Neibs setstate"},
  9340. {NULL} /* Sentinel */
  9341. };
  9342. void _init_py_Images2Neibs(py::module m) {
  9343. using py_op = PyOp(Images2Neibs);
  9344. auto& py_type = PyOpType(Images2Neibs);
  9345. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9346. py_type.tp_name = "megengine.core._imperative_rt.ops.Images2Neibs";
  9347. py_type.tp_basicsize = sizeof(PyOp(Images2Neibs));
  9348. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9349. py_type.tp_doc = "Images2Neibs";
  9350. py_type.tp_base = &PyOpType(OpDef);
  9351. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9352. py_type.tp_new = py_new_generic<py_op>;
  9353. py_type.tp_init = py_op::py_init;
  9354. py_type.tp_methods = py_op::tp_methods;
  9355. py_type.tp_getset = py_op::py_getsetters;
  9356. mgb_assert(PyType_Ready(&py_type) >= 0);
  9357. PyType_Modified(&py_type);
  9358. m.add_object("Images2Neibs", reinterpret_cast<PyObject*>(&py_type));
  9359. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Images2Neibs::typeinfo(), &py_type).second);
  9360. }
  9361. PyOpDefBegin(IncrMeshIndexing) // {
  9362. static PyGetSetDef py_getsetters[];
  9363. static PyMethodDef tp_methods[];
  9364. static PyObject* getstate(PyObject* self, PyObject*) {
  9365. auto& opdef = reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst();
  9366. static_cast<void>(opdef);
  9367. std::unordered_map<std::string, py::object> state {
  9368. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9369. };
  9370. return py::cast(state).release().ptr();
  9371. }
  9372. static PyObject* setstate(PyObject* self, PyObject* args) {
  9373. PyObject* dict = PyTuple_GetItem(args, 0);
  9374. if (!dict) return NULL;
  9375. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9376. auto& opdef = reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst();
  9377. static_cast<void>(opdef);
  9378. {
  9379. auto&& iter = state.find("items");
  9380. if (iter != state.end()) {
  9381. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9382. }
  9383. }
  9384. Py_RETURN_NONE;
  9385. }
  9386. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9387. // };
  9388. PyOpDefEnd(IncrMeshIndexing)
  9389. int PyOp(IncrMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9390. static const char* kwlist[] = {"items", "scope", NULL};
  9391. PyObject *items = NULL, *scope = NULL;
  9392. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9393. return -1;
  9394. if (items) {
  9395. try {
  9396. // TODO: remove this guard which is used for pybind11 implicit conversion
  9397. py::detail::loader_life_support guard{};
  9398. reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst().items =
  9399. py::cast<decltype(IncrMeshIndexing::items)>(py::handle(items));
  9400. } CATCH_ALL(-1)
  9401. }
  9402. if (scope) {
  9403. try {
  9404. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9405. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9406. } CATCH_ALL(-1)
  9407. }
  9408. return 0;
  9409. }
  9410. PyGetSetDef PyOp(IncrMeshIndexing)::py_getsetters[] = {
  9411. {const_cast<char*>("items"), py_get_generic(IncrMeshIndexing, items), py_set_generic(IncrMeshIndexing, items), const_cast<char*>("items"), NULL},
  9412. {NULL} /* Sentinel */
  9413. };
  9414. PyMethodDef PyOp(IncrMeshIndexing)::tp_methods[] = {
  9415. {const_cast<char*>("__getstate__"), PyOp(IncrMeshIndexing)::getstate, METH_NOARGS, "IncrMeshIndexing getstate"},
  9416. {const_cast<char*>("__setstate__"), PyOp(IncrMeshIndexing)::setstate, METH_VARARGS, "IncrMeshIndexing setstate"},
  9417. {NULL} /* Sentinel */
  9418. };
  9419. void _init_py_IncrMeshIndexing(py::module m) {
  9420. using py_op = PyOp(IncrMeshIndexing);
  9421. auto& py_type = PyOpType(IncrMeshIndexing);
  9422. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9423. py_type.tp_name = "megengine.core._imperative_rt.ops.IncrMeshIndexing";
  9424. py_type.tp_basicsize = sizeof(PyOp(IncrMeshIndexing));
  9425. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9426. py_type.tp_doc = "IncrMeshIndexing";
  9427. py_type.tp_base = &PyOpType(OpDef);
  9428. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9429. py_type.tp_new = py_new_generic<py_op>;
  9430. py_type.tp_init = py_op::py_init;
  9431. py_type.tp_methods = py_op::tp_methods;
  9432. py_type.tp_getset = py_op::py_getsetters;
  9433. mgb_assert(PyType_Ready(&py_type) >= 0);
  9434. PyType_Modified(&py_type);
  9435. m.add_object("IncrMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  9436. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrMeshIndexing::typeinfo(), &py_type).second);
  9437. }
  9438. PyOpDefBegin(IncrSubtensor) // {
  9439. static PyGetSetDef py_getsetters[];
  9440. static PyMethodDef tp_methods[];
  9441. static PyObject* getstate(PyObject* self, PyObject*) {
  9442. auto& opdef = reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst();
  9443. static_cast<void>(opdef);
  9444. std::unordered_map<std::string, py::object> state {
  9445. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9446. };
  9447. return py::cast(state).release().ptr();
  9448. }
  9449. static PyObject* setstate(PyObject* self, PyObject* args) {
  9450. PyObject* dict = PyTuple_GetItem(args, 0);
  9451. if (!dict) return NULL;
  9452. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9453. auto& opdef = reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst();
  9454. static_cast<void>(opdef);
  9455. {
  9456. auto&& iter = state.find("items");
  9457. if (iter != state.end()) {
  9458. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9459. }
  9460. }
  9461. Py_RETURN_NONE;
  9462. }
  9463. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9464. // };
  9465. PyOpDefEnd(IncrSubtensor)
  9466. int PyOp(IncrSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9467. static const char* kwlist[] = {"items", "scope", NULL};
  9468. PyObject *items = NULL, *scope = NULL;
  9469. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9470. return -1;
  9471. if (items) {
  9472. try {
  9473. // TODO: remove this guard which is used for pybind11 implicit conversion
  9474. py::detail::loader_life_support guard{};
  9475. reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst().items =
  9476. py::cast<decltype(IncrSubtensor::items)>(py::handle(items));
  9477. } CATCH_ALL(-1)
  9478. }
  9479. if (scope) {
  9480. try {
  9481. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9482. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9483. } CATCH_ALL(-1)
  9484. }
  9485. return 0;
  9486. }
  9487. PyGetSetDef PyOp(IncrSubtensor)::py_getsetters[] = {
  9488. {const_cast<char*>("items"), py_get_generic(IncrSubtensor, items), py_set_generic(IncrSubtensor, items), const_cast<char*>("items"), NULL},
  9489. {NULL} /* Sentinel */
  9490. };
  9491. PyMethodDef PyOp(IncrSubtensor)::tp_methods[] = {
  9492. {const_cast<char*>("__getstate__"), PyOp(IncrSubtensor)::getstate, METH_NOARGS, "IncrSubtensor getstate"},
  9493. {const_cast<char*>("__setstate__"), PyOp(IncrSubtensor)::setstate, METH_VARARGS, "IncrSubtensor setstate"},
  9494. {NULL} /* Sentinel */
  9495. };
  9496. void _init_py_IncrSubtensor(py::module m) {
  9497. using py_op = PyOp(IncrSubtensor);
  9498. auto& py_type = PyOpType(IncrSubtensor);
  9499. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9500. py_type.tp_name = "megengine.core._imperative_rt.ops.IncrSubtensor";
  9501. py_type.tp_basicsize = sizeof(PyOp(IncrSubtensor));
  9502. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9503. py_type.tp_doc = "IncrSubtensor";
  9504. py_type.tp_base = &PyOpType(OpDef);
  9505. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9506. py_type.tp_new = py_new_generic<py_op>;
  9507. py_type.tp_init = py_op::py_init;
  9508. py_type.tp_methods = py_op::tp_methods;
  9509. py_type.tp_getset = py_op::py_getsetters;
  9510. mgb_assert(PyType_Ready(&py_type) >= 0);
  9511. PyType_Modified(&py_type);
  9512. m.add_object("IncrSubtensor", reinterpret_cast<PyObject*>(&py_type));
  9513. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrSubtensor::typeinfo(), &py_type).second);
  9514. }
  9515. PyOpDefBegin(IndexingIncrMultiAxisVec) // {
  9516. static PyGetSetDef py_getsetters[];
  9517. static PyMethodDef tp_methods[];
  9518. static PyObject* getstate(PyObject* self, PyObject*) {
  9519. auto& opdef = reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst();
  9520. static_cast<void>(opdef);
  9521. std::unordered_map<std::string, py::object> state {
  9522. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9523. };
  9524. return py::cast(state).release().ptr();
  9525. }
  9526. static PyObject* setstate(PyObject* self, PyObject* args) {
  9527. PyObject* dict = PyTuple_GetItem(args, 0);
  9528. if (!dict) return NULL;
  9529. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9530. auto& opdef = reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst();
  9531. static_cast<void>(opdef);
  9532. {
  9533. auto&& iter = state.find("items");
  9534. if (iter != state.end()) {
  9535. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9536. }
  9537. }
  9538. Py_RETURN_NONE;
  9539. }
  9540. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9541. // };
  9542. PyOpDefEnd(IndexingIncrMultiAxisVec)
  9543. int PyOp(IndexingIncrMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9544. static const char* kwlist[] = {"items", "scope", NULL};
  9545. PyObject *items = NULL, *scope = NULL;
  9546. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9547. return -1;
  9548. if (items) {
  9549. try {
  9550. // TODO: remove this guard which is used for pybind11 implicit conversion
  9551. py::detail::loader_life_support guard{};
  9552. reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst().items =
  9553. py::cast<decltype(IndexingIncrMultiAxisVec::items)>(py::handle(items));
  9554. } CATCH_ALL(-1)
  9555. }
  9556. if (scope) {
  9557. try {
  9558. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9559. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9560. } CATCH_ALL(-1)
  9561. }
  9562. return 0;
  9563. }
  9564. PyGetSetDef PyOp(IndexingIncrMultiAxisVec)::py_getsetters[] = {
  9565. {const_cast<char*>("items"), py_get_generic(IndexingIncrMultiAxisVec, items), py_set_generic(IndexingIncrMultiAxisVec, items), const_cast<char*>("items"), NULL},
  9566. {NULL} /* Sentinel */
  9567. };
  9568. PyMethodDef PyOp(IndexingIncrMultiAxisVec)::tp_methods[] = {
  9569. {const_cast<char*>("__getstate__"), PyOp(IndexingIncrMultiAxisVec)::getstate, METH_NOARGS, "IndexingIncrMultiAxisVec getstate"},
  9570. {const_cast<char*>("__setstate__"), PyOp(IndexingIncrMultiAxisVec)::setstate, METH_VARARGS, "IndexingIncrMultiAxisVec setstate"},
  9571. {NULL} /* Sentinel */
  9572. };
  9573. void _init_py_IndexingIncrMultiAxisVec(py::module m) {
  9574. using py_op = PyOp(IndexingIncrMultiAxisVec);
  9575. auto& py_type = PyOpType(IndexingIncrMultiAxisVec);
  9576. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9577. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingIncrMultiAxisVec";
  9578. py_type.tp_basicsize = sizeof(PyOp(IndexingIncrMultiAxisVec));
  9579. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9580. py_type.tp_doc = "IndexingIncrMultiAxisVec";
  9581. py_type.tp_base = &PyOpType(OpDef);
  9582. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9583. py_type.tp_new = py_new_generic<py_op>;
  9584. py_type.tp_init = py_op::py_init;
  9585. py_type.tp_methods = py_op::tp_methods;
  9586. py_type.tp_getset = py_op::py_getsetters;
  9587. mgb_assert(PyType_Ready(&py_type) >= 0);
  9588. PyType_Modified(&py_type);
  9589. m.add_object("IndexingIncrMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  9590. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingIncrMultiAxisVec::typeinfo(), &py_type).second);
  9591. }
  9592. PyOpDefBegin(IndexingMultiAxisVec) // {
  9593. static PyGetSetDef py_getsetters[];
  9594. static PyMethodDef tp_methods[];
  9595. static PyObject* getstate(PyObject* self, PyObject*) {
  9596. auto& opdef = reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst();
  9597. static_cast<void>(opdef);
  9598. std::unordered_map<std::string, py::object> state {
  9599. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9600. };
  9601. return py::cast(state).release().ptr();
  9602. }
  9603. static PyObject* setstate(PyObject* self, PyObject* args) {
  9604. PyObject* dict = PyTuple_GetItem(args, 0);
  9605. if (!dict) return NULL;
  9606. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9607. auto& opdef = reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst();
  9608. static_cast<void>(opdef);
  9609. {
  9610. auto&& iter = state.find("items");
  9611. if (iter != state.end()) {
  9612. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9613. }
  9614. }
  9615. Py_RETURN_NONE;
  9616. }
  9617. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9618. // };
  9619. PyOpDefEnd(IndexingMultiAxisVec)
  9620. int PyOp(IndexingMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9621. static const char* kwlist[] = {"items", "scope", NULL};
  9622. PyObject *items = NULL, *scope = NULL;
  9623. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9624. return -1;
  9625. if (items) {
  9626. try {
  9627. // TODO: remove this guard which is used for pybind11 implicit conversion
  9628. py::detail::loader_life_support guard{};
  9629. reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst().items =
  9630. py::cast<decltype(IndexingMultiAxisVec::items)>(py::handle(items));
  9631. } CATCH_ALL(-1)
  9632. }
  9633. if (scope) {
  9634. try {
  9635. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9636. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9637. } CATCH_ALL(-1)
  9638. }
  9639. return 0;
  9640. }
  9641. PyGetSetDef PyOp(IndexingMultiAxisVec)::py_getsetters[] = {
  9642. {const_cast<char*>("items"), py_get_generic(IndexingMultiAxisVec, items), py_set_generic(IndexingMultiAxisVec, items), const_cast<char*>("items"), NULL},
  9643. {NULL} /* Sentinel */
  9644. };
  9645. PyMethodDef PyOp(IndexingMultiAxisVec)::tp_methods[] = {
  9646. {const_cast<char*>("__getstate__"), PyOp(IndexingMultiAxisVec)::getstate, METH_NOARGS, "IndexingMultiAxisVec getstate"},
  9647. {const_cast<char*>("__setstate__"), PyOp(IndexingMultiAxisVec)::setstate, METH_VARARGS, "IndexingMultiAxisVec setstate"},
  9648. {NULL} /* Sentinel */
  9649. };
  9650. void _init_py_IndexingMultiAxisVec(py::module m) {
  9651. using py_op = PyOp(IndexingMultiAxisVec);
  9652. auto& py_type = PyOpType(IndexingMultiAxisVec);
  9653. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9654. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingMultiAxisVec";
  9655. py_type.tp_basicsize = sizeof(PyOp(IndexingMultiAxisVec));
  9656. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9657. py_type.tp_doc = "IndexingMultiAxisVec";
  9658. py_type.tp_base = &PyOpType(OpDef);
  9659. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9660. py_type.tp_new = py_new_generic<py_op>;
  9661. py_type.tp_init = py_op::py_init;
  9662. py_type.tp_methods = py_op::tp_methods;
  9663. py_type.tp_getset = py_op::py_getsetters;
  9664. mgb_assert(PyType_Ready(&py_type) >= 0);
  9665. PyType_Modified(&py_type);
  9666. m.add_object("IndexingMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  9667. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingMultiAxisVec::typeinfo(), &py_type).second);
  9668. }
  9669. PyOpDefBegin(IndexingOneHot) // {
  9670. static PyGetSetDef py_getsetters[];
  9671. static PyMethodDef tp_methods[];
  9672. static PyObject* getstate(PyObject* self, PyObject*) {
  9673. auto& opdef = reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst();
  9674. static_cast<void>(opdef);
  9675. std::unordered_map<std::string, py::object> state {
  9676. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  9677. {"ndim", serialization<decltype(opdef.ndim)>::dump(opdef.ndim)}
  9678. };
  9679. return py::cast(state).release().ptr();
  9680. }
  9681. static PyObject* setstate(PyObject* self, PyObject* args) {
  9682. PyObject* dict = PyTuple_GetItem(args, 0);
  9683. if (!dict) return NULL;
  9684. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9685. auto& opdef = reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst();
  9686. static_cast<void>(opdef);
  9687. {
  9688. auto&& iter = state.find("axis");
  9689. if (iter != state.end()) {
  9690. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  9691. }
  9692. }
  9693. {
  9694. auto&& iter = state.find("ndim");
  9695. if (iter != state.end()) {
  9696. opdef.ndim = serialization<decltype(opdef.ndim)>::load(iter->second);
  9697. }
  9698. }
  9699. Py_RETURN_NONE;
  9700. }
  9701. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9702. // };
  9703. PyOpDefEnd(IndexingOneHot)
  9704. int PyOp(IndexingOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9705. static const char* kwlist[] = {"axis", "ndim", "scope", NULL};
  9706. PyObject *axis = NULL, *ndim = NULL, *scope = NULL;
  9707. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &ndim, &scope))
  9708. return -1;
  9709. if (axis) {
  9710. try {
  9711. // TODO: remove this guard which is used for pybind11 implicit conversion
  9712. py::detail::loader_life_support guard{};
  9713. reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst().axis =
  9714. py::cast<decltype(IndexingOneHot::axis)>(py::handle(axis));
  9715. } CATCH_ALL(-1)
  9716. }
  9717. if (ndim) {
  9718. try {
  9719. // TODO: remove this guard which is used for pybind11 implicit conversion
  9720. py::detail::loader_life_support guard{};
  9721. reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst().ndim =
  9722. py::cast<decltype(IndexingOneHot::ndim)>(py::handle(ndim));
  9723. } CATCH_ALL(-1)
  9724. }
  9725. if (scope) {
  9726. try {
  9727. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9728. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9729. } CATCH_ALL(-1)
  9730. }
  9731. return 0;
  9732. }
  9733. PyGetSetDef PyOp(IndexingOneHot)::py_getsetters[] = {
  9734. {const_cast<char*>("axis"), py_get_generic(IndexingOneHot, axis), py_set_generic(IndexingOneHot, axis), const_cast<char*>("axis"), NULL},
  9735. {const_cast<char*>("ndim"), py_get_generic(IndexingOneHot, ndim), py_set_generic(IndexingOneHot, ndim), const_cast<char*>("ndim"), NULL},
  9736. {NULL} /* Sentinel */
  9737. };
  9738. PyMethodDef PyOp(IndexingOneHot)::tp_methods[] = {
  9739. {const_cast<char*>("__getstate__"), PyOp(IndexingOneHot)::getstate, METH_NOARGS, "IndexingOneHot getstate"},
  9740. {const_cast<char*>("__setstate__"), PyOp(IndexingOneHot)::setstate, METH_VARARGS, "IndexingOneHot setstate"},
  9741. {NULL} /* Sentinel */
  9742. };
  9743. void _init_py_IndexingOneHot(py::module m) {
  9744. using py_op = PyOp(IndexingOneHot);
  9745. auto& py_type = PyOpType(IndexingOneHot);
  9746. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9747. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingOneHot";
  9748. py_type.tp_basicsize = sizeof(PyOp(IndexingOneHot));
  9749. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9750. py_type.tp_doc = "IndexingOneHot";
  9751. py_type.tp_base = &PyOpType(OpDef);
  9752. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9753. py_type.tp_new = py_new_generic<py_op>;
  9754. py_type.tp_init = py_op::py_init;
  9755. py_type.tp_methods = py_op::tp_methods;
  9756. py_type.tp_getset = py_op::py_getsetters;
  9757. mgb_assert(PyType_Ready(&py_type) >= 0);
  9758. PyType_Modified(&py_type);
  9759. m.add_object("IndexingOneHot", reinterpret_cast<PyObject*>(&py_type));
  9760. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingOneHot::typeinfo(), &py_type).second);
  9761. }
  9762. PyOpDefBegin(IndexingSetMultiAxisVec) // {
  9763. static PyGetSetDef py_getsetters[];
  9764. static PyMethodDef tp_methods[];
  9765. static PyObject* getstate(PyObject* self, PyObject*) {
  9766. auto& opdef = reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst();
  9767. static_cast<void>(opdef);
  9768. std::unordered_map<std::string, py::object> state {
  9769. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9770. };
  9771. return py::cast(state).release().ptr();
  9772. }
  9773. static PyObject* setstate(PyObject* self, PyObject* args) {
  9774. PyObject* dict = PyTuple_GetItem(args, 0);
  9775. if (!dict) return NULL;
  9776. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9777. auto& opdef = reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst();
  9778. static_cast<void>(opdef);
  9779. {
  9780. auto&& iter = state.find("items");
  9781. if (iter != state.end()) {
  9782. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9783. }
  9784. }
  9785. Py_RETURN_NONE;
  9786. }
  9787. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9788. // };
  9789. PyOpDefEnd(IndexingSetMultiAxisVec)
  9790. int PyOp(IndexingSetMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9791. static const char* kwlist[] = {"items", "scope", NULL};
  9792. PyObject *items = NULL, *scope = NULL;
  9793. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9794. return -1;
  9795. if (items) {
  9796. try {
  9797. // TODO: remove this guard which is used for pybind11 implicit conversion
  9798. py::detail::loader_life_support guard{};
  9799. reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst().items =
  9800. py::cast<decltype(IndexingSetMultiAxisVec::items)>(py::handle(items));
  9801. } CATCH_ALL(-1)
  9802. }
  9803. if (scope) {
  9804. try {
  9805. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9806. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9807. } CATCH_ALL(-1)
  9808. }
  9809. return 0;
  9810. }
  9811. PyGetSetDef PyOp(IndexingSetMultiAxisVec)::py_getsetters[] = {
  9812. {const_cast<char*>("items"), py_get_generic(IndexingSetMultiAxisVec, items), py_set_generic(IndexingSetMultiAxisVec, items), const_cast<char*>("items"), NULL},
  9813. {NULL} /* Sentinel */
  9814. };
  9815. PyMethodDef PyOp(IndexingSetMultiAxisVec)::tp_methods[] = {
  9816. {const_cast<char*>("__getstate__"), PyOp(IndexingSetMultiAxisVec)::getstate, METH_NOARGS, "IndexingSetMultiAxisVec getstate"},
  9817. {const_cast<char*>("__setstate__"), PyOp(IndexingSetMultiAxisVec)::setstate, METH_VARARGS, "IndexingSetMultiAxisVec setstate"},
  9818. {NULL} /* Sentinel */
  9819. };
  9820. void _init_py_IndexingSetMultiAxisVec(py::module m) {
  9821. using py_op = PyOp(IndexingSetMultiAxisVec);
  9822. auto& py_type = PyOpType(IndexingSetMultiAxisVec);
  9823. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9824. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetMultiAxisVec";
  9825. py_type.tp_basicsize = sizeof(PyOp(IndexingSetMultiAxisVec));
  9826. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9827. py_type.tp_doc = "IndexingSetMultiAxisVec";
  9828. py_type.tp_base = &PyOpType(OpDef);
  9829. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9830. py_type.tp_new = py_new_generic<py_op>;
  9831. py_type.tp_init = py_op::py_init;
  9832. py_type.tp_methods = py_op::tp_methods;
  9833. py_type.tp_getset = py_op::py_getsetters;
  9834. mgb_assert(PyType_Ready(&py_type) >= 0);
  9835. PyType_Modified(&py_type);
  9836. m.add_object("IndexingSetMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  9837. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetMultiAxisVec::typeinfo(), &py_type).second);
  9838. }
  9839. PyOpDefBegin(IndexingSetOneHot) // {
  9840. static PyGetSetDef py_getsetters[];
  9841. static PyMethodDef tp_methods[];
  9842. static PyObject* getstate(PyObject* self, PyObject*) {
  9843. auto& opdef = reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst();
  9844. static_cast<void>(opdef);
  9845. std::unordered_map<std::string, py::object> state {
  9846. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  9847. {"ndim", serialization<decltype(opdef.ndim)>::dump(opdef.ndim)}
  9848. };
  9849. return py::cast(state).release().ptr();
  9850. }
  9851. static PyObject* setstate(PyObject* self, PyObject* args) {
  9852. PyObject* dict = PyTuple_GetItem(args, 0);
  9853. if (!dict) return NULL;
  9854. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9855. auto& opdef = reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst();
  9856. static_cast<void>(opdef);
  9857. {
  9858. auto&& iter = state.find("axis");
  9859. if (iter != state.end()) {
  9860. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  9861. }
  9862. }
  9863. {
  9864. auto&& iter = state.find("ndim");
  9865. if (iter != state.end()) {
  9866. opdef.ndim = serialization<decltype(opdef.ndim)>::load(iter->second);
  9867. }
  9868. }
  9869. Py_RETURN_NONE;
  9870. }
  9871. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9872. // };
  9873. PyOpDefEnd(IndexingSetOneHot)
  9874. int PyOp(IndexingSetOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9875. static const char* kwlist[] = {"axis", "ndim", "scope", NULL};
  9876. PyObject *axis = NULL, *ndim = NULL, *scope = NULL;
  9877. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &ndim, &scope))
  9878. return -1;
  9879. if (axis) {
  9880. try {
  9881. // TODO: remove this guard which is used for pybind11 implicit conversion
  9882. py::detail::loader_life_support guard{};
  9883. reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst().axis =
  9884. py::cast<decltype(IndexingSetOneHot::axis)>(py::handle(axis));
  9885. } CATCH_ALL(-1)
  9886. }
  9887. if (ndim) {
  9888. try {
  9889. // TODO: remove this guard which is used for pybind11 implicit conversion
  9890. py::detail::loader_life_support guard{};
  9891. reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst().ndim =
  9892. py::cast<decltype(IndexingSetOneHot::ndim)>(py::handle(ndim));
  9893. } CATCH_ALL(-1)
  9894. }
  9895. if (scope) {
  9896. try {
  9897. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9898. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9899. } CATCH_ALL(-1)
  9900. }
  9901. return 0;
  9902. }
  9903. PyGetSetDef PyOp(IndexingSetOneHot)::py_getsetters[] = {
  9904. {const_cast<char*>("axis"), py_get_generic(IndexingSetOneHot, axis), py_set_generic(IndexingSetOneHot, axis), const_cast<char*>("axis"), NULL},
  9905. {const_cast<char*>("ndim"), py_get_generic(IndexingSetOneHot, ndim), py_set_generic(IndexingSetOneHot, ndim), const_cast<char*>("ndim"), NULL},
  9906. {NULL} /* Sentinel */
  9907. };
  9908. PyMethodDef PyOp(IndexingSetOneHot)::tp_methods[] = {
  9909. {const_cast<char*>("__getstate__"), PyOp(IndexingSetOneHot)::getstate, METH_NOARGS, "IndexingSetOneHot getstate"},
  9910. {const_cast<char*>("__setstate__"), PyOp(IndexingSetOneHot)::setstate, METH_VARARGS, "IndexingSetOneHot setstate"},
  9911. {NULL} /* Sentinel */
  9912. };
  9913. void _init_py_IndexingSetOneHot(py::module m) {
  9914. using py_op = PyOp(IndexingSetOneHot);
  9915. auto& py_type = PyOpType(IndexingSetOneHot);
  9916. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9917. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetOneHot";
  9918. py_type.tp_basicsize = sizeof(PyOp(IndexingSetOneHot));
  9919. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9920. py_type.tp_doc = "IndexingSetOneHot";
  9921. py_type.tp_base = &PyOpType(OpDef);
  9922. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9923. py_type.tp_new = py_new_generic<py_op>;
  9924. py_type.tp_init = py_op::py_init;
  9925. py_type.tp_methods = py_op::tp_methods;
  9926. py_type.tp_getset = py_op::py_getsetters;
  9927. mgb_assert(PyType_Ready(&py_type) >= 0);
  9928. PyType_Modified(&py_type);
  9929. m.add_object("IndexingSetOneHot", reinterpret_cast<PyObject*>(&py_type));
  9930. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetOneHot::typeinfo(), &py_type).second);
  9931. }
  9932. PyOpDefBegin(InplaceAdd) // {
  9933. static PyGetSetDef py_getsetters[];
  9934. static PyMethodDef tp_methods[];
  9935. static PyObject* getstate(PyObject* self, PyObject*) {
  9936. auto& opdef = reinterpret_cast<PyOp(InplaceAdd)*>(self)->inst();
  9937. static_cast<void>(opdef);
  9938. std::unordered_map<std::string, py::object> state {
  9939. };
  9940. return py::cast(state).release().ptr();
  9941. }
  9942. static PyObject* setstate(PyObject* self, PyObject* args) {
  9943. PyObject* dict = PyTuple_GetItem(args, 0);
  9944. if (!dict) return NULL;
  9945. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9946. auto& opdef = reinterpret_cast<PyOp(InplaceAdd)*>(self)->inst();
  9947. static_cast<void>(opdef);
  9948. Py_RETURN_NONE;
  9949. }
  9950. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9951. // };
  9952. PyOpDefEnd(InplaceAdd)
  9953. int PyOp(InplaceAdd)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9954. return 0;
  9955. }
  9956. PyGetSetDef PyOp(InplaceAdd)::py_getsetters[] = {
  9957. {NULL} /* Sentinel */
  9958. };
  9959. PyMethodDef PyOp(InplaceAdd)::tp_methods[] = {
  9960. {const_cast<char*>("__getstate__"), PyOp(InplaceAdd)::getstate, METH_NOARGS, "InplaceAdd getstate"},
  9961. {const_cast<char*>("__setstate__"), PyOp(InplaceAdd)::setstate, METH_VARARGS, "InplaceAdd setstate"},
  9962. {NULL} /* Sentinel */
  9963. };
  9964. void _init_py_InplaceAdd(py::module m) {
  9965. using py_op = PyOp(InplaceAdd);
  9966. auto& py_type = PyOpType(InplaceAdd);
  9967. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9968. py_type.tp_name = "megengine.core._imperative_rt.ops.InplaceAdd";
  9969. py_type.tp_basicsize = sizeof(PyOp(InplaceAdd));
  9970. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9971. py_type.tp_doc = "InplaceAdd";
  9972. py_type.tp_base = &PyOpType(OpDef);
  9973. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9974. py_type.tp_new = py_new_generic<py_op>;
  9975. py_type.tp_init = py_op::py_init;
  9976. py_type.tp_methods = py_op::tp_methods;
  9977. py_type.tp_getset = py_op::py_getsetters;
  9978. mgb_assert(PyType_Ready(&py_type) >= 0);
  9979. PyType_Modified(&py_type);
  9980. m.add_object("InplaceAdd", reinterpret_cast<PyObject*>(&py_type));
  9981. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(InplaceAdd::typeinfo(), &py_type).second);
  9982. }
  9983. PyOpDefBegin(LAMBUpdate) // {
  9984. static PyGetSetDef py_getsetters[];
  9985. static PyMethodDef tp_methods[];
  9986. static PyObject* getstate(PyObject* self, PyObject*) {
  9987. auto& opdef = reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst();
  9988. static_cast<void>(opdef);
  9989. std::unordered_map<std::string, py::object> state {
  9990. {"beta_1", serialization<decltype(opdef.beta_1)>::dump(opdef.beta_1)},
  9991. {"beta_2", serialization<decltype(opdef.beta_2)>::dump(opdef.beta_2)},
  9992. {"step", serialization<decltype(opdef.step)>::dump(opdef.step)},
  9993. {"lr", serialization<decltype(opdef.lr)>::dump(opdef.lr)},
  9994. {"weight_decay", serialization<decltype(opdef.weight_decay)>::dump(opdef.weight_decay)},
  9995. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  9996. {"bias_correction", serialization<decltype(opdef.bias_correction)>::dump(opdef.bias_correction)},
  9997. {"always_adapt", serialization<decltype(opdef.always_adapt)>::dump(opdef.always_adapt)}
  9998. };
  9999. return py::cast(state).release().ptr();
  10000. }
  10001. static PyObject* setstate(PyObject* self, PyObject* args) {
  10002. PyObject* dict = PyTuple_GetItem(args, 0);
  10003. if (!dict) return NULL;
  10004. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10005. auto& opdef = reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst();
  10006. static_cast<void>(opdef);
  10007. {
  10008. auto&& iter = state.find("beta_1");
  10009. if (iter != state.end()) {
  10010. opdef.beta_1 = serialization<decltype(opdef.beta_1)>::load(iter->second);
  10011. }
  10012. }
  10013. {
  10014. auto&& iter = state.find("beta_2");
  10015. if (iter != state.end()) {
  10016. opdef.beta_2 = serialization<decltype(opdef.beta_2)>::load(iter->second);
  10017. }
  10018. }
  10019. {
  10020. auto&& iter = state.find("step");
  10021. if (iter != state.end()) {
  10022. opdef.step = serialization<decltype(opdef.step)>::load(iter->second);
  10023. }
  10024. }
  10025. {
  10026. auto&& iter = state.find("lr");
  10027. if (iter != state.end()) {
  10028. opdef.lr = serialization<decltype(opdef.lr)>::load(iter->second);
  10029. }
  10030. }
  10031. {
  10032. auto&& iter = state.find("weight_decay");
  10033. if (iter != state.end()) {
  10034. opdef.weight_decay = serialization<decltype(opdef.weight_decay)>::load(iter->second);
  10035. }
  10036. }
  10037. {
  10038. auto&& iter = state.find("eps");
  10039. if (iter != state.end()) {
  10040. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  10041. }
  10042. }
  10043. {
  10044. auto&& iter = state.find("bias_correction");
  10045. if (iter != state.end()) {
  10046. opdef.bias_correction = serialization<decltype(opdef.bias_correction)>::load(iter->second);
  10047. }
  10048. }
  10049. {
  10050. auto&& iter = state.find("always_adapt");
  10051. if (iter != state.end()) {
  10052. opdef.always_adapt = serialization<decltype(opdef.always_adapt)>::load(iter->second);
  10053. }
  10054. }
  10055. Py_RETURN_NONE;
  10056. }
  10057. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10058. // };
  10059. PyOpDefEnd(LAMBUpdate)
  10060. int PyOp(LAMBUpdate)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10061. static const char* kwlist[] = {"beta_1", "beta_2", "step", "lr", "weight_decay", "eps", "bias_correction", "always_adapt", "scope", NULL};
  10062. PyObject *beta_1 = NULL, *beta_2 = NULL, *step = NULL, *lr = NULL, *weight_decay = NULL, *eps = NULL, *bias_correction = NULL, *always_adapt = NULL, *scope = NULL;
  10063. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &beta_1, &beta_2, &step, &lr, &weight_decay, &eps, &bias_correction, &always_adapt, &scope))
  10064. return -1;
  10065. if (beta_1) {
  10066. try {
  10067. // TODO: remove this guard which is used for pybind11 implicit conversion
  10068. py::detail::loader_life_support guard{};
  10069. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().beta_1 =
  10070. py::cast<decltype(LAMBUpdate::beta_1)>(py::handle(beta_1));
  10071. } CATCH_ALL(-1)
  10072. }
  10073. if (beta_2) {
  10074. try {
  10075. // TODO: remove this guard which is used for pybind11 implicit conversion
  10076. py::detail::loader_life_support guard{};
  10077. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().beta_2 =
  10078. py::cast<decltype(LAMBUpdate::beta_2)>(py::handle(beta_2));
  10079. } CATCH_ALL(-1)
  10080. }
  10081. if (step) {
  10082. try {
  10083. // TODO: remove this guard which is used for pybind11 implicit conversion
  10084. py::detail::loader_life_support guard{};
  10085. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().step =
  10086. py::cast<decltype(LAMBUpdate::step)>(py::handle(step));
  10087. } CATCH_ALL(-1)
  10088. }
  10089. if (lr) {
  10090. try {
  10091. // TODO: remove this guard which is used for pybind11 implicit conversion
  10092. py::detail::loader_life_support guard{};
  10093. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().lr =
  10094. py::cast<decltype(LAMBUpdate::lr)>(py::handle(lr));
  10095. } CATCH_ALL(-1)
  10096. }
  10097. if (weight_decay) {
  10098. try {
  10099. // TODO: remove this guard which is used for pybind11 implicit conversion
  10100. py::detail::loader_life_support guard{};
  10101. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().weight_decay =
  10102. py::cast<decltype(LAMBUpdate::weight_decay)>(py::handle(weight_decay));
  10103. } CATCH_ALL(-1)
  10104. }
  10105. if (eps) {
  10106. try {
  10107. // TODO: remove this guard which is used for pybind11 implicit conversion
  10108. py::detail::loader_life_support guard{};
  10109. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().eps =
  10110. py::cast<decltype(LAMBUpdate::eps)>(py::handle(eps));
  10111. } CATCH_ALL(-1)
  10112. }
  10113. if (bias_correction) {
  10114. try {
  10115. // TODO: remove this guard which is used for pybind11 implicit conversion
  10116. py::detail::loader_life_support guard{};
  10117. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().bias_correction =
  10118. py::cast<decltype(LAMBUpdate::bias_correction)>(py::handle(bias_correction));
  10119. } CATCH_ALL(-1)
  10120. }
  10121. if (always_adapt) {
  10122. try {
  10123. // TODO: remove this guard which is used for pybind11 implicit conversion
  10124. py::detail::loader_life_support guard{};
  10125. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().always_adapt =
  10126. py::cast<decltype(LAMBUpdate::always_adapt)>(py::handle(always_adapt));
  10127. } CATCH_ALL(-1)
  10128. }
  10129. if (scope) {
  10130. try {
  10131. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10132. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10133. } CATCH_ALL(-1)
  10134. }
  10135. return 0;
  10136. }
  10137. PyGetSetDef PyOp(LAMBUpdate)::py_getsetters[] = {
  10138. {const_cast<char*>("beta_1"), py_get_generic(LAMBUpdate, beta_1), py_set_generic(LAMBUpdate, beta_1), const_cast<char*>("beta_1"), NULL},
  10139. {const_cast<char*>("beta_2"), py_get_generic(LAMBUpdate, beta_2), py_set_generic(LAMBUpdate, beta_2), const_cast<char*>("beta_2"), NULL},
  10140. {const_cast<char*>("step"), py_get_generic(LAMBUpdate, step), py_set_generic(LAMBUpdate, step), const_cast<char*>("step"), NULL},
  10141. {const_cast<char*>("lr"), py_get_generic(LAMBUpdate, lr), py_set_generic(LAMBUpdate, lr), const_cast<char*>("lr"), NULL},
  10142. {const_cast<char*>("weight_decay"), py_get_generic(LAMBUpdate, weight_decay), py_set_generic(LAMBUpdate, weight_decay), const_cast<char*>("weight_decay"), NULL},
  10143. {const_cast<char*>("eps"), py_get_generic(LAMBUpdate, eps), py_set_generic(LAMBUpdate, eps), const_cast<char*>("eps"), NULL},
  10144. {const_cast<char*>("bias_correction"), py_get_generic(LAMBUpdate, bias_correction), py_set_generic(LAMBUpdate, bias_correction), const_cast<char*>("bias_correction"), NULL},
  10145. {const_cast<char*>("always_adapt"), py_get_generic(LAMBUpdate, always_adapt), py_set_generic(LAMBUpdate, always_adapt), const_cast<char*>("always_adapt"), NULL},
  10146. {NULL} /* Sentinel */
  10147. };
  10148. PyMethodDef PyOp(LAMBUpdate)::tp_methods[] = {
  10149. {const_cast<char*>("__getstate__"), PyOp(LAMBUpdate)::getstate, METH_NOARGS, "LAMBUpdate getstate"},
  10150. {const_cast<char*>("__setstate__"), PyOp(LAMBUpdate)::setstate, METH_VARARGS, "LAMBUpdate setstate"},
  10151. {NULL} /* Sentinel */
  10152. };
  10153. void _init_py_LAMBUpdate(py::module m) {
  10154. using py_op = PyOp(LAMBUpdate);
  10155. auto& py_type = PyOpType(LAMBUpdate);
  10156. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10157. py_type.tp_name = "megengine.core._imperative_rt.ops.LAMBUpdate";
  10158. py_type.tp_basicsize = sizeof(PyOp(LAMBUpdate));
  10159. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10160. py_type.tp_doc = "LAMBUpdate";
  10161. py_type.tp_base = &PyOpType(OpDef);
  10162. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10163. py_type.tp_new = py_new_generic<py_op>;
  10164. py_type.tp_init = py_op::py_init;
  10165. py_type.tp_methods = py_op::tp_methods;
  10166. py_type.tp_getset = py_op::py_getsetters;
  10167. mgb_assert(PyType_Ready(&py_type) >= 0);
  10168. PyType_Modified(&py_type);
  10169. m.add_object("LAMBUpdate", reinterpret_cast<PyObject*>(&py_type));
  10170. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LAMBUpdate::typeinfo(), &py_type).second);
  10171. }
  10172. PyOpDefBegin(LRN) // {
  10173. static PyGetSetDef py_getsetters[];
  10174. static PyMethodDef tp_methods[];
  10175. static PyObject* getstate(PyObject* self, PyObject*) {
  10176. auto& opdef = reinterpret_cast<PyOp(LRN)*>(self)->inst();
  10177. static_cast<void>(opdef);
  10178. std::unordered_map<std::string, py::object> state {
  10179. {"n", serialization<decltype(opdef.n)>::dump(opdef.n)},
  10180. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)},
  10181. {"alpha", serialization<decltype(opdef.alpha)>::dump(opdef.alpha)},
  10182. {"beta", serialization<decltype(opdef.beta)>::dump(opdef.beta)}
  10183. };
  10184. return py::cast(state).release().ptr();
  10185. }
  10186. static PyObject* setstate(PyObject* self, PyObject* args) {
  10187. PyObject* dict = PyTuple_GetItem(args, 0);
  10188. if (!dict) return NULL;
  10189. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10190. auto& opdef = reinterpret_cast<PyOp(LRN)*>(self)->inst();
  10191. static_cast<void>(opdef);
  10192. {
  10193. auto&& iter = state.find("n");
  10194. if (iter != state.end()) {
  10195. opdef.n = serialization<decltype(opdef.n)>::load(iter->second);
  10196. }
  10197. }
  10198. {
  10199. auto&& iter = state.find("k");
  10200. if (iter != state.end()) {
  10201. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  10202. }
  10203. }
  10204. {
  10205. auto&& iter = state.find("alpha");
  10206. if (iter != state.end()) {
  10207. opdef.alpha = serialization<decltype(opdef.alpha)>::load(iter->second);
  10208. }
  10209. }
  10210. {
  10211. auto&& iter = state.find("beta");
  10212. if (iter != state.end()) {
  10213. opdef.beta = serialization<decltype(opdef.beta)>::load(iter->second);
  10214. }
  10215. }
  10216. Py_RETURN_NONE;
  10217. }
  10218. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10219. // };
  10220. PyOpDefEnd(LRN)
  10221. int PyOp(LRN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10222. static const char* kwlist[] = {"n", "k", "alpha", "beta", "scope", NULL};
  10223. PyObject *n = NULL, *k = NULL, *alpha = NULL, *beta = NULL, *scope = NULL;
  10224. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &n, &k, &alpha, &beta, &scope))
  10225. return -1;
  10226. if (n) {
  10227. try {
  10228. // TODO: remove this guard which is used for pybind11 implicit conversion
  10229. py::detail::loader_life_support guard{};
  10230. reinterpret_cast<PyOp(LRN)*>(self)->inst().n =
  10231. py::cast<decltype(LRN::n)>(py::handle(n));
  10232. } CATCH_ALL(-1)
  10233. }
  10234. if (k) {
  10235. try {
  10236. // TODO: remove this guard which is used for pybind11 implicit conversion
  10237. py::detail::loader_life_support guard{};
  10238. reinterpret_cast<PyOp(LRN)*>(self)->inst().k =
  10239. py::cast<decltype(LRN::k)>(py::handle(k));
  10240. } CATCH_ALL(-1)
  10241. }
  10242. if (alpha) {
  10243. try {
  10244. // TODO: remove this guard which is used for pybind11 implicit conversion
  10245. py::detail::loader_life_support guard{};
  10246. reinterpret_cast<PyOp(LRN)*>(self)->inst().alpha =
  10247. py::cast<decltype(LRN::alpha)>(py::handle(alpha));
  10248. } CATCH_ALL(-1)
  10249. }
  10250. if (beta) {
  10251. try {
  10252. // TODO: remove this guard which is used for pybind11 implicit conversion
  10253. py::detail::loader_life_support guard{};
  10254. reinterpret_cast<PyOp(LRN)*>(self)->inst().beta =
  10255. py::cast<decltype(LRN::beta)>(py::handle(beta));
  10256. } CATCH_ALL(-1)
  10257. }
  10258. if (scope) {
  10259. try {
  10260. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10261. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10262. } CATCH_ALL(-1)
  10263. }
  10264. return 0;
  10265. }
  10266. PyGetSetDef PyOp(LRN)::py_getsetters[] = {
  10267. {const_cast<char*>("n"), py_get_generic(LRN, n), py_set_generic(LRN, n), const_cast<char*>("n"), NULL},
  10268. {const_cast<char*>("k"), py_get_generic(LRN, k), py_set_generic(LRN, k), const_cast<char*>("k"), NULL},
  10269. {const_cast<char*>("alpha"), py_get_generic(LRN, alpha), py_set_generic(LRN, alpha), const_cast<char*>("alpha"), NULL},
  10270. {const_cast<char*>("beta"), py_get_generic(LRN, beta), py_set_generic(LRN, beta), const_cast<char*>("beta"), NULL},
  10271. {NULL} /* Sentinel */
  10272. };
  10273. PyMethodDef PyOp(LRN)::tp_methods[] = {
  10274. {const_cast<char*>("__getstate__"), PyOp(LRN)::getstate, METH_NOARGS, "LRN getstate"},
  10275. {const_cast<char*>("__setstate__"), PyOp(LRN)::setstate, METH_VARARGS, "LRN setstate"},
  10276. {NULL} /* Sentinel */
  10277. };
  10278. void _init_py_LRN(py::module m) {
  10279. using py_op = PyOp(LRN);
  10280. auto& py_type = PyOpType(LRN);
  10281. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10282. py_type.tp_name = "megengine.core._imperative_rt.ops.LRN";
  10283. py_type.tp_basicsize = sizeof(PyOp(LRN));
  10284. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10285. py_type.tp_doc = "LRN";
  10286. py_type.tp_base = &PyOpType(OpDef);
  10287. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10288. py_type.tp_new = py_new_generic<py_op>;
  10289. py_type.tp_init = py_op::py_init;
  10290. py_type.tp_methods = py_op::tp_methods;
  10291. py_type.tp_getset = py_op::py_getsetters;
  10292. mgb_assert(PyType_Ready(&py_type) >= 0);
  10293. PyType_Modified(&py_type);
  10294. m.add_object("LRN", reinterpret_cast<PyObject*>(&py_type));
  10295. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LRN::typeinfo(), &py_type).second);
  10296. }
  10297. PyOpDefBegin(LSQ) // {
  10298. static PyGetSetDef py_getsetters[];
  10299. static PyMethodDef tp_methods[];
  10300. static PyObject* getstate(PyObject* self, PyObject*) {
  10301. auto& opdef = reinterpret_cast<PyOp(LSQ)*>(self)->inst();
  10302. static_cast<void>(opdef);
  10303. std::unordered_map<std::string, py::object> state {
  10304. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  10305. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  10306. };
  10307. return py::cast(state).release().ptr();
  10308. }
  10309. static PyObject* setstate(PyObject* self, PyObject* args) {
  10310. PyObject* dict = PyTuple_GetItem(args, 0);
  10311. if (!dict) return NULL;
  10312. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10313. auto& opdef = reinterpret_cast<PyOp(LSQ)*>(self)->inst();
  10314. static_cast<void>(opdef);
  10315. {
  10316. auto&& iter = state.find("qmin");
  10317. if (iter != state.end()) {
  10318. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  10319. }
  10320. }
  10321. {
  10322. auto&& iter = state.find("qmax");
  10323. if (iter != state.end()) {
  10324. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  10325. }
  10326. }
  10327. Py_RETURN_NONE;
  10328. }
  10329. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10330. // };
  10331. PyOpDefEnd(LSQ)
  10332. int PyOp(LSQ)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10333. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  10334. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  10335. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  10336. return -1;
  10337. if (qmin) {
  10338. try {
  10339. // TODO: remove this guard which is used for pybind11 implicit conversion
  10340. py::detail::loader_life_support guard{};
  10341. reinterpret_cast<PyOp(LSQ)*>(self)->inst().qmin =
  10342. py::cast<decltype(LSQ::qmin)>(py::handle(qmin));
  10343. } CATCH_ALL(-1)
  10344. }
  10345. if (qmax) {
  10346. try {
  10347. // TODO: remove this guard which is used for pybind11 implicit conversion
  10348. py::detail::loader_life_support guard{};
  10349. reinterpret_cast<PyOp(LSQ)*>(self)->inst().qmax =
  10350. py::cast<decltype(LSQ::qmax)>(py::handle(qmax));
  10351. } CATCH_ALL(-1)
  10352. }
  10353. if (scope) {
  10354. try {
  10355. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10356. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10357. } CATCH_ALL(-1)
  10358. }
  10359. return 0;
  10360. }
  10361. PyGetSetDef PyOp(LSQ)::py_getsetters[] = {
  10362. {const_cast<char*>("qmin"), py_get_generic(LSQ, qmin), py_set_generic(LSQ, qmin), const_cast<char*>("qmin"), NULL},
  10363. {const_cast<char*>("qmax"), py_get_generic(LSQ, qmax), py_set_generic(LSQ, qmax), const_cast<char*>("qmax"), NULL},
  10364. {NULL} /* Sentinel */
  10365. };
  10366. PyMethodDef PyOp(LSQ)::tp_methods[] = {
  10367. {const_cast<char*>("__getstate__"), PyOp(LSQ)::getstate, METH_NOARGS, "LSQ getstate"},
  10368. {const_cast<char*>("__setstate__"), PyOp(LSQ)::setstate, METH_VARARGS, "LSQ setstate"},
  10369. {NULL} /* Sentinel */
  10370. };
  10371. void _init_py_LSQ(py::module m) {
  10372. using py_op = PyOp(LSQ);
  10373. auto& py_type = PyOpType(LSQ);
  10374. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10375. py_type.tp_name = "megengine.core._imperative_rt.ops.LSQ";
  10376. py_type.tp_basicsize = sizeof(PyOp(LSQ));
  10377. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10378. py_type.tp_doc = "LSQ";
  10379. py_type.tp_base = &PyOpType(OpDef);
  10380. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10381. py_type.tp_new = py_new_generic<py_op>;
  10382. py_type.tp_init = py_op::py_init;
  10383. py_type.tp_methods = py_op::tp_methods;
  10384. py_type.tp_getset = py_op::py_getsetters;
  10385. mgb_assert(PyType_Ready(&py_type) >= 0);
  10386. PyType_Modified(&py_type);
  10387. m.add_object("LSQ", reinterpret_cast<PyObject*>(&py_type));
  10388. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSQ::typeinfo(), &py_type).second);
  10389. }
  10390. void _init_py_LSTM_FwdMode(PyTypeObject& py_type) {
  10391. auto& e_type = EnumWrapper<LSTM::FwdMode>::type;
  10392. Py_INCREF(e_type);
  10393. mgb_assert(PyDict_SetItemString(
  10394. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  10395. }
  10396. PyOpDefBegin(LSTM) // {
  10397. static PyGetSetDef py_getsetters[];
  10398. static PyMethodDef tp_methods[];
  10399. static PyObject* getstate(PyObject* self, PyObject*) {
  10400. auto& opdef = reinterpret_cast<PyOp(LSTM)*>(self)->inst();
  10401. static_cast<void>(opdef);
  10402. std::unordered_map<std::string, py::object> state {
  10403. {"num_layers", serialization<decltype(opdef.num_layers)>::dump(opdef.num_layers)},
  10404. {"bidirectional", serialization<decltype(opdef.bidirectional)>::dump(opdef.bidirectional)},
  10405. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)},
  10406. {"hidden_size", serialization<decltype(opdef.hidden_size)>::dump(opdef.hidden_size)},
  10407. {"proj_size", serialization<decltype(opdef.proj_size)>::dump(opdef.proj_size)},
  10408. {"dropout", serialization<decltype(opdef.dropout)>::dump(opdef.dropout)},
  10409. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)}
  10410. };
  10411. return py::cast(state).release().ptr();
  10412. }
  10413. static PyObject* setstate(PyObject* self, PyObject* args) {
  10414. PyObject* dict = PyTuple_GetItem(args, 0);
  10415. if (!dict) return NULL;
  10416. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10417. auto& opdef = reinterpret_cast<PyOp(LSTM)*>(self)->inst();
  10418. static_cast<void>(opdef);
  10419. {
  10420. auto&& iter = state.find("num_layers");
  10421. if (iter != state.end()) {
  10422. opdef.num_layers = serialization<decltype(opdef.num_layers)>::load(iter->second);
  10423. }
  10424. }
  10425. {
  10426. auto&& iter = state.find("bidirectional");
  10427. if (iter != state.end()) {
  10428. opdef.bidirectional = serialization<decltype(opdef.bidirectional)>::load(iter->second);
  10429. }
  10430. }
  10431. {
  10432. auto&& iter = state.find("bias");
  10433. if (iter != state.end()) {
  10434. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  10435. }
  10436. }
  10437. {
  10438. auto&& iter = state.find("hidden_size");
  10439. if (iter != state.end()) {
  10440. opdef.hidden_size = serialization<decltype(opdef.hidden_size)>::load(iter->second);
  10441. }
  10442. }
  10443. {
  10444. auto&& iter = state.find("proj_size");
  10445. if (iter != state.end()) {
  10446. opdef.proj_size = serialization<decltype(opdef.proj_size)>::load(iter->second);
  10447. }
  10448. }
  10449. {
  10450. auto&& iter = state.find("dropout");
  10451. if (iter != state.end()) {
  10452. opdef.dropout = serialization<decltype(opdef.dropout)>::load(iter->second);
  10453. }
  10454. }
  10455. {
  10456. auto&& iter = state.find("fwd_mode");
  10457. if (iter != state.end()) {
  10458. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  10459. }
  10460. }
  10461. Py_RETURN_NONE;
  10462. }
  10463. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10464. // };
  10465. PyOpDefEnd(LSTM)
  10466. int PyOp(LSTM)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10467. static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "proj_size", "dropout", "fwd_mode", "scope", NULL};
  10468. PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *proj_size = NULL, *dropout = NULL, *fwd_mode = NULL, *scope = NULL;
  10469. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &proj_size, &dropout, &fwd_mode, &scope))
  10470. return -1;
  10471. if (num_layers) {
  10472. try {
  10473. // TODO: remove this guard which is used for pybind11 implicit conversion
  10474. py::detail::loader_life_support guard{};
  10475. reinterpret_cast<PyOp(LSTM)*>(self)->inst().num_layers =
  10476. py::cast<decltype(LSTM::num_layers)>(py::handle(num_layers));
  10477. } CATCH_ALL(-1)
  10478. }
  10479. if (bidirectional) {
  10480. try {
  10481. // TODO: remove this guard which is used for pybind11 implicit conversion
  10482. py::detail::loader_life_support guard{};
  10483. reinterpret_cast<PyOp(LSTM)*>(self)->inst().bidirectional =
  10484. py::cast<decltype(LSTM::bidirectional)>(py::handle(bidirectional));
  10485. } CATCH_ALL(-1)
  10486. }
  10487. if (bias) {
  10488. try {
  10489. // TODO: remove this guard which is used for pybind11 implicit conversion
  10490. py::detail::loader_life_support guard{};
  10491. reinterpret_cast<PyOp(LSTM)*>(self)->inst().bias =
  10492. py::cast<decltype(LSTM::bias)>(py::handle(bias));
  10493. } CATCH_ALL(-1)
  10494. }
  10495. if (hidden_size) {
  10496. try {
  10497. // TODO: remove this guard which is used for pybind11 implicit conversion
  10498. py::detail::loader_life_support guard{};
  10499. reinterpret_cast<PyOp(LSTM)*>(self)->inst().hidden_size =
  10500. py::cast<decltype(LSTM::hidden_size)>(py::handle(hidden_size));
  10501. } CATCH_ALL(-1)
  10502. }
  10503. if (proj_size) {
  10504. try {
  10505. // TODO: remove this guard which is used for pybind11 implicit conversion
  10506. py::detail::loader_life_support guard{};
  10507. reinterpret_cast<PyOp(LSTM)*>(self)->inst().proj_size =
  10508. py::cast<decltype(LSTM::proj_size)>(py::handle(proj_size));
  10509. } CATCH_ALL(-1)
  10510. }
  10511. if (dropout) {
  10512. try {
  10513. // TODO: remove this guard which is used for pybind11 implicit conversion
  10514. py::detail::loader_life_support guard{};
  10515. reinterpret_cast<PyOp(LSTM)*>(self)->inst().dropout =
  10516. py::cast<decltype(LSTM::dropout)>(py::handle(dropout));
  10517. } CATCH_ALL(-1)
  10518. }
  10519. if (fwd_mode) {
  10520. try {
  10521. // TODO: remove this guard which is used for pybind11 implicit conversion
  10522. py::detail::loader_life_support guard{};
  10523. reinterpret_cast<PyOp(LSTM)*>(self)->inst().fwd_mode =
  10524. py::cast<decltype(LSTM::fwd_mode)>(py::handle(fwd_mode));
  10525. } CATCH_ALL(-1)
  10526. }
  10527. if (scope) {
  10528. try {
  10529. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10530. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10531. } CATCH_ALL(-1)
  10532. }
  10533. return 0;
  10534. }
  10535. PyGetSetDef PyOp(LSTM)::py_getsetters[] = {
  10536. {const_cast<char*>("num_layers"), py_get_generic(LSTM, num_layers), py_set_generic(LSTM, num_layers), const_cast<char*>("num_layers"), NULL},
  10537. {const_cast<char*>("bidirectional"), py_get_generic(LSTM, bidirectional), py_set_generic(LSTM, bidirectional), const_cast<char*>("bidirectional"), NULL},
  10538. {const_cast<char*>("bias"), py_get_generic(LSTM, bias), py_set_generic(LSTM, bias), const_cast<char*>("bias"), NULL},
  10539. {const_cast<char*>("hidden_size"), py_get_generic(LSTM, hidden_size), py_set_generic(LSTM, hidden_size), const_cast<char*>("hidden_size"), NULL},
  10540. {const_cast<char*>("proj_size"), py_get_generic(LSTM, proj_size), py_set_generic(LSTM, proj_size), const_cast<char*>("proj_size"), NULL},
  10541. {const_cast<char*>("dropout"), py_get_generic(LSTM, dropout), py_set_generic(LSTM, dropout), const_cast<char*>("dropout"), NULL},
  10542. {const_cast<char*>("fwd_mode"), py_get_generic(LSTM, fwd_mode), py_set_generic(LSTM, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  10543. {NULL} /* Sentinel */
  10544. };
  10545. PyMethodDef PyOp(LSTM)::tp_methods[] = {
  10546. {const_cast<char*>("__getstate__"), PyOp(LSTM)::getstate, METH_NOARGS, "LSTM getstate"},
  10547. {const_cast<char*>("__setstate__"), PyOp(LSTM)::setstate, METH_VARARGS, "LSTM setstate"},
  10548. {NULL} /* Sentinel */
  10549. };
  10550. void _init_py_LSTM(py::module m) {
  10551. using py_op = PyOp(LSTM);
  10552. auto& py_type = PyOpType(LSTM);
  10553. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10554. py_type.tp_name = "megengine.core._imperative_rt.ops.LSTM";
  10555. py_type.tp_basicsize = sizeof(PyOp(LSTM));
  10556. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10557. py_type.tp_doc = "LSTM";
  10558. py_type.tp_base = &PyOpType(OpDef);
  10559. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10560. py_type.tp_new = py_new_generic<py_op>;
  10561. py_type.tp_init = py_op::py_init;
  10562. py_type.tp_methods = py_op::tp_methods;
  10563. py_type.tp_getset = py_op::py_getsetters;
  10564. mgb_assert(PyType_Ready(&py_type) >= 0);
  10565. _init_py_LSTM_FwdMode(py_type);
  10566. PyType_Modified(&py_type);
  10567. m.add_object("LSTM", reinterpret_cast<PyObject*>(&py_type));
  10568. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTM::typeinfo(), &py_type).second);
  10569. }
  10570. PyOpDefBegin(LSTMCell) // {
  10571. static PyGetSetDef py_getsetters[];
  10572. static PyMethodDef tp_methods[];
  10573. static PyObject* getstate(PyObject* self, PyObject*) {
  10574. auto& opdef = reinterpret_cast<PyOp(LSTMCell)*>(self)->inst();
  10575. static_cast<void>(opdef);
  10576. std::unordered_map<std::string, py::object> state {
  10577. };
  10578. return py::cast(state).release().ptr();
  10579. }
  10580. static PyObject* setstate(PyObject* self, PyObject* args) {
  10581. PyObject* dict = PyTuple_GetItem(args, 0);
  10582. if (!dict) return NULL;
  10583. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10584. auto& opdef = reinterpret_cast<PyOp(LSTMCell)*>(self)->inst();
  10585. static_cast<void>(opdef);
  10586. Py_RETURN_NONE;
  10587. }
  10588. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10589. // };
  10590. PyOpDefEnd(LSTMCell)
  10591. int PyOp(LSTMCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10592. return 0;
  10593. }
  10594. PyGetSetDef PyOp(LSTMCell)::py_getsetters[] = {
  10595. {NULL} /* Sentinel */
  10596. };
  10597. PyMethodDef PyOp(LSTMCell)::tp_methods[] = {
  10598. {const_cast<char*>("__getstate__"), PyOp(LSTMCell)::getstate, METH_NOARGS, "LSTMCell getstate"},
  10599. {const_cast<char*>("__setstate__"), PyOp(LSTMCell)::setstate, METH_VARARGS, "LSTMCell setstate"},
  10600. {NULL} /* Sentinel */
  10601. };
  10602. void _init_py_LSTMCell(py::module m) {
  10603. using py_op = PyOp(LSTMCell);
  10604. auto& py_type = PyOpType(LSTMCell);
  10605. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10606. py_type.tp_name = "megengine.core._imperative_rt.ops.LSTMCell";
  10607. py_type.tp_basicsize = sizeof(PyOp(LSTMCell));
  10608. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10609. py_type.tp_doc = "LSTMCell";
  10610. py_type.tp_base = &PyOpType(OpDef);
  10611. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10612. py_type.tp_new = py_new_generic<py_op>;
  10613. py_type.tp_init = py_op::py_init;
  10614. py_type.tp_methods = py_op::tp_methods;
  10615. py_type.tp_getset = py_op::py_getsetters;
  10616. mgb_assert(PyType_Ready(&py_type) >= 0);
  10617. PyType_Modified(&py_type);
  10618. m.add_object("LSTMCell", reinterpret_cast<PyObject*>(&py_type));
  10619. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTMCell::typeinfo(), &py_type).second);
  10620. }
  10621. PyOpDefBegin(LayerNorm) // {
  10622. static PyGetSetDef py_getsetters[];
  10623. static PyMethodDef tp_methods[];
  10624. static PyObject* getstate(PyObject* self, PyObject*) {
  10625. auto& opdef = reinterpret_cast<PyOp(LayerNorm)*>(self)->inst();
  10626. static_cast<void>(opdef);
  10627. std::unordered_map<std::string, py::object> state {
  10628. {"affine", serialization<decltype(opdef.affine)>::dump(opdef.affine)},
  10629. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  10630. {"normalized_dim", serialization<decltype(opdef.normalized_dim)>::dump(opdef.normalized_dim)},
  10631. {"normalized_size", serialization<decltype(opdef.normalized_size)>::dump(opdef.normalized_size)}
  10632. };
  10633. return py::cast(state).release().ptr();
  10634. }
  10635. static PyObject* setstate(PyObject* self, PyObject* args) {
  10636. PyObject* dict = PyTuple_GetItem(args, 0);
  10637. if (!dict) return NULL;
  10638. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10639. auto& opdef = reinterpret_cast<PyOp(LayerNorm)*>(self)->inst();
  10640. static_cast<void>(opdef);
  10641. {
  10642. auto&& iter = state.find("affine");
  10643. if (iter != state.end()) {
  10644. opdef.affine = serialization<decltype(opdef.affine)>::load(iter->second);
  10645. }
  10646. }
  10647. {
  10648. auto&& iter = state.find("eps");
  10649. if (iter != state.end()) {
  10650. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  10651. }
  10652. }
  10653. {
  10654. auto&& iter = state.find("normalized_dim");
  10655. if (iter != state.end()) {
  10656. opdef.normalized_dim = serialization<decltype(opdef.normalized_dim)>::load(iter->second);
  10657. }
  10658. }
  10659. {
  10660. auto&& iter = state.find("normalized_size");
  10661. if (iter != state.end()) {
  10662. opdef.normalized_size = serialization<decltype(opdef.normalized_size)>::load(iter->second);
  10663. }
  10664. }
  10665. Py_RETURN_NONE;
  10666. }
  10667. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10668. // };
  10669. PyOpDefEnd(LayerNorm)
  10670. int PyOp(LayerNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10671. static const char* kwlist[] = {"affine", "eps", "normalized_dim", "normalized_size", "scope", NULL};
  10672. PyObject *affine = NULL, *eps = NULL, *normalized_dim = NULL, *normalized_size = NULL, *scope = NULL;
  10673. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &affine, &eps, &normalized_dim, &normalized_size, &scope))
  10674. return -1;
  10675. if (affine) {
  10676. try {
  10677. // TODO: remove this guard which is used for pybind11 implicit conversion
  10678. py::detail::loader_life_support guard{};
  10679. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().affine =
  10680. py::cast<decltype(LayerNorm::affine)>(py::handle(affine));
  10681. } CATCH_ALL(-1)
  10682. }
  10683. if (eps) {
  10684. try {
  10685. // TODO: remove this guard which is used for pybind11 implicit conversion
  10686. py::detail::loader_life_support guard{};
  10687. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().eps =
  10688. py::cast<decltype(LayerNorm::eps)>(py::handle(eps));
  10689. } CATCH_ALL(-1)
  10690. }
  10691. if (normalized_dim) {
  10692. try {
  10693. // TODO: remove this guard which is used for pybind11 implicit conversion
  10694. py::detail::loader_life_support guard{};
  10695. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().normalized_dim =
  10696. py::cast<decltype(LayerNorm::normalized_dim)>(py::handle(normalized_dim));
  10697. } CATCH_ALL(-1)
  10698. }
  10699. if (normalized_size) {
  10700. try {
  10701. // TODO: remove this guard which is used for pybind11 implicit conversion
  10702. py::detail::loader_life_support guard{};
  10703. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().normalized_size =
  10704. py::cast<decltype(LayerNorm::normalized_size)>(py::handle(normalized_size));
  10705. } CATCH_ALL(-1)
  10706. }
  10707. if (scope) {
  10708. try {
  10709. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10710. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10711. } CATCH_ALL(-1)
  10712. }
  10713. return 0;
  10714. }
  10715. PyGetSetDef PyOp(LayerNorm)::py_getsetters[] = {
  10716. {const_cast<char*>("affine"), py_get_generic(LayerNorm, affine), py_set_generic(LayerNorm, affine), const_cast<char*>("affine"), NULL},
  10717. {const_cast<char*>("eps"), py_get_generic(LayerNorm, eps), py_set_generic(LayerNorm, eps), const_cast<char*>("eps"), NULL},
  10718. {const_cast<char*>("normalized_dim"), py_get_generic(LayerNorm, normalized_dim), py_set_generic(LayerNorm, normalized_dim), const_cast<char*>("normalized_dim"), NULL},
  10719. {const_cast<char*>("normalized_size"), py_get_generic(LayerNorm, normalized_size), py_set_generic(LayerNorm, normalized_size), const_cast<char*>("normalized_size"), NULL},
  10720. {NULL} /* Sentinel */
  10721. };
  10722. PyMethodDef PyOp(LayerNorm)::tp_methods[] = {
  10723. {const_cast<char*>("__getstate__"), PyOp(LayerNorm)::getstate, METH_NOARGS, "LayerNorm getstate"},
  10724. {const_cast<char*>("__setstate__"), PyOp(LayerNorm)::setstate, METH_VARARGS, "LayerNorm setstate"},
  10725. {NULL} /* Sentinel */
  10726. };
  10727. void _init_py_LayerNorm(py::module m) {
  10728. using py_op = PyOp(LayerNorm);
  10729. auto& py_type = PyOpType(LayerNorm);
  10730. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10731. py_type.tp_name = "megengine.core._imperative_rt.ops.LayerNorm";
  10732. py_type.tp_basicsize = sizeof(PyOp(LayerNorm));
  10733. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10734. py_type.tp_doc = "LayerNorm";
  10735. py_type.tp_base = &PyOpType(OpDef);
  10736. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10737. py_type.tp_new = py_new_generic<py_op>;
  10738. py_type.tp_init = py_op::py_init;
  10739. py_type.tp_methods = py_op::tp_methods;
  10740. py_type.tp_getset = py_op::py_getsetters;
  10741. mgb_assert(PyType_Ready(&py_type) >= 0);
  10742. PyType_Modified(&py_type);
  10743. m.add_object("LayerNorm", reinterpret_cast<PyObject*>(&py_type));
  10744. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LayerNorm::typeinfo(), &py_type).second);
  10745. }
  10746. PyOpDefBegin(Linspace) // {
  10747. static PyGetSetDef py_getsetters[];
  10748. static PyMethodDef tp_methods[];
  10749. static PyObject* getstate(PyObject* self, PyObject*) {
  10750. auto& opdef = reinterpret_cast<PyOp(Linspace)*>(self)->inst();
  10751. static_cast<void>(opdef);
  10752. std::unordered_map<std::string, py::object> state {
  10753. {"endpoint", serialization<decltype(opdef.endpoint)>::dump(opdef.endpoint)},
  10754. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  10755. };
  10756. return py::cast(state).release().ptr();
  10757. }
  10758. static PyObject* setstate(PyObject* self, PyObject* args) {
  10759. PyObject* dict = PyTuple_GetItem(args, 0);
  10760. if (!dict) return NULL;
  10761. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10762. auto& opdef = reinterpret_cast<PyOp(Linspace)*>(self)->inst();
  10763. static_cast<void>(opdef);
  10764. {
  10765. auto&& iter = state.find("endpoint");
  10766. if (iter != state.end()) {
  10767. opdef.endpoint = serialization<decltype(opdef.endpoint)>::load(iter->second);
  10768. }
  10769. }
  10770. {
  10771. auto&& iter = state.find("comp_node");
  10772. if (iter != state.end()) {
  10773. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  10774. }
  10775. }
  10776. Py_RETURN_NONE;
  10777. }
  10778. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10779. // };
  10780. PyOpDefEnd(Linspace)
  10781. int PyOp(Linspace)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10782. static const char* kwlist[] = {"endpoint", "comp_node", "scope", NULL};
  10783. PyObject *endpoint = NULL, *comp_node = NULL, *scope = NULL;
  10784. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &endpoint, &comp_node, &scope))
  10785. return -1;
  10786. if (endpoint) {
  10787. try {
  10788. // TODO: remove this guard which is used for pybind11 implicit conversion
  10789. py::detail::loader_life_support guard{};
  10790. reinterpret_cast<PyOp(Linspace)*>(self)->inst().endpoint =
  10791. py::cast<decltype(Linspace::endpoint)>(py::handle(endpoint));
  10792. } CATCH_ALL(-1)
  10793. }
  10794. if (comp_node) {
  10795. try {
  10796. // TODO: remove this guard which is used for pybind11 implicit conversion
  10797. py::detail::loader_life_support guard{};
  10798. reinterpret_cast<PyOp(Linspace)*>(self)->inst().comp_node =
  10799. py::cast<decltype(Linspace::comp_node)>(py::handle(comp_node));
  10800. } CATCH_ALL(-1)
  10801. }
  10802. if (scope) {
  10803. try {
  10804. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10805. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10806. } CATCH_ALL(-1)
  10807. }
  10808. return 0;
  10809. }
  10810. PyGetSetDef PyOp(Linspace)::py_getsetters[] = {
  10811. {const_cast<char*>("endpoint"), py_get_generic(Linspace, endpoint), py_set_generic(Linspace, endpoint), const_cast<char*>("endpoint"), NULL},
  10812. {const_cast<char*>("comp_node"), py_get_generic(Linspace, comp_node), py_set_generic(Linspace, comp_node), const_cast<char*>("comp_node"), NULL},
  10813. {NULL} /* Sentinel */
  10814. };
  10815. PyMethodDef PyOp(Linspace)::tp_methods[] = {
  10816. {const_cast<char*>("__getstate__"), PyOp(Linspace)::getstate, METH_NOARGS, "Linspace getstate"},
  10817. {const_cast<char*>("__setstate__"), PyOp(Linspace)::setstate, METH_VARARGS, "Linspace setstate"},
  10818. {NULL} /* Sentinel */
  10819. };
  10820. void _init_py_Linspace(py::module m) {
  10821. using py_op = PyOp(Linspace);
  10822. auto& py_type = PyOpType(Linspace);
  10823. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10824. py_type.tp_name = "megengine.core._imperative_rt.ops.Linspace";
  10825. py_type.tp_basicsize = sizeof(PyOp(Linspace));
  10826. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10827. py_type.tp_doc = "Linspace";
  10828. py_type.tp_base = &PyOpType(OpDef);
  10829. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10830. py_type.tp_new = py_new_generic<py_op>;
  10831. py_type.tp_init = py_op::py_init;
  10832. py_type.tp_methods = py_op::tp_methods;
  10833. py_type.tp_getset = py_op::py_getsetters;
  10834. mgb_assert(PyType_Ready(&py_type) >= 0);
  10835. PyType_Modified(&py_type);
  10836. m.add_object("Linspace", reinterpret_cast<PyObject*>(&py_type));
  10837. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Linspace::typeinfo(), &py_type).second);
  10838. }
  10839. PyOpDefBegin(MagicMindRuntime) // {
  10840. static PyGetSetDef py_getsetters[];
  10841. static PyMethodDef tp_methods[];
  10842. static PyObject* getstate(PyObject* self, PyObject*) {
  10843. auto& opdef = reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst();
  10844. static_cast<void>(opdef);
  10845. std::unordered_map<std::string, py::object> state {
  10846. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  10847. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  10848. };
  10849. return py::cast(state).release().ptr();
  10850. }
  10851. static PyObject* setstate(PyObject* self, PyObject* args) {
  10852. PyObject* dict = PyTuple_GetItem(args, 0);
  10853. if (!dict) return NULL;
  10854. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10855. auto& opdef = reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst();
  10856. static_cast<void>(opdef);
  10857. {
  10858. auto&& iter = state.find("buf");
  10859. if (iter != state.end()) {
  10860. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  10861. }
  10862. }
  10863. {
  10864. auto&& iter = state.find("buf_size");
  10865. if (iter != state.end()) {
  10866. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  10867. }
  10868. }
  10869. Py_RETURN_NONE;
  10870. }
  10871. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10872. // };
  10873. PyOpDefEnd(MagicMindRuntime)
  10874. int PyOp(MagicMindRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10875. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  10876. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  10877. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  10878. return -1;
  10879. if (buf) {
  10880. try {
  10881. // TODO: remove this guard which is used for pybind11 implicit conversion
  10882. py::detail::loader_life_support guard{};
  10883. reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst().buf =
  10884. py::cast<decltype(MagicMindRuntime::buf)>(py::handle(buf));
  10885. } CATCH_ALL(-1)
  10886. }
  10887. if (buf_size) {
  10888. try {
  10889. // TODO: remove this guard which is used for pybind11 implicit conversion
  10890. py::detail::loader_life_support guard{};
  10891. reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst().buf_size =
  10892. py::cast<decltype(MagicMindRuntime::buf_size)>(py::handle(buf_size));
  10893. } CATCH_ALL(-1)
  10894. }
  10895. if (scope) {
  10896. try {
  10897. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10898. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10899. } CATCH_ALL(-1)
  10900. }
  10901. return 0;
  10902. }
  10903. PyGetSetDef PyOp(MagicMindRuntime)::py_getsetters[] = {
  10904. {const_cast<char*>("buf"), py_get_generic(MagicMindRuntime, buf), py_set_generic(MagicMindRuntime, buf), const_cast<char*>("buf"), NULL},
  10905. {const_cast<char*>("buf_size"), py_get_generic(MagicMindRuntime, buf_size), py_set_generic(MagicMindRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  10906. {NULL} /* Sentinel */
  10907. };
  10908. PyMethodDef PyOp(MagicMindRuntime)::tp_methods[] = {
  10909. {const_cast<char*>("__getstate__"), PyOp(MagicMindRuntime)::getstate, METH_NOARGS, "MagicMindRuntime getstate"},
  10910. {const_cast<char*>("__setstate__"), PyOp(MagicMindRuntime)::setstate, METH_VARARGS, "MagicMindRuntime setstate"},
  10911. {NULL} /* Sentinel */
  10912. };
  10913. void _init_py_MagicMindRuntime(py::module m) {
  10914. using py_op = PyOp(MagicMindRuntime);
  10915. auto& py_type = PyOpType(MagicMindRuntime);
  10916. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10917. py_type.tp_name = "megengine.core._imperative_rt.ops.MagicMindRuntime";
  10918. py_type.tp_basicsize = sizeof(PyOp(MagicMindRuntime));
  10919. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10920. py_type.tp_doc = "MagicMindRuntime";
  10921. py_type.tp_base = &PyOpType(OpDef);
  10922. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10923. py_type.tp_new = py_new_generic<py_op>;
  10924. py_type.tp_init = py_op::py_init;
  10925. py_type.tp_methods = py_op::tp_methods;
  10926. py_type.tp_getset = py_op::py_getsetters;
  10927. mgb_assert(PyType_Ready(&py_type) >= 0);
  10928. PyType_Modified(&py_type);
  10929. m.add_object("MagicMindRuntime", reinterpret_cast<PyObject*>(&py_type));
  10930. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MagicMindRuntime::typeinfo(), &py_type).second);
  10931. }
  10932. PyOpDefBegin(MatrixInverse) // {
  10933. static PyGetSetDef py_getsetters[];
  10934. static PyMethodDef tp_methods[];
  10935. static PyObject* getstate(PyObject* self, PyObject*) {
  10936. auto& opdef = reinterpret_cast<PyOp(MatrixInverse)*>(self)->inst();
  10937. static_cast<void>(opdef);
  10938. std::unordered_map<std::string, py::object> state {
  10939. };
  10940. return py::cast(state).release().ptr();
  10941. }
  10942. static PyObject* setstate(PyObject* self, PyObject* args) {
  10943. PyObject* dict = PyTuple_GetItem(args, 0);
  10944. if (!dict) return NULL;
  10945. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10946. auto& opdef = reinterpret_cast<PyOp(MatrixInverse)*>(self)->inst();
  10947. static_cast<void>(opdef);
  10948. Py_RETURN_NONE;
  10949. }
  10950. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10951. // };
  10952. PyOpDefEnd(MatrixInverse)
  10953. int PyOp(MatrixInverse)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10954. return 0;
  10955. }
  10956. PyGetSetDef PyOp(MatrixInverse)::py_getsetters[] = {
  10957. {NULL} /* Sentinel */
  10958. };
  10959. PyMethodDef PyOp(MatrixInverse)::tp_methods[] = {
  10960. {const_cast<char*>("__getstate__"), PyOp(MatrixInverse)::getstate, METH_NOARGS, "MatrixInverse getstate"},
  10961. {const_cast<char*>("__setstate__"), PyOp(MatrixInverse)::setstate, METH_VARARGS, "MatrixInverse setstate"},
  10962. {NULL} /* Sentinel */
  10963. };
  10964. void _init_py_MatrixInverse(py::module m) {
  10965. using py_op = PyOp(MatrixInverse);
  10966. auto& py_type = PyOpType(MatrixInverse);
  10967. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10968. py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixInverse";
  10969. py_type.tp_basicsize = sizeof(PyOp(MatrixInverse));
  10970. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10971. py_type.tp_doc = "MatrixInverse";
  10972. py_type.tp_base = &PyOpType(OpDef);
  10973. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10974. py_type.tp_new = py_new_generic<py_op>;
  10975. py_type.tp_init = py_op::py_init;
  10976. py_type.tp_methods = py_op::tp_methods;
  10977. py_type.tp_getset = py_op::py_getsetters;
  10978. mgb_assert(PyType_Ready(&py_type) >= 0);
  10979. PyType_Modified(&py_type);
  10980. m.add_object("MatrixInverse", reinterpret_cast<PyObject*>(&py_type));
  10981. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixInverse::typeinfo(), &py_type).second);
  10982. }
  10983. void _init_py_MatrixMul_ComputeMode(PyTypeObject& py_type) {
  10984. auto& e_type = EnumWrapper<MatrixMul::ComputeMode>::type;
  10985. Py_INCREF(e_type);
  10986. mgb_assert(PyDict_SetItemString(
  10987. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  10988. }
  10989. void _init_py_MatrixMul_Format(PyTypeObject& py_type) {
  10990. auto& e_type = EnumWrapper<MatrixMul::Format>::type;
  10991. Py_INCREF(e_type);
  10992. mgb_assert(PyDict_SetItemString(
  10993. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  10994. }
  10995. void _init_py_MatrixMul_Strategy(PyTypeObject& py_type) {
  10996. auto& e_type = BitCombinedEnumWrapper<MatrixMul::Strategy>::type;
  10997. Py_INCREF(e_type);
  10998. mgb_assert(PyDict_SetItemString(
  10999. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  11000. }
  11001. PyOpDefBegin(MatrixMul) // {
  11002. static PyGetSetDef py_getsetters[];
  11003. static PyMethodDef tp_methods[];
  11004. static PyObject* getstate(PyObject* self, PyObject*) {
  11005. auto& opdef = reinterpret_cast<PyOp(MatrixMul)*>(self)->inst();
  11006. static_cast<void>(opdef);
  11007. std::unordered_map<std::string, py::object> state {
  11008. {"transposeA", serialization<decltype(opdef.transposeA)>::dump(opdef.transposeA)},
  11009. {"transposeB", serialization<decltype(opdef.transposeB)>::dump(opdef.transposeB)},
  11010. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  11011. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  11012. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  11013. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  11014. {"dimA", serialization<decltype(opdef.dimA)>::dump(opdef.dimA)},
  11015. {"dimB", serialization<decltype(opdef.dimB)>::dump(opdef.dimB)}
  11016. };
  11017. return py::cast(state).release().ptr();
  11018. }
  11019. static PyObject* setstate(PyObject* self, PyObject* args) {
  11020. PyObject* dict = PyTuple_GetItem(args, 0);
  11021. if (!dict) return NULL;
  11022. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11023. auto& opdef = reinterpret_cast<PyOp(MatrixMul)*>(self)->inst();
  11024. static_cast<void>(opdef);
  11025. {
  11026. auto&& iter = state.find("transposeA");
  11027. if (iter != state.end()) {
  11028. opdef.transposeA = serialization<decltype(opdef.transposeA)>::load(iter->second);
  11029. }
  11030. }
  11031. {
  11032. auto&& iter = state.find("transposeB");
  11033. if (iter != state.end()) {
  11034. opdef.transposeB = serialization<decltype(opdef.transposeB)>::load(iter->second);
  11035. }
  11036. }
  11037. {
  11038. auto&& iter = state.find("compute_mode");
  11039. if (iter != state.end()) {
  11040. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  11041. }
  11042. }
  11043. {
  11044. auto&& iter = state.find("format");
  11045. if (iter != state.end()) {
  11046. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  11047. }
  11048. }
  11049. {
  11050. auto&& iter = state.find("strategy");
  11051. if (iter != state.end()) {
  11052. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  11053. }
  11054. }
  11055. {
  11056. auto&& iter = state.find("workspace_limit");
  11057. if (iter != state.end()) {
  11058. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  11059. }
  11060. }
  11061. {
  11062. auto&& iter = state.find("dimA");
  11063. if (iter != state.end()) {
  11064. opdef.dimA = serialization<decltype(opdef.dimA)>::load(iter->second);
  11065. }
  11066. }
  11067. {
  11068. auto&& iter = state.find("dimB");
  11069. if (iter != state.end()) {
  11070. opdef.dimB = serialization<decltype(opdef.dimB)>::load(iter->second);
  11071. }
  11072. }
  11073. Py_RETURN_NONE;
  11074. }
  11075. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11076. // };
  11077. PyOpDefEnd(MatrixMul)
  11078. int PyOp(MatrixMul)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11079. static const char* kwlist[] = {"transposeA", "transposeB", "compute_mode", "format", "strategy", "workspace_limit", "dimA", "dimB", "scope", NULL};
  11080. PyObject *transposeA = NULL, *transposeB = NULL, *compute_mode = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *dimA = NULL, *dimB = NULL, *scope = NULL;
  11081. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &transposeA, &transposeB, &compute_mode, &format, &strategy, &workspace_limit, &dimA, &dimB, &scope))
  11082. return -1;
  11083. if (transposeA) {
  11084. try {
  11085. // TODO: remove this guard which is used for pybind11 implicit conversion
  11086. py::detail::loader_life_support guard{};
  11087. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().transposeA =
  11088. py::cast<decltype(MatrixMul::transposeA)>(py::handle(transposeA));
  11089. } CATCH_ALL(-1)
  11090. }
  11091. if (transposeB) {
  11092. try {
  11093. // TODO: remove this guard which is used for pybind11 implicit conversion
  11094. py::detail::loader_life_support guard{};
  11095. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().transposeB =
  11096. py::cast<decltype(MatrixMul::transposeB)>(py::handle(transposeB));
  11097. } CATCH_ALL(-1)
  11098. }
  11099. if (compute_mode) {
  11100. try {
  11101. // TODO: remove this guard which is used for pybind11 implicit conversion
  11102. py::detail::loader_life_support guard{};
  11103. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().compute_mode =
  11104. py::cast<decltype(MatrixMul::compute_mode)>(py::handle(compute_mode));
  11105. } CATCH_ALL(-1)
  11106. }
  11107. if (format) {
  11108. try {
  11109. // TODO: remove this guard which is used for pybind11 implicit conversion
  11110. py::detail::loader_life_support guard{};
  11111. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().format =
  11112. py::cast<decltype(MatrixMul::format)>(py::handle(format));
  11113. } CATCH_ALL(-1)
  11114. }
  11115. if (strategy) {
  11116. try {
  11117. // TODO: remove this guard which is used for pybind11 implicit conversion
  11118. py::detail::loader_life_support guard{};
  11119. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().strategy =
  11120. py::cast<decltype(MatrixMul::strategy)>(py::handle(strategy));
  11121. } CATCH_ALL(-1)
  11122. }
  11123. if (workspace_limit) {
  11124. try {
  11125. // TODO: remove this guard which is used for pybind11 implicit conversion
  11126. py::detail::loader_life_support guard{};
  11127. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().workspace_limit =
  11128. py::cast<decltype(MatrixMul::workspace_limit)>(py::handle(workspace_limit));
  11129. } CATCH_ALL(-1)
  11130. }
  11131. if (dimA) {
  11132. try {
  11133. // TODO: remove this guard which is used for pybind11 implicit conversion
  11134. py::detail::loader_life_support guard{};
  11135. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().dimA =
  11136. py::cast<decltype(MatrixMul::dimA)>(py::handle(dimA));
  11137. } CATCH_ALL(-1)
  11138. }
  11139. if (dimB) {
  11140. try {
  11141. // TODO: remove this guard which is used for pybind11 implicit conversion
  11142. py::detail::loader_life_support guard{};
  11143. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().dimB =
  11144. py::cast<decltype(MatrixMul::dimB)>(py::handle(dimB));
  11145. } CATCH_ALL(-1)
  11146. }
  11147. if (scope) {
  11148. try {
  11149. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11150. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11151. } CATCH_ALL(-1)
  11152. }
  11153. return 0;
  11154. }
  11155. PyGetSetDef PyOp(MatrixMul)::py_getsetters[] = {
  11156. {const_cast<char*>("transposeA"), py_get_generic(MatrixMul, transposeA), py_set_generic(MatrixMul, transposeA), const_cast<char*>("transposeA"), NULL},
  11157. {const_cast<char*>("transposeB"), py_get_generic(MatrixMul, transposeB), py_set_generic(MatrixMul, transposeB), const_cast<char*>("transposeB"), NULL},
  11158. {const_cast<char*>("compute_mode"), py_get_generic(MatrixMul, compute_mode), py_set_generic(MatrixMul, compute_mode), const_cast<char*>("compute_mode"), NULL},
  11159. {const_cast<char*>("format"), py_get_generic(MatrixMul, format), py_set_generic(MatrixMul, format), const_cast<char*>("format"), NULL},
  11160. {const_cast<char*>("strategy"), py_get_generic(MatrixMul, strategy), py_set_generic(MatrixMul, strategy), const_cast<char*>("strategy"), NULL},
  11161. {const_cast<char*>("workspace_limit"), py_get_generic(MatrixMul, workspace_limit), py_set_generic(MatrixMul, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  11162. {const_cast<char*>("dimA"), py_get_generic(MatrixMul, dimA), py_set_generic(MatrixMul, dimA), const_cast<char*>("dimA"), NULL},
  11163. {const_cast<char*>("dimB"), py_get_generic(MatrixMul, dimB), py_set_generic(MatrixMul, dimB), const_cast<char*>("dimB"), NULL},
  11164. {NULL} /* Sentinel */
  11165. };
  11166. PyMethodDef PyOp(MatrixMul)::tp_methods[] = {
  11167. {const_cast<char*>("__getstate__"), PyOp(MatrixMul)::getstate, METH_NOARGS, "MatrixMul getstate"},
  11168. {const_cast<char*>("__setstate__"), PyOp(MatrixMul)::setstate, METH_VARARGS, "MatrixMul setstate"},
  11169. {NULL} /* Sentinel */
  11170. };
  11171. void _init_py_MatrixMul(py::module m) {
  11172. using py_op = PyOp(MatrixMul);
  11173. auto& py_type = PyOpType(MatrixMul);
  11174. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11175. py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixMul";
  11176. py_type.tp_basicsize = sizeof(PyOp(MatrixMul));
  11177. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11178. py_type.tp_doc = "MatrixMul";
  11179. py_type.tp_base = &PyOpType(OpDef);
  11180. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11181. py_type.tp_new = py_new_generic<py_op>;
  11182. py_type.tp_init = py_op::py_init;
  11183. py_type.tp_methods = py_op::tp_methods;
  11184. py_type.tp_getset = py_op::py_getsetters;
  11185. mgb_assert(PyType_Ready(&py_type) >= 0);
  11186. _init_py_MatrixMul_ComputeMode(py_type);
  11187. _init_py_MatrixMul_Format(py_type);
  11188. _init_py_MatrixMul_Strategy(py_type);
  11189. PyType_Modified(&py_type);
  11190. m.add_object("MatrixMul", reinterpret_cast<PyObject*>(&py_type));
  11191. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixMul::typeinfo(), &py_type).second);
  11192. }
  11193. PyOpDefBegin(MeshIndexing) // {
  11194. static PyGetSetDef py_getsetters[];
  11195. static PyMethodDef tp_methods[];
  11196. static PyObject* getstate(PyObject* self, PyObject*) {
  11197. auto& opdef = reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst();
  11198. static_cast<void>(opdef);
  11199. std::unordered_map<std::string, py::object> state {
  11200. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  11201. };
  11202. return py::cast(state).release().ptr();
  11203. }
  11204. static PyObject* setstate(PyObject* self, PyObject* args) {
  11205. PyObject* dict = PyTuple_GetItem(args, 0);
  11206. if (!dict) return NULL;
  11207. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11208. auto& opdef = reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst();
  11209. static_cast<void>(opdef);
  11210. {
  11211. auto&& iter = state.find("items");
  11212. if (iter != state.end()) {
  11213. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  11214. }
  11215. }
  11216. Py_RETURN_NONE;
  11217. }
  11218. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11219. // };
  11220. PyOpDefEnd(MeshIndexing)
  11221. int PyOp(MeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11222. static const char* kwlist[] = {"items", "scope", NULL};
  11223. PyObject *items = NULL, *scope = NULL;
  11224. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  11225. return -1;
  11226. if (items) {
  11227. try {
  11228. // TODO: remove this guard which is used for pybind11 implicit conversion
  11229. py::detail::loader_life_support guard{};
  11230. reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst().items =
  11231. py::cast<decltype(MeshIndexing::items)>(py::handle(items));
  11232. } CATCH_ALL(-1)
  11233. }
  11234. if (scope) {
  11235. try {
  11236. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11237. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11238. } CATCH_ALL(-1)
  11239. }
  11240. return 0;
  11241. }
  11242. PyGetSetDef PyOp(MeshIndexing)::py_getsetters[] = {
  11243. {const_cast<char*>("items"), py_get_generic(MeshIndexing, items), py_set_generic(MeshIndexing, items), const_cast<char*>("items"), NULL},
  11244. {NULL} /* Sentinel */
  11245. };
  11246. PyMethodDef PyOp(MeshIndexing)::tp_methods[] = {
  11247. {const_cast<char*>("__getstate__"), PyOp(MeshIndexing)::getstate, METH_NOARGS, "MeshIndexing getstate"},
  11248. {const_cast<char*>("__setstate__"), PyOp(MeshIndexing)::setstate, METH_VARARGS, "MeshIndexing setstate"},
  11249. {NULL} /* Sentinel */
  11250. };
  11251. void _init_py_MeshIndexing(py::module m) {
  11252. using py_op = PyOp(MeshIndexing);
  11253. auto& py_type = PyOpType(MeshIndexing);
  11254. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11255. py_type.tp_name = "megengine.core._imperative_rt.ops.MeshIndexing";
  11256. py_type.tp_basicsize = sizeof(PyOp(MeshIndexing));
  11257. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11258. py_type.tp_doc = "MeshIndexing";
  11259. py_type.tp_base = &PyOpType(OpDef);
  11260. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11261. py_type.tp_new = py_new_generic<py_op>;
  11262. py_type.tp_init = py_op::py_init;
  11263. py_type.tp_methods = py_op::tp_methods;
  11264. py_type.tp_getset = py_op::py_getsetters;
  11265. mgb_assert(PyType_Ready(&py_type) >= 0);
  11266. PyType_Modified(&py_type);
  11267. m.add_object("MeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  11268. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MeshIndexing::typeinfo(), &py_type).second);
  11269. }
  11270. PyOpDefBegin(NMSKeep) // {
  11271. static PyGetSetDef py_getsetters[];
  11272. static PyMethodDef tp_methods[];
  11273. static PyObject* getstate(PyObject* self, PyObject*) {
  11274. auto& opdef = reinterpret_cast<PyOp(NMSKeep)*>(self)->inst();
  11275. static_cast<void>(opdef);
  11276. std::unordered_map<std::string, py::object> state {
  11277. {"iou_thresh", serialization<decltype(opdef.iou_thresh)>::dump(opdef.iou_thresh)},
  11278. {"max_output", serialization<decltype(opdef.max_output)>::dump(opdef.max_output)}
  11279. };
  11280. return py::cast(state).release().ptr();
  11281. }
  11282. static PyObject* setstate(PyObject* self, PyObject* args) {
  11283. PyObject* dict = PyTuple_GetItem(args, 0);
  11284. if (!dict) return NULL;
  11285. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11286. auto& opdef = reinterpret_cast<PyOp(NMSKeep)*>(self)->inst();
  11287. static_cast<void>(opdef);
  11288. {
  11289. auto&& iter = state.find("iou_thresh");
  11290. if (iter != state.end()) {
  11291. opdef.iou_thresh = serialization<decltype(opdef.iou_thresh)>::load(iter->second);
  11292. }
  11293. }
  11294. {
  11295. auto&& iter = state.find("max_output");
  11296. if (iter != state.end()) {
  11297. opdef.max_output = serialization<decltype(opdef.max_output)>::load(iter->second);
  11298. }
  11299. }
  11300. Py_RETURN_NONE;
  11301. }
  11302. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11303. // };
  11304. PyOpDefEnd(NMSKeep)
  11305. int PyOp(NMSKeep)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11306. static const char* kwlist[] = {"iou_thresh", "max_output", "scope", NULL};
  11307. PyObject *iou_thresh = NULL, *max_output = NULL, *scope = NULL;
  11308. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &iou_thresh, &max_output, &scope))
  11309. return -1;
  11310. if (iou_thresh) {
  11311. try {
  11312. // TODO: remove this guard which is used for pybind11 implicit conversion
  11313. py::detail::loader_life_support guard{};
  11314. reinterpret_cast<PyOp(NMSKeep)*>(self)->inst().iou_thresh =
  11315. py::cast<decltype(NMSKeep::iou_thresh)>(py::handle(iou_thresh));
  11316. } CATCH_ALL(-1)
  11317. }
  11318. if (max_output) {
  11319. try {
  11320. // TODO: remove this guard which is used for pybind11 implicit conversion
  11321. py::detail::loader_life_support guard{};
  11322. reinterpret_cast<PyOp(NMSKeep)*>(self)->inst().max_output =
  11323. py::cast<decltype(NMSKeep::max_output)>(py::handle(max_output));
  11324. } CATCH_ALL(-1)
  11325. }
  11326. if (scope) {
  11327. try {
  11328. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11329. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11330. } CATCH_ALL(-1)
  11331. }
  11332. return 0;
  11333. }
  11334. PyGetSetDef PyOp(NMSKeep)::py_getsetters[] = {
  11335. {const_cast<char*>("iou_thresh"), py_get_generic(NMSKeep, iou_thresh), py_set_generic(NMSKeep, iou_thresh), const_cast<char*>("iou_thresh"), NULL},
  11336. {const_cast<char*>("max_output"), py_get_generic(NMSKeep, max_output), py_set_generic(NMSKeep, max_output), const_cast<char*>("max_output"), NULL},
  11337. {NULL} /* Sentinel */
  11338. };
  11339. PyMethodDef PyOp(NMSKeep)::tp_methods[] = {
  11340. {const_cast<char*>("__getstate__"), PyOp(NMSKeep)::getstate, METH_NOARGS, "NMSKeep getstate"},
  11341. {const_cast<char*>("__setstate__"), PyOp(NMSKeep)::setstate, METH_VARARGS, "NMSKeep setstate"},
  11342. {NULL} /* Sentinel */
  11343. };
  11344. void _init_py_NMSKeep(py::module m) {
  11345. using py_op = PyOp(NMSKeep);
  11346. auto& py_type = PyOpType(NMSKeep);
  11347. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11348. py_type.tp_name = "megengine.core._imperative_rt.ops.NMSKeep";
  11349. py_type.tp_basicsize = sizeof(PyOp(NMSKeep));
  11350. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11351. py_type.tp_doc = "NMSKeep";
  11352. py_type.tp_base = &PyOpType(OpDef);
  11353. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11354. py_type.tp_new = py_new_generic<py_op>;
  11355. py_type.tp_init = py_op::py_init;
  11356. py_type.tp_methods = py_op::tp_methods;
  11357. py_type.tp_getset = py_op::py_getsetters;
  11358. mgb_assert(PyType_Ready(&py_type) >= 0);
  11359. PyType_Modified(&py_type);
  11360. m.add_object("NMSKeep", reinterpret_cast<PyObject*>(&py_type));
  11361. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NMSKeep::typeinfo(), &py_type).second);
  11362. }
  11363. PyOpDefBegin(NvOf) // {
  11364. static PyGetSetDef py_getsetters[];
  11365. static PyMethodDef tp_methods[];
  11366. static PyObject* getstate(PyObject* self, PyObject*) {
  11367. auto& opdef = reinterpret_cast<PyOp(NvOf)*>(self)->inst();
  11368. static_cast<void>(opdef);
  11369. std::unordered_map<std::string, py::object> state {
  11370. {"precision", serialization<decltype(opdef.precision)>::dump(opdef.precision)}
  11371. };
  11372. return py::cast(state).release().ptr();
  11373. }
  11374. static PyObject* setstate(PyObject* self, PyObject* args) {
  11375. PyObject* dict = PyTuple_GetItem(args, 0);
  11376. if (!dict) return NULL;
  11377. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11378. auto& opdef = reinterpret_cast<PyOp(NvOf)*>(self)->inst();
  11379. static_cast<void>(opdef);
  11380. {
  11381. auto&& iter = state.find("precision");
  11382. if (iter != state.end()) {
  11383. opdef.precision = serialization<decltype(opdef.precision)>::load(iter->second);
  11384. }
  11385. }
  11386. Py_RETURN_NONE;
  11387. }
  11388. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11389. // };
  11390. PyOpDefEnd(NvOf)
  11391. int PyOp(NvOf)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11392. static const char* kwlist[] = {"precision", "scope", NULL};
  11393. PyObject *precision = NULL, *scope = NULL;
  11394. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &precision, &scope))
  11395. return -1;
  11396. if (precision) {
  11397. try {
  11398. // TODO: remove this guard which is used for pybind11 implicit conversion
  11399. py::detail::loader_life_support guard{};
  11400. reinterpret_cast<PyOp(NvOf)*>(self)->inst().precision =
  11401. py::cast<decltype(NvOf::precision)>(py::handle(precision));
  11402. } CATCH_ALL(-1)
  11403. }
  11404. if (scope) {
  11405. try {
  11406. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11407. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11408. } CATCH_ALL(-1)
  11409. }
  11410. return 0;
  11411. }
  11412. PyGetSetDef PyOp(NvOf)::py_getsetters[] = {
  11413. {const_cast<char*>("precision"), py_get_generic(NvOf, precision), py_set_generic(NvOf, precision), const_cast<char*>("precision"), NULL},
  11414. {NULL} /* Sentinel */
  11415. };
  11416. PyMethodDef PyOp(NvOf)::tp_methods[] = {
  11417. {const_cast<char*>("__getstate__"), PyOp(NvOf)::getstate, METH_NOARGS, "NvOf getstate"},
  11418. {const_cast<char*>("__setstate__"), PyOp(NvOf)::setstate, METH_VARARGS, "NvOf setstate"},
  11419. {NULL} /* Sentinel */
  11420. };
  11421. void _init_py_NvOf(py::module m) {
  11422. using py_op = PyOp(NvOf);
  11423. auto& py_type = PyOpType(NvOf);
  11424. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11425. py_type.tp_name = "megengine.core._imperative_rt.ops.NvOf";
  11426. py_type.tp_basicsize = sizeof(PyOp(NvOf));
  11427. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11428. py_type.tp_doc = "NvOf";
  11429. py_type.tp_base = &PyOpType(OpDef);
  11430. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11431. py_type.tp_new = py_new_generic<py_op>;
  11432. py_type.tp_init = py_op::py_init;
  11433. py_type.tp_methods = py_op::tp_methods;
  11434. py_type.tp_getset = py_op::py_getsetters;
  11435. mgb_assert(PyType_Ready(&py_type) >= 0);
  11436. PyType_Modified(&py_type);
  11437. m.add_object("NvOf", reinterpret_cast<PyObject*>(&py_type));
  11438. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NvOf::typeinfo(), &py_type).second);
  11439. }
  11440. template<> struct EnumTrait<Padding::PaddingMode> {
  11441. static constexpr const char *name = "Padding.PaddingMode";
  11442. static constexpr std::underlying_type_t<Padding::PaddingMode> max = 3 - 1;
  11443. };
  11444. template<> PyTypeObject* EnumWrapper<Padding::PaddingMode>::type = nullptr;
  11445. template<> const char*
  11446. EnumWrapper<Padding::PaddingMode>::members[] = {"REPLICATE", "REFLECT", "CONSTANT"};
  11447. template<> std::unordered_map<std::string, Padding::PaddingMode>
  11448. EnumWrapper<Padding::PaddingMode>::mem2value = {{normalize_enum("REPLICATE"), Padding::PaddingMode::REPLICATE}, {normalize_enum("REFLECT"), Padding::PaddingMode::REFLECT}, {normalize_enum("CONSTANT"), Padding::PaddingMode::CONSTANT}};
  11449. template<> PyObject* EnumWrapper<Padding::PaddingMode>::pyobj_insts[3] = {nullptr};
  11450. void _init_py_Padding_PaddingMode(PyTypeObject& py_type) {
  11451. auto& e_type = EnumWrapper<Padding::PaddingMode>::type;
  11452. static PyMethodDef tp_methods[] = {
  11453. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Padding::PaddingMode>::py_dump, METH_NOARGS, NULL},
  11454. {NULL} /* Sentinel */
  11455. };
  11456. static PyType_Slot slots[] = {
  11457. {Py_tp_repr, (void*)EnumWrapper<Padding::PaddingMode>::py_repr},
  11458. {Py_tp_richcompare, (void*)EnumWrapper<Padding::PaddingMode>::tp_richcompare},
  11459. {Py_tp_methods, tp_methods},
  11460. {0, NULL}
  11461. };
  11462. static PyType_Spec spec = {
  11463. // name
  11464. "megengine.core._imperative_rt.ops.Padding.PaddingMode",
  11465. // basicsize
  11466. sizeof(EnumWrapper<Padding::PaddingMode>),
  11467. // itemsize
  11468. 0,
  11469. // flags
  11470. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  11471. // slots
  11472. slots
  11473. };
  11474. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  11475. mgb_assert(
  11476. e_type->tp_setattro(
  11477. reinterpret_cast<PyObject*>(e_type),
  11478. py::cast("__name__").release().ptr(),
  11479. py::cast("PaddingMode").release().ptr()) >= 0);
  11480. mgb_assert(
  11481. e_type->tp_setattro(
  11482. reinterpret_cast<PyObject*>(e_type),
  11483. py::cast("__module__").release().ptr(),
  11484. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  11485. mgb_assert(
  11486. e_type->tp_setattro(
  11487. reinterpret_cast<PyObject*>(e_type),
  11488. py::cast("__qualname__").release().ptr(),
  11489. py::cast("Padding.PaddingMode").release().ptr()) >= 0);
  11490. {
  11491. PyObject* inst = e_type->tp_alloc(e_type, 0);
  11492. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::REPLICATE;
  11493. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0);
  11494. EnumWrapper<Padding::PaddingMode>::pyobj_insts[0] = inst;
  11495. }{
  11496. PyObject* inst = e_type->tp_alloc(e_type, 0);
  11497. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::REFLECT;
  11498. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0);
  11499. EnumWrapper<Padding::PaddingMode>::pyobj_insts[1] = inst;
  11500. }{
  11501. PyObject* inst = e_type->tp_alloc(e_type, 0);
  11502. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::CONSTANT;
  11503. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0);
  11504. EnumWrapper<Padding::PaddingMode>::pyobj_insts[2] = inst;
  11505. }
  11506. Py_INCREF(e_type);
  11507. mgb_assert(PyDict_SetItemString(
  11508. py_type.tp_dict, "PaddingMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  11509. }
  11510. PyOpDefBegin(Padding) // {
  11511. static PyGetSetDef py_getsetters[];
  11512. static PyMethodDef tp_methods[];
  11513. static PyObject* getstate(PyObject* self, PyObject*) {
  11514. auto& opdef = reinterpret_cast<PyOp(Padding)*>(self)->inst();
  11515. static_cast<void>(opdef);
  11516. std::unordered_map<std::string, py::object> state {
  11517. {"front_offset_dim0", serialization<decltype(opdef.front_offset_dim0)>::dump(opdef.front_offset_dim0)},
  11518. {"front_offset_dim1", serialization<decltype(opdef.front_offset_dim1)>::dump(opdef.front_offset_dim1)},
  11519. {"front_offset_dim2", serialization<decltype(opdef.front_offset_dim2)>::dump(opdef.front_offset_dim2)},
  11520. {"front_offset_dim3", serialization<decltype(opdef.front_offset_dim3)>::dump(opdef.front_offset_dim3)},
  11521. {"front_offset_dim4", serialization<decltype(opdef.front_offset_dim4)>::dump(opdef.front_offset_dim4)},
  11522. {"front_offset_dim5", serialization<decltype(opdef.front_offset_dim5)>::dump(opdef.front_offset_dim5)},
  11523. {"front_offset_dim6", serialization<decltype(opdef.front_offset_dim6)>::dump(opdef.front_offset_dim6)},
  11524. {"back_offset_dim0", serialization<decltype(opdef.back_offset_dim0)>::dump(opdef.back_offset_dim0)},
  11525. {"back_offset_dim1", serialization<decltype(opdef.back_offset_dim1)>::dump(opdef.back_offset_dim1)},
  11526. {"back_offset_dim2", serialization<decltype(opdef.back_offset_dim2)>::dump(opdef.back_offset_dim2)},
  11527. {"back_offset_dim3", serialization<decltype(opdef.back_offset_dim3)>::dump(opdef.back_offset_dim3)},
  11528. {"back_offset_dim4", serialization<decltype(opdef.back_offset_dim4)>::dump(opdef.back_offset_dim4)},
  11529. {"back_offset_dim5", serialization<decltype(opdef.back_offset_dim5)>::dump(opdef.back_offset_dim5)},
  11530. {"back_offset_dim6", serialization<decltype(opdef.back_offset_dim6)>::dump(opdef.back_offset_dim6)},
  11531. {"padding_val", serialization<decltype(opdef.padding_val)>::dump(opdef.padding_val)},
  11532. {"padding_mode", serialization<decltype(opdef.padding_mode)>::dump(opdef.padding_mode)}
  11533. };
  11534. return py::cast(state).release().ptr();
  11535. }
  11536. static PyObject* setstate(PyObject* self, PyObject* args) {
  11537. PyObject* dict = PyTuple_GetItem(args, 0);
  11538. if (!dict) return NULL;
  11539. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11540. auto& opdef = reinterpret_cast<PyOp(Padding)*>(self)->inst();
  11541. static_cast<void>(opdef);
  11542. {
  11543. auto&& iter = state.find("front_offset_dim0");
  11544. if (iter != state.end()) {
  11545. opdef.front_offset_dim0 = serialization<decltype(opdef.front_offset_dim0)>::load(iter->second);
  11546. }
  11547. }
  11548. {
  11549. auto&& iter = state.find("front_offset_dim1");
  11550. if (iter != state.end()) {
  11551. opdef.front_offset_dim1 = serialization<decltype(opdef.front_offset_dim1)>::load(iter->second);
  11552. }
  11553. }
  11554. {
  11555. auto&& iter = state.find("front_offset_dim2");
  11556. if (iter != state.end()) {
  11557. opdef.front_offset_dim2 = serialization<decltype(opdef.front_offset_dim2)>::load(iter->second);
  11558. }
  11559. }
  11560. {
  11561. auto&& iter = state.find("front_offset_dim3");
  11562. if (iter != state.end()) {
  11563. opdef.front_offset_dim3 = serialization<decltype(opdef.front_offset_dim3)>::load(iter->second);
  11564. }
  11565. }
  11566. {
  11567. auto&& iter = state.find("front_offset_dim4");
  11568. if (iter != state.end()) {
  11569. opdef.front_offset_dim4 = serialization<decltype(opdef.front_offset_dim4)>::load(iter->second);
  11570. }
  11571. }
  11572. {
  11573. auto&& iter = state.find("front_offset_dim5");
  11574. if (iter != state.end()) {
  11575. opdef.front_offset_dim5 = serialization<decltype(opdef.front_offset_dim5)>::load(iter->second);
  11576. }
  11577. }
  11578. {
  11579. auto&& iter = state.find("front_offset_dim6");
  11580. if (iter != state.end()) {
  11581. opdef.front_offset_dim6 = serialization<decltype(opdef.front_offset_dim6)>::load(iter->second);
  11582. }
  11583. }
  11584. {
  11585. auto&& iter = state.find("back_offset_dim0");
  11586. if (iter != state.end()) {
  11587. opdef.back_offset_dim0 = serialization<decltype(opdef.back_offset_dim0)>::load(iter->second);
  11588. }
  11589. }
  11590. {
  11591. auto&& iter = state.find("back_offset_dim1");
  11592. if (iter != state.end()) {
  11593. opdef.back_offset_dim1 = serialization<decltype(opdef.back_offset_dim1)>::load(iter->second);
  11594. }
  11595. }
  11596. {
  11597. auto&& iter = state.find("back_offset_dim2");
  11598. if (iter != state.end()) {
  11599. opdef.back_offset_dim2 = serialization<decltype(opdef.back_offset_dim2)>::load(iter->second);
  11600. }
  11601. }
  11602. {
  11603. auto&& iter = state.find("back_offset_dim3");
  11604. if (iter != state.end()) {
  11605. opdef.back_offset_dim3 = serialization<decltype(opdef.back_offset_dim3)>::load(iter->second);
  11606. }
  11607. }
  11608. {
  11609. auto&& iter = state.find("back_offset_dim4");
  11610. if (iter != state.end()) {
  11611. opdef.back_offset_dim4 = serialization<decltype(opdef.back_offset_dim4)>::load(iter->second);
  11612. }
  11613. }
  11614. {
  11615. auto&& iter = state.find("back_offset_dim5");
  11616. if (iter != state.end()) {
  11617. opdef.back_offset_dim5 = serialization<decltype(opdef.back_offset_dim5)>::load(iter->second);
  11618. }
  11619. }
  11620. {
  11621. auto&& iter = state.find("back_offset_dim6");
  11622. if (iter != state.end()) {
  11623. opdef.back_offset_dim6 = serialization<decltype(opdef.back_offset_dim6)>::load(iter->second);
  11624. }
  11625. }
  11626. {
  11627. auto&& iter = state.find("padding_val");
  11628. if (iter != state.end()) {
  11629. opdef.padding_val = serialization<decltype(opdef.padding_val)>::load(iter->second);
  11630. }
  11631. }
  11632. {
  11633. auto&& iter = state.find("padding_mode");
  11634. if (iter != state.end()) {
  11635. opdef.padding_mode = serialization<decltype(opdef.padding_mode)>::load(iter->second);
  11636. }
  11637. }
  11638. Py_RETURN_NONE;
  11639. }
  11640. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11641. // };
  11642. PyOpDefEnd(Padding)
  11643. int PyOp(Padding)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11644. static const char* kwlist[] = {"front_offset_dim0", "front_offset_dim1", "front_offset_dim2", "front_offset_dim3", "front_offset_dim4", "front_offset_dim5", "front_offset_dim6", "back_offset_dim0", "back_offset_dim1", "back_offset_dim2", "back_offset_dim3", "back_offset_dim4", "back_offset_dim5", "back_offset_dim6", "padding_val", "padding_mode", "scope", NULL};
  11645. PyObject *front_offset_dim0 = NULL, *front_offset_dim1 = NULL, *front_offset_dim2 = NULL, *front_offset_dim3 = NULL, *front_offset_dim4 = NULL, *front_offset_dim5 = NULL, *front_offset_dim6 = NULL, *back_offset_dim0 = NULL, *back_offset_dim1 = NULL, *back_offset_dim2 = NULL, *back_offset_dim3 = NULL, *back_offset_dim4 = NULL, *back_offset_dim5 = NULL, *back_offset_dim6 = NULL, *padding_val = NULL, *padding_mode = NULL, *scope = NULL;
  11646. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOOO", const_cast<char**>(kwlist), &front_offset_dim0, &front_offset_dim1, &front_offset_dim2, &front_offset_dim3, &front_offset_dim4, &front_offset_dim5, &front_offset_dim6, &back_offset_dim0, &back_offset_dim1, &back_offset_dim2, &back_offset_dim3, &back_offset_dim4, &back_offset_dim5, &back_offset_dim6, &padding_val, &padding_mode, &scope))
  11647. return -1;
  11648. if (front_offset_dim0) {
  11649. try {
  11650. // TODO: remove this guard which is used for pybind11 implicit conversion
  11651. py::detail::loader_life_support guard{};
  11652. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim0 =
  11653. py::cast<decltype(Padding::front_offset_dim0)>(py::handle(front_offset_dim0));
  11654. } CATCH_ALL(-1)
  11655. }
  11656. if (front_offset_dim1) {
  11657. try {
  11658. // TODO: remove this guard which is used for pybind11 implicit conversion
  11659. py::detail::loader_life_support guard{};
  11660. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim1 =
  11661. py::cast<decltype(Padding::front_offset_dim1)>(py::handle(front_offset_dim1));
  11662. } CATCH_ALL(-1)
  11663. }
  11664. if (front_offset_dim2) {
  11665. try {
  11666. // TODO: remove this guard which is used for pybind11 implicit conversion
  11667. py::detail::loader_life_support guard{};
  11668. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim2 =
  11669. py::cast<decltype(Padding::front_offset_dim2)>(py::handle(front_offset_dim2));
  11670. } CATCH_ALL(-1)
  11671. }
  11672. if (front_offset_dim3) {
  11673. try {
  11674. // TODO: remove this guard which is used for pybind11 implicit conversion
  11675. py::detail::loader_life_support guard{};
  11676. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim3 =
  11677. py::cast<decltype(Padding::front_offset_dim3)>(py::handle(front_offset_dim3));
  11678. } CATCH_ALL(-1)
  11679. }
  11680. if (front_offset_dim4) {
  11681. try {
  11682. // TODO: remove this guard which is used for pybind11 implicit conversion
  11683. py::detail::loader_life_support guard{};
  11684. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim4 =
  11685. py::cast<decltype(Padding::front_offset_dim4)>(py::handle(front_offset_dim4));
  11686. } CATCH_ALL(-1)
  11687. }
  11688. if (front_offset_dim5) {
  11689. try {
  11690. // TODO: remove this guard which is used for pybind11 implicit conversion
  11691. py::detail::loader_life_support guard{};
  11692. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim5 =
  11693. py::cast<decltype(Padding::front_offset_dim5)>(py::handle(front_offset_dim5));
  11694. } CATCH_ALL(-1)
  11695. }
  11696. if (front_offset_dim6) {
  11697. try {
  11698. // TODO: remove this guard which is used for pybind11 implicit conversion
  11699. py::detail::loader_life_support guard{};
  11700. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim6 =
  11701. py::cast<decltype(Padding::front_offset_dim6)>(py::handle(front_offset_dim6));
  11702. } CATCH_ALL(-1)
  11703. }
  11704. if (back_offset_dim0) {
  11705. try {
  11706. // TODO: remove this guard which is used for pybind11 implicit conversion
  11707. py::detail::loader_life_support guard{};
  11708. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim0 =
  11709. py::cast<decltype(Padding::back_offset_dim0)>(py::handle(back_offset_dim0));
  11710. } CATCH_ALL(-1)
  11711. }
  11712. if (back_offset_dim1) {
  11713. try {
  11714. // TODO: remove this guard which is used for pybind11 implicit conversion
  11715. py::detail::loader_life_support guard{};
  11716. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim1 =
  11717. py::cast<decltype(Padding::back_offset_dim1)>(py::handle(back_offset_dim1));
  11718. } CATCH_ALL(-1)
  11719. }
  11720. if (back_offset_dim2) {
  11721. try {
  11722. // TODO: remove this guard which is used for pybind11 implicit conversion
  11723. py::detail::loader_life_support guard{};
  11724. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim2 =
  11725. py::cast<decltype(Padding::back_offset_dim2)>(py::handle(back_offset_dim2));
  11726. } CATCH_ALL(-1)
  11727. }
  11728. if (back_offset_dim3) {
  11729. try {
  11730. // TODO: remove this guard which is used for pybind11 implicit conversion
  11731. py::detail::loader_life_support guard{};
  11732. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim3 =
  11733. py::cast<decltype(Padding::back_offset_dim3)>(py::handle(back_offset_dim3));
  11734. } CATCH_ALL(-1)
  11735. }
  11736. if (back_offset_dim4) {
  11737. try {
  11738. // TODO: remove this guard which is used for pybind11 implicit conversion
  11739. py::detail::loader_life_support guard{};
  11740. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim4 =
  11741. py::cast<decltype(Padding::back_offset_dim4)>(py::handle(back_offset_dim4));
  11742. } CATCH_ALL(-1)
  11743. }
  11744. if (back_offset_dim5) {
  11745. try {
  11746. // TODO: remove this guard which is used for pybind11 implicit conversion
  11747. py::detail::loader_life_support guard{};
  11748. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim5 =
  11749. py::cast<decltype(Padding::back_offset_dim5)>(py::handle(back_offset_dim5));
  11750. } CATCH_ALL(-1)
  11751. }
  11752. if (back_offset_dim6) {
  11753. try {
  11754. // TODO: remove this guard which is used for pybind11 implicit conversion
  11755. py::detail::loader_life_support guard{};
  11756. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim6 =
  11757. py::cast<decltype(Padding::back_offset_dim6)>(py::handle(back_offset_dim6));
  11758. } CATCH_ALL(-1)
  11759. }
  11760. if (padding_val) {
  11761. try {
  11762. // TODO: remove this guard which is used for pybind11 implicit conversion
  11763. py::detail::loader_life_support guard{};
  11764. reinterpret_cast<PyOp(Padding)*>(self)->inst().padding_val =
  11765. py::cast<decltype(Padding::padding_val)>(py::handle(padding_val));
  11766. } CATCH_ALL(-1)
  11767. }
  11768. if (padding_mode) {
  11769. try {
  11770. // TODO: remove this guard which is used for pybind11 implicit conversion
  11771. py::detail::loader_life_support guard{};
  11772. reinterpret_cast<PyOp(Padding)*>(self)->inst().padding_mode =
  11773. py::cast<decltype(Padding::padding_mode)>(py::handle(padding_mode));
  11774. } CATCH_ALL(-1)
  11775. }
  11776. if (scope) {
  11777. try {
  11778. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11779. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11780. } CATCH_ALL(-1)
  11781. }
  11782. return 0;
  11783. }
  11784. PyGetSetDef PyOp(Padding)::py_getsetters[] = {
  11785. {const_cast<char*>("front_offset_dim0"), py_get_generic(Padding, front_offset_dim0), py_set_generic(Padding, front_offset_dim0), const_cast<char*>("front_offset_dim0"), NULL},
  11786. {const_cast<char*>("front_offset_dim1"), py_get_generic(Padding, front_offset_dim1), py_set_generic(Padding, front_offset_dim1), const_cast<char*>("front_offset_dim1"), NULL},
  11787. {const_cast<char*>("front_offset_dim2"), py_get_generic(Padding, front_offset_dim2), py_set_generic(Padding, front_offset_dim2), const_cast<char*>("front_offset_dim2"), NULL},
  11788. {const_cast<char*>("front_offset_dim3"), py_get_generic(Padding, front_offset_dim3), py_set_generic(Padding, front_offset_dim3), const_cast<char*>("front_offset_dim3"), NULL},
  11789. {const_cast<char*>("front_offset_dim4"), py_get_generic(Padding, front_offset_dim4), py_set_generic(Padding, front_offset_dim4), const_cast<char*>("front_offset_dim4"), NULL},
  11790. {const_cast<char*>("front_offset_dim5"), py_get_generic(Padding, front_offset_dim5), py_set_generic(Padding, front_offset_dim5), const_cast<char*>("front_offset_dim5"), NULL},
  11791. {const_cast<char*>("front_offset_dim6"), py_get_generic(Padding, front_offset_dim6), py_set_generic(Padding, front_offset_dim6), const_cast<char*>("front_offset_dim6"), NULL},
  11792. {const_cast<char*>("back_offset_dim0"), py_get_generic(Padding, back_offset_dim0), py_set_generic(Padding, back_offset_dim0), const_cast<char*>("back_offset_dim0"), NULL},
  11793. {const_cast<char*>("back_offset_dim1"), py_get_generic(Padding, back_offset_dim1), py_set_generic(Padding, back_offset_dim1), const_cast<char*>("back_offset_dim1"), NULL},
  11794. {const_cast<char*>("back_offset_dim2"), py_get_generic(Padding, back_offset_dim2), py_set_generic(Padding, back_offset_dim2), const_cast<char*>("back_offset_dim2"), NULL},
  11795. {const_cast<char*>("back_offset_dim3"), py_get_generic(Padding, back_offset_dim3), py_set_generic(Padding, back_offset_dim3), const_cast<char*>("back_offset_dim3"), NULL},
  11796. {const_cast<char*>("back_offset_dim4"), py_get_generic(Padding, back_offset_dim4), py_set_generic(Padding, back_offset_dim4), const_cast<char*>("back_offset_dim4"), NULL},
  11797. {const_cast<char*>("back_offset_dim5"), py_get_generic(Padding, back_offset_dim5), py_set_generic(Padding, back_offset_dim5), const_cast<char*>("back_offset_dim5"), NULL},
  11798. {const_cast<char*>("back_offset_dim6"), py_get_generic(Padding, back_offset_dim6), py_set_generic(Padding, back_offset_dim6), const_cast<char*>("back_offset_dim6"), NULL},
  11799. {const_cast<char*>("padding_val"), py_get_generic(Padding, padding_val), py_set_generic(Padding, padding_val), const_cast<char*>("padding_val"), NULL},
  11800. {const_cast<char*>("padding_mode"), py_get_generic(Padding, padding_mode), py_set_generic(Padding, padding_mode), const_cast<char*>("padding_mode"), NULL},
  11801. {NULL} /* Sentinel */
  11802. };
  11803. PyMethodDef PyOp(Padding)::tp_methods[] = {
  11804. {const_cast<char*>("__getstate__"), PyOp(Padding)::getstate, METH_NOARGS, "Padding getstate"},
  11805. {const_cast<char*>("__setstate__"), PyOp(Padding)::setstate, METH_VARARGS, "Padding setstate"},
  11806. {NULL} /* Sentinel */
  11807. };
  11808. void _init_py_Padding(py::module m) {
  11809. using py_op = PyOp(Padding);
  11810. auto& py_type = PyOpType(Padding);
  11811. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11812. py_type.tp_name = "megengine.core._imperative_rt.ops.Padding";
  11813. py_type.tp_basicsize = sizeof(PyOp(Padding));
  11814. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11815. py_type.tp_doc = "Padding";
  11816. py_type.tp_base = &PyOpType(OpDef);
  11817. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11818. py_type.tp_new = py_new_generic<py_op>;
  11819. py_type.tp_init = py_op::py_init;
  11820. py_type.tp_methods = py_op::tp_methods;
  11821. py_type.tp_getset = py_op::py_getsetters;
  11822. mgb_assert(PyType_Ready(&py_type) >= 0);
  11823. _init_py_Padding_PaddingMode(py_type);
  11824. PyType_Modified(&py_type);
  11825. m.add_object("Padding", reinterpret_cast<PyObject*>(&py_type));
  11826. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Padding::typeinfo(), &py_type).second);
  11827. }
  11828. PyOpDefBegin(ParamPackConcat) // {
  11829. static PyGetSetDef py_getsetters[];
  11830. static PyMethodDef tp_methods[];
  11831. static PyObject* getstate(PyObject* self, PyObject*) {
  11832. auto& opdef = reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst();
  11833. static_cast<void>(opdef);
  11834. std::unordered_map<std::string, py::object> state {
  11835. {"offsets", serialization<decltype(opdef.offsets)>::dump(opdef.offsets)}
  11836. };
  11837. return py::cast(state).release().ptr();
  11838. }
  11839. static PyObject* setstate(PyObject* self, PyObject* args) {
  11840. PyObject* dict = PyTuple_GetItem(args, 0);
  11841. if (!dict) return NULL;
  11842. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11843. auto& opdef = reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst();
  11844. static_cast<void>(opdef);
  11845. {
  11846. auto&& iter = state.find("offsets");
  11847. if (iter != state.end()) {
  11848. opdef.offsets = serialization<decltype(opdef.offsets)>::load(iter->second);
  11849. }
  11850. }
  11851. Py_RETURN_NONE;
  11852. }
  11853. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11854. // };
  11855. PyOpDefEnd(ParamPackConcat)
  11856. int PyOp(ParamPackConcat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11857. static const char* kwlist[] = {"offsets", "scope", NULL};
  11858. PyObject *offsets = NULL, *scope = NULL;
  11859. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &offsets, &scope))
  11860. return -1;
  11861. if (offsets) {
  11862. try {
  11863. // TODO: remove this guard which is used for pybind11 implicit conversion
  11864. py::detail::loader_life_support guard{};
  11865. reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst().offsets =
  11866. py::cast<decltype(ParamPackConcat::offsets)>(py::handle(offsets));
  11867. } CATCH_ALL(-1)
  11868. }
  11869. if (scope) {
  11870. try {
  11871. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11872. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11873. } CATCH_ALL(-1)
  11874. }
  11875. return 0;
  11876. }
  11877. PyGetSetDef PyOp(ParamPackConcat)::py_getsetters[] = {
  11878. {const_cast<char*>("offsets"), py_get_generic(ParamPackConcat, offsets), py_set_generic(ParamPackConcat, offsets), const_cast<char*>("offsets"), NULL},
  11879. {NULL} /* Sentinel */
  11880. };
  11881. PyMethodDef PyOp(ParamPackConcat)::tp_methods[] = {
  11882. {const_cast<char*>("__getstate__"), PyOp(ParamPackConcat)::getstate, METH_NOARGS, "ParamPackConcat getstate"},
  11883. {const_cast<char*>("__setstate__"), PyOp(ParamPackConcat)::setstate, METH_VARARGS, "ParamPackConcat setstate"},
  11884. {NULL} /* Sentinel */
  11885. };
  11886. void _init_py_ParamPackConcat(py::module m) {
  11887. using py_op = PyOp(ParamPackConcat);
  11888. auto& py_type = PyOpType(ParamPackConcat);
  11889. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11890. py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackConcat";
  11891. py_type.tp_basicsize = sizeof(PyOp(ParamPackConcat));
  11892. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11893. py_type.tp_doc = "ParamPackConcat";
  11894. py_type.tp_base = &PyOpType(OpDef);
  11895. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11896. py_type.tp_new = py_new_generic<py_op>;
  11897. py_type.tp_init = py_op::py_init;
  11898. py_type.tp_methods = py_op::tp_methods;
  11899. py_type.tp_getset = py_op::py_getsetters;
  11900. mgb_assert(PyType_Ready(&py_type) >= 0);
  11901. PyType_Modified(&py_type);
  11902. m.add_object("ParamPackConcat", reinterpret_cast<PyObject*>(&py_type));
  11903. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackConcat::typeinfo(), &py_type).second);
  11904. }
  11905. PyOpDefBegin(ParamPackSplit) // {
  11906. static PyGetSetDef py_getsetters[];
  11907. static PyMethodDef tp_methods[];
  11908. static PyObject* getstate(PyObject* self, PyObject*) {
  11909. auto& opdef = reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst();
  11910. static_cast<void>(opdef);
  11911. std::unordered_map<std::string, py::object> state {
  11912. {"offsets", serialization<decltype(opdef.offsets)>::dump(opdef.offsets)},
  11913. {"shapes", serialization<decltype(opdef.shapes)>::dump(opdef.shapes)}
  11914. };
  11915. return py::cast(state).release().ptr();
  11916. }
  11917. static PyObject* setstate(PyObject* self, PyObject* args) {
  11918. PyObject* dict = PyTuple_GetItem(args, 0);
  11919. if (!dict) return NULL;
  11920. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11921. auto& opdef = reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst();
  11922. static_cast<void>(opdef);
  11923. {
  11924. auto&& iter = state.find("offsets");
  11925. if (iter != state.end()) {
  11926. opdef.offsets = serialization<decltype(opdef.offsets)>::load(iter->second);
  11927. }
  11928. }
  11929. {
  11930. auto&& iter = state.find("shapes");
  11931. if (iter != state.end()) {
  11932. opdef.shapes = serialization<decltype(opdef.shapes)>::load(iter->second);
  11933. }
  11934. }
  11935. Py_RETURN_NONE;
  11936. }
  11937. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11938. // };
  11939. PyOpDefEnd(ParamPackSplit)
  11940. int PyOp(ParamPackSplit)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11941. static const char* kwlist[] = {"offsets", "shapes", "scope", NULL};
  11942. PyObject *offsets = NULL, *shapes = NULL, *scope = NULL;
  11943. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &offsets, &shapes, &scope))
  11944. return -1;
  11945. if (offsets) {
  11946. try {
  11947. // TODO: remove this guard which is used for pybind11 implicit conversion
  11948. py::detail::loader_life_support guard{};
  11949. reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst().offsets =
  11950. py::cast<decltype(ParamPackSplit::offsets)>(py::handle(offsets));
  11951. } CATCH_ALL(-1)
  11952. }
  11953. if (shapes) {
  11954. try {
  11955. // TODO: remove this guard which is used for pybind11 implicit conversion
  11956. py::detail::loader_life_support guard{};
  11957. reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst().shapes =
  11958. py::cast<decltype(ParamPackSplit::shapes)>(py::handle(shapes));
  11959. } CATCH_ALL(-1)
  11960. }
  11961. if (scope) {
  11962. try {
  11963. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11964. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11965. } CATCH_ALL(-1)
  11966. }
  11967. return 0;
  11968. }
  11969. PyGetSetDef PyOp(ParamPackSplit)::py_getsetters[] = {
  11970. {const_cast<char*>("offsets"), py_get_generic(ParamPackSplit, offsets), py_set_generic(ParamPackSplit, offsets), const_cast<char*>("offsets"), NULL},
  11971. {const_cast<char*>("shapes"), py_get_generic(ParamPackSplit, shapes), py_set_generic(ParamPackSplit, shapes), const_cast<char*>("shapes"), NULL},
  11972. {NULL} /* Sentinel */
  11973. };
  11974. PyMethodDef PyOp(ParamPackSplit)::tp_methods[] = {
  11975. {const_cast<char*>("__getstate__"), PyOp(ParamPackSplit)::getstate, METH_NOARGS, "ParamPackSplit getstate"},
  11976. {const_cast<char*>("__setstate__"), PyOp(ParamPackSplit)::setstate, METH_VARARGS, "ParamPackSplit setstate"},
  11977. {NULL} /* Sentinel */
  11978. };
  11979. void _init_py_ParamPackSplit(py::module m) {
  11980. using py_op = PyOp(ParamPackSplit);
  11981. auto& py_type = PyOpType(ParamPackSplit);
  11982. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11983. py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackSplit";
  11984. py_type.tp_basicsize = sizeof(PyOp(ParamPackSplit));
  11985. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11986. py_type.tp_doc = "ParamPackSplit";
  11987. py_type.tp_base = &PyOpType(OpDef);
  11988. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11989. py_type.tp_new = py_new_generic<py_op>;
  11990. py_type.tp_init = py_op::py_init;
  11991. py_type.tp_methods = py_op::tp_methods;
  11992. py_type.tp_getset = py_op::py_getsetters;
  11993. mgb_assert(PyType_Ready(&py_type) >= 0);
  11994. PyType_Modified(&py_type);
  11995. m.add_object("ParamPackSplit", reinterpret_cast<PyObject*>(&py_type));
  11996. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackSplit::typeinfo(), &py_type).second);
  11997. }
  11998. PyOpDefBegin(PermutationRNG) // {
  11999. static PyGetSetDef py_getsetters[];
  12000. static PyMethodDef tp_methods[];
  12001. static PyObject* getstate(PyObject* self, PyObject*) {
  12002. auto& opdef = reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst();
  12003. static_cast<void>(opdef);
  12004. std::unordered_map<std::string, py::object> state {
  12005. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  12006. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  12007. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  12008. };
  12009. return py::cast(state).release().ptr();
  12010. }
  12011. static PyObject* setstate(PyObject* self, PyObject* args) {
  12012. PyObject* dict = PyTuple_GetItem(args, 0);
  12013. if (!dict) return NULL;
  12014. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12015. auto& opdef = reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst();
  12016. static_cast<void>(opdef);
  12017. {
  12018. auto&& iter = state.find("seed");
  12019. if (iter != state.end()) {
  12020. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  12021. }
  12022. }
  12023. {
  12024. auto&& iter = state.find("dtype");
  12025. if (iter != state.end()) {
  12026. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  12027. }
  12028. }
  12029. {
  12030. auto&& iter = state.find("handle");
  12031. if (iter != state.end()) {
  12032. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  12033. }
  12034. }
  12035. Py_RETURN_NONE;
  12036. }
  12037. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12038. // };
  12039. PyOpDefEnd(PermutationRNG)
  12040. int PyOp(PermutationRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12041. static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL};
  12042. PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  12043. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &seed, &dtype, &handle, &scope))
  12044. return -1;
  12045. if (seed) {
  12046. try {
  12047. // TODO: remove this guard which is used for pybind11 implicit conversion
  12048. py::detail::loader_life_support guard{};
  12049. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().seed =
  12050. py::cast<decltype(PermutationRNG::seed)>(py::handle(seed));
  12051. } CATCH_ALL(-1)
  12052. }
  12053. if (dtype) {
  12054. try {
  12055. // TODO: remove this guard which is used for pybind11 implicit conversion
  12056. py::detail::loader_life_support guard{};
  12057. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().dtype =
  12058. py::cast<decltype(PermutationRNG::dtype)>(py::handle(dtype));
  12059. } CATCH_ALL(-1)
  12060. }
  12061. if (handle) {
  12062. try {
  12063. // TODO: remove this guard which is used for pybind11 implicit conversion
  12064. py::detail::loader_life_support guard{};
  12065. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().handle =
  12066. py::cast<decltype(PermutationRNG::handle)>(py::handle(handle));
  12067. } CATCH_ALL(-1)
  12068. }
  12069. if (scope) {
  12070. try {
  12071. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12072. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12073. } CATCH_ALL(-1)
  12074. }
  12075. return 0;
  12076. }
  12077. PyGetSetDef PyOp(PermutationRNG)::py_getsetters[] = {
  12078. {const_cast<char*>("seed"), py_get_generic(PermutationRNG, seed), py_set_generic(PermutationRNG, seed), const_cast<char*>("seed"), NULL},
  12079. {const_cast<char*>("dtype"), py_get_generic(PermutationRNG, dtype), py_set_generic(PermutationRNG, dtype), const_cast<char*>("dtype"), NULL},
  12080. {const_cast<char*>("handle"), py_get_generic(PermutationRNG, handle), py_set_generic(PermutationRNG, handle), const_cast<char*>("handle"), NULL},
  12081. {NULL} /* Sentinel */
  12082. };
  12083. PyMethodDef PyOp(PermutationRNG)::tp_methods[] = {
  12084. {const_cast<char*>("__getstate__"), PyOp(PermutationRNG)::getstate, METH_NOARGS, "PermutationRNG getstate"},
  12085. {const_cast<char*>("__setstate__"), PyOp(PermutationRNG)::setstate, METH_VARARGS, "PermutationRNG setstate"},
  12086. {NULL} /* Sentinel */
  12087. };
  12088. void _init_py_PermutationRNG(py::module m) {
  12089. using py_op = PyOp(PermutationRNG);
  12090. auto& py_type = PyOpType(PermutationRNG);
  12091. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12092. py_type.tp_name = "megengine.core._imperative_rt.ops.PermutationRNG";
  12093. py_type.tp_basicsize = sizeof(PyOp(PermutationRNG));
  12094. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12095. py_type.tp_doc = "PermutationRNG";
  12096. py_type.tp_base = &PyOpType(OpDef);
  12097. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12098. py_type.tp_new = py_new_generic<py_op>;
  12099. py_type.tp_init = py_op::py_init;
  12100. py_type.tp_methods = py_op::tp_methods;
  12101. py_type.tp_getset = py_op::py_getsetters;
  12102. mgb_assert(PyType_Ready(&py_type) >= 0);
  12103. PyType_Modified(&py_type);
  12104. m.add_object("PermutationRNG", reinterpret_cast<PyObject*>(&py_type));
  12105. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PermutationRNG::typeinfo(), &py_type).second);
  12106. }
  12107. PyOpDefBegin(PixelShuffle) // {
  12108. static PyGetSetDef py_getsetters[];
  12109. static PyMethodDef tp_methods[];
  12110. static PyObject* getstate(PyObject* self, PyObject*) {
  12111. auto& opdef = reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst();
  12112. static_cast<void>(opdef);
  12113. std::unordered_map<std::string, py::object> state {
  12114. {"factor", serialization<decltype(opdef.factor)>::dump(opdef.factor)}
  12115. };
  12116. return py::cast(state).release().ptr();
  12117. }
  12118. static PyObject* setstate(PyObject* self, PyObject* args) {
  12119. PyObject* dict = PyTuple_GetItem(args, 0);
  12120. if (!dict) return NULL;
  12121. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12122. auto& opdef = reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst();
  12123. static_cast<void>(opdef);
  12124. {
  12125. auto&& iter = state.find("factor");
  12126. if (iter != state.end()) {
  12127. opdef.factor = serialization<decltype(opdef.factor)>::load(iter->second);
  12128. }
  12129. }
  12130. Py_RETURN_NONE;
  12131. }
  12132. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12133. // };
  12134. PyOpDefEnd(PixelShuffle)
  12135. int PyOp(PixelShuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12136. static const char* kwlist[] = {"factor", "scope", NULL};
  12137. PyObject *factor = NULL, *scope = NULL;
  12138. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &factor, &scope))
  12139. return -1;
  12140. if (factor) {
  12141. try {
  12142. // TODO: remove this guard which is used for pybind11 implicit conversion
  12143. py::detail::loader_life_support guard{};
  12144. reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst().factor =
  12145. py::cast<decltype(PixelShuffle::factor)>(py::handle(factor));
  12146. } CATCH_ALL(-1)
  12147. }
  12148. if (scope) {
  12149. try {
  12150. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12151. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12152. } CATCH_ALL(-1)
  12153. }
  12154. return 0;
  12155. }
  12156. PyGetSetDef PyOp(PixelShuffle)::py_getsetters[] = {
  12157. {const_cast<char*>("factor"), py_get_generic(PixelShuffle, factor), py_set_generic(PixelShuffle, factor), const_cast<char*>("factor"), NULL},
  12158. {NULL} /* Sentinel */
  12159. };
  12160. PyMethodDef PyOp(PixelShuffle)::tp_methods[] = {
  12161. {const_cast<char*>("__getstate__"), PyOp(PixelShuffle)::getstate, METH_NOARGS, "PixelShuffle getstate"},
  12162. {const_cast<char*>("__setstate__"), PyOp(PixelShuffle)::setstate, METH_VARARGS, "PixelShuffle setstate"},
  12163. {NULL} /* Sentinel */
  12164. };
  12165. void _init_py_PixelShuffle(py::module m) {
  12166. using py_op = PyOp(PixelShuffle);
  12167. auto& py_type = PyOpType(PixelShuffle);
  12168. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12169. py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffle";
  12170. py_type.tp_basicsize = sizeof(PyOp(PixelShuffle));
  12171. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12172. py_type.tp_doc = "PixelShuffle";
  12173. py_type.tp_base = &PyOpType(OpDef);
  12174. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12175. py_type.tp_new = py_new_generic<py_op>;
  12176. py_type.tp_init = py_op::py_init;
  12177. py_type.tp_methods = py_op::tp_methods;
  12178. py_type.tp_getset = py_op::py_getsetters;
  12179. mgb_assert(PyType_Ready(&py_type) >= 0);
  12180. PyType_Modified(&py_type);
  12181. m.add_object("PixelShuffle", reinterpret_cast<PyObject*>(&py_type));
  12182. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffle::typeinfo(), &py_type).second);
  12183. }
  12184. PyOpDefBegin(PixelShuffleBackward) // {
  12185. static PyGetSetDef py_getsetters[];
  12186. static PyMethodDef tp_methods[];
  12187. static PyObject* getstate(PyObject* self, PyObject*) {
  12188. auto& opdef = reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst();
  12189. static_cast<void>(opdef);
  12190. std::unordered_map<std::string, py::object> state {
  12191. {"factor", serialization<decltype(opdef.factor)>::dump(opdef.factor)}
  12192. };
  12193. return py::cast(state).release().ptr();
  12194. }
  12195. static PyObject* setstate(PyObject* self, PyObject* args) {
  12196. PyObject* dict = PyTuple_GetItem(args, 0);
  12197. if (!dict) return NULL;
  12198. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12199. auto& opdef = reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst();
  12200. static_cast<void>(opdef);
  12201. {
  12202. auto&& iter = state.find("factor");
  12203. if (iter != state.end()) {
  12204. opdef.factor = serialization<decltype(opdef.factor)>::load(iter->second);
  12205. }
  12206. }
  12207. Py_RETURN_NONE;
  12208. }
  12209. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12210. // };
  12211. PyOpDefEnd(PixelShuffleBackward)
  12212. int PyOp(PixelShuffleBackward)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12213. static const char* kwlist[] = {"factor", "scope", NULL};
  12214. PyObject *factor = NULL, *scope = NULL;
  12215. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &factor, &scope))
  12216. return -1;
  12217. if (factor) {
  12218. try {
  12219. // TODO: remove this guard which is used for pybind11 implicit conversion
  12220. py::detail::loader_life_support guard{};
  12221. reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst().factor =
  12222. py::cast<decltype(PixelShuffleBackward::factor)>(py::handle(factor));
  12223. } CATCH_ALL(-1)
  12224. }
  12225. if (scope) {
  12226. try {
  12227. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12228. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12229. } CATCH_ALL(-1)
  12230. }
  12231. return 0;
  12232. }
  12233. PyGetSetDef PyOp(PixelShuffleBackward)::py_getsetters[] = {
  12234. {const_cast<char*>("factor"), py_get_generic(PixelShuffleBackward, factor), py_set_generic(PixelShuffleBackward, factor), const_cast<char*>("factor"), NULL},
  12235. {NULL} /* Sentinel */
  12236. };
  12237. PyMethodDef PyOp(PixelShuffleBackward)::tp_methods[] = {
  12238. {const_cast<char*>("__getstate__"), PyOp(PixelShuffleBackward)::getstate, METH_NOARGS, "PixelShuffleBackward getstate"},
  12239. {const_cast<char*>("__setstate__"), PyOp(PixelShuffleBackward)::setstate, METH_VARARGS, "PixelShuffleBackward setstate"},
  12240. {NULL} /* Sentinel */
  12241. };
  12242. void _init_py_PixelShuffleBackward(py::module m) {
  12243. using py_op = PyOp(PixelShuffleBackward);
  12244. auto& py_type = PyOpType(PixelShuffleBackward);
  12245. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12246. py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffleBackward";
  12247. py_type.tp_basicsize = sizeof(PyOp(PixelShuffleBackward));
  12248. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12249. py_type.tp_doc = "PixelShuffleBackward";
  12250. py_type.tp_base = &PyOpType(OpDef);
  12251. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12252. py_type.tp_new = py_new_generic<py_op>;
  12253. py_type.tp_init = py_op::py_init;
  12254. py_type.tp_methods = py_op::tp_methods;
  12255. py_type.tp_getset = py_op::py_getsetters;
  12256. mgb_assert(PyType_Ready(&py_type) >= 0);
  12257. PyType_Modified(&py_type);
  12258. m.add_object("PixelShuffleBackward", reinterpret_cast<PyObject*>(&py_type));
  12259. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffleBackward::typeinfo(), &py_type).second);
  12260. }
  12261. PyOpDefBegin(PoissonRNG) // {
  12262. static PyGetSetDef py_getsetters[];
  12263. static PyMethodDef tp_methods[];
  12264. static PyObject* getstate(PyObject* self, PyObject*) {
  12265. auto& opdef = reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst();
  12266. static_cast<void>(opdef);
  12267. std::unordered_map<std::string, py::object> state {
  12268. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  12269. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  12270. };
  12271. return py::cast(state).release().ptr();
  12272. }
  12273. static PyObject* setstate(PyObject* self, PyObject* args) {
  12274. PyObject* dict = PyTuple_GetItem(args, 0);
  12275. if (!dict) return NULL;
  12276. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12277. auto& opdef = reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst();
  12278. static_cast<void>(opdef);
  12279. {
  12280. auto&& iter = state.find("seed");
  12281. if (iter != state.end()) {
  12282. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  12283. }
  12284. }
  12285. {
  12286. auto&& iter = state.find("handle");
  12287. if (iter != state.end()) {
  12288. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  12289. }
  12290. }
  12291. Py_RETURN_NONE;
  12292. }
  12293. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12294. // };
  12295. PyOpDefEnd(PoissonRNG)
  12296. int PyOp(PoissonRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12297. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  12298. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  12299. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  12300. return -1;
  12301. if (seed) {
  12302. try {
  12303. // TODO: remove this guard which is used for pybind11 implicit conversion
  12304. py::detail::loader_life_support guard{};
  12305. reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst().seed =
  12306. py::cast<decltype(PoissonRNG::seed)>(py::handle(seed));
  12307. } CATCH_ALL(-1)
  12308. }
  12309. if (handle) {
  12310. try {
  12311. // TODO: remove this guard which is used for pybind11 implicit conversion
  12312. py::detail::loader_life_support guard{};
  12313. reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst().handle =
  12314. py::cast<decltype(PoissonRNG::handle)>(py::handle(handle));
  12315. } CATCH_ALL(-1)
  12316. }
  12317. if (scope) {
  12318. try {
  12319. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12320. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12321. } CATCH_ALL(-1)
  12322. }
  12323. return 0;
  12324. }
  12325. PyGetSetDef PyOp(PoissonRNG)::py_getsetters[] = {
  12326. {const_cast<char*>("seed"), py_get_generic(PoissonRNG, seed), py_set_generic(PoissonRNG, seed), const_cast<char*>("seed"), NULL},
  12327. {const_cast<char*>("handle"), py_get_generic(PoissonRNG, handle), py_set_generic(PoissonRNG, handle), const_cast<char*>("handle"), NULL},
  12328. {NULL} /* Sentinel */
  12329. };
  12330. PyMethodDef PyOp(PoissonRNG)::tp_methods[] = {
  12331. {const_cast<char*>("__getstate__"), PyOp(PoissonRNG)::getstate, METH_NOARGS, "PoissonRNG getstate"},
  12332. {const_cast<char*>("__setstate__"), PyOp(PoissonRNG)::setstate, METH_VARARGS, "PoissonRNG setstate"},
  12333. {NULL} /* Sentinel */
  12334. };
  12335. void _init_py_PoissonRNG(py::module m) {
  12336. using py_op = PyOp(PoissonRNG);
  12337. auto& py_type = PyOpType(PoissonRNG);
  12338. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12339. py_type.tp_name = "megengine.core._imperative_rt.ops.PoissonRNG";
  12340. py_type.tp_basicsize = sizeof(PyOp(PoissonRNG));
  12341. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12342. py_type.tp_doc = "PoissonRNG";
  12343. py_type.tp_base = &PyOpType(OpDef);
  12344. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12345. py_type.tp_new = py_new_generic<py_op>;
  12346. py_type.tp_init = py_op::py_init;
  12347. py_type.tp_methods = py_op::tp_methods;
  12348. py_type.tp_getset = py_op::py_getsetters;
  12349. mgb_assert(PyType_Ready(&py_type) >= 0);
  12350. PyType_Modified(&py_type);
  12351. m.add_object("PoissonRNG", reinterpret_cast<PyObject*>(&py_type));
  12352. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PoissonRNG::typeinfo(), &py_type).second);
  12353. }
  12354. void _init_py_Pooling_Mode(PyTypeObject& py_type) {
  12355. auto& e_type = EnumWrapper<Pooling::Mode>::type;
  12356. Py_INCREF(e_type);
  12357. mgb_assert(PyDict_SetItemString(
  12358. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12359. }
  12360. void _init_py_Pooling_Format(PyTypeObject& py_type) {
  12361. auto& e_type = EnumWrapper<Pooling::Format>::type;
  12362. Py_INCREF(e_type);
  12363. mgb_assert(PyDict_SetItemString(
  12364. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12365. }
  12366. void _init_py_Pooling_Strategy(PyTypeObject& py_type) {
  12367. auto& e_type = BitCombinedEnumWrapper<Pooling::Strategy>::type;
  12368. Py_INCREF(e_type);
  12369. mgb_assert(PyDict_SetItemString(
  12370. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12371. }
  12372. PyOpDefBegin(Pooling) // {
  12373. static PyGetSetDef py_getsetters[];
  12374. static PyMethodDef tp_methods[];
  12375. static PyObject* getstate(PyObject* self, PyObject*) {
  12376. auto& opdef = reinterpret_cast<PyOp(Pooling)*>(self)->inst();
  12377. static_cast<void>(opdef);
  12378. std::unordered_map<std::string, py::object> state {
  12379. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  12380. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  12381. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  12382. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  12383. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  12384. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  12385. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)},
  12386. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  12387. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  12388. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  12389. };
  12390. return py::cast(state).release().ptr();
  12391. }
  12392. static PyObject* setstate(PyObject* self, PyObject* args) {
  12393. PyObject* dict = PyTuple_GetItem(args, 0);
  12394. if (!dict) return NULL;
  12395. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12396. auto& opdef = reinterpret_cast<PyOp(Pooling)*>(self)->inst();
  12397. static_cast<void>(opdef);
  12398. {
  12399. auto&& iter = state.find("mode");
  12400. if (iter != state.end()) {
  12401. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  12402. }
  12403. }
  12404. {
  12405. auto&& iter = state.find("pad_h");
  12406. if (iter != state.end()) {
  12407. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  12408. }
  12409. }
  12410. {
  12411. auto&& iter = state.find("pad_w");
  12412. if (iter != state.end()) {
  12413. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  12414. }
  12415. }
  12416. {
  12417. auto&& iter = state.find("stride_h");
  12418. if (iter != state.end()) {
  12419. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  12420. }
  12421. }
  12422. {
  12423. auto&& iter = state.find("stride_w");
  12424. if (iter != state.end()) {
  12425. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  12426. }
  12427. }
  12428. {
  12429. auto&& iter = state.find("window_h");
  12430. if (iter != state.end()) {
  12431. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  12432. }
  12433. }
  12434. {
  12435. auto&& iter = state.find("window_w");
  12436. if (iter != state.end()) {
  12437. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  12438. }
  12439. }
  12440. {
  12441. auto&& iter = state.find("format");
  12442. if (iter != state.end()) {
  12443. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  12444. }
  12445. }
  12446. {
  12447. auto&& iter = state.find("strategy");
  12448. if (iter != state.end()) {
  12449. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  12450. }
  12451. }
  12452. {
  12453. auto&& iter = state.find("workspace_limit");
  12454. if (iter != state.end()) {
  12455. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  12456. }
  12457. }
  12458. Py_RETURN_NONE;
  12459. }
  12460. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12461. // };
  12462. PyOpDefEnd(Pooling)
  12463. int PyOp(Pooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12464. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "window_h", "window_w", "format", "strategy", "workspace_limit", "scope", NULL};
  12465. PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *window_h = NULL, *window_w = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL;
  12466. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &window_h, &window_w, &format, &strategy, &workspace_limit, &scope))
  12467. return -1;
  12468. if (mode) {
  12469. try {
  12470. // TODO: remove this guard which is used for pybind11 implicit conversion
  12471. py::detail::loader_life_support guard{};
  12472. reinterpret_cast<PyOp(Pooling)*>(self)->inst().mode =
  12473. py::cast<decltype(Pooling::mode)>(py::handle(mode));
  12474. } CATCH_ALL(-1)
  12475. }
  12476. if (pad_h) {
  12477. try {
  12478. // TODO: remove this guard which is used for pybind11 implicit conversion
  12479. py::detail::loader_life_support guard{};
  12480. reinterpret_cast<PyOp(Pooling)*>(self)->inst().pad_h =
  12481. py::cast<decltype(Pooling::pad_h)>(py::handle(pad_h));
  12482. } CATCH_ALL(-1)
  12483. }
  12484. if (pad_w) {
  12485. try {
  12486. // TODO: remove this guard which is used for pybind11 implicit conversion
  12487. py::detail::loader_life_support guard{};
  12488. reinterpret_cast<PyOp(Pooling)*>(self)->inst().pad_w =
  12489. py::cast<decltype(Pooling::pad_w)>(py::handle(pad_w));
  12490. } CATCH_ALL(-1)
  12491. }
  12492. if (stride_h) {
  12493. try {
  12494. // TODO: remove this guard which is used for pybind11 implicit conversion
  12495. py::detail::loader_life_support guard{};
  12496. reinterpret_cast<PyOp(Pooling)*>(self)->inst().stride_h =
  12497. py::cast<decltype(Pooling::stride_h)>(py::handle(stride_h));
  12498. } CATCH_ALL(-1)
  12499. }
  12500. if (stride_w) {
  12501. try {
  12502. // TODO: remove this guard which is used for pybind11 implicit conversion
  12503. py::detail::loader_life_support guard{};
  12504. reinterpret_cast<PyOp(Pooling)*>(self)->inst().stride_w =
  12505. py::cast<decltype(Pooling::stride_w)>(py::handle(stride_w));
  12506. } CATCH_ALL(-1)
  12507. }
  12508. if (window_h) {
  12509. try {
  12510. // TODO: remove this guard which is used for pybind11 implicit conversion
  12511. py::detail::loader_life_support guard{};
  12512. reinterpret_cast<PyOp(Pooling)*>(self)->inst().window_h =
  12513. py::cast<decltype(Pooling::window_h)>(py::handle(window_h));
  12514. } CATCH_ALL(-1)
  12515. }
  12516. if (window_w) {
  12517. try {
  12518. // TODO: remove this guard which is used for pybind11 implicit conversion
  12519. py::detail::loader_life_support guard{};
  12520. reinterpret_cast<PyOp(Pooling)*>(self)->inst().window_w =
  12521. py::cast<decltype(Pooling::window_w)>(py::handle(window_w));
  12522. } CATCH_ALL(-1)
  12523. }
  12524. if (format) {
  12525. try {
  12526. // TODO: remove this guard which is used for pybind11 implicit conversion
  12527. py::detail::loader_life_support guard{};
  12528. reinterpret_cast<PyOp(Pooling)*>(self)->inst().format =
  12529. py::cast<decltype(Pooling::format)>(py::handle(format));
  12530. } CATCH_ALL(-1)
  12531. }
  12532. if (strategy) {
  12533. try {
  12534. // TODO: remove this guard which is used for pybind11 implicit conversion
  12535. py::detail::loader_life_support guard{};
  12536. reinterpret_cast<PyOp(Pooling)*>(self)->inst().strategy =
  12537. py::cast<decltype(Pooling::strategy)>(py::handle(strategy));
  12538. } CATCH_ALL(-1)
  12539. }
  12540. if (workspace_limit) {
  12541. try {
  12542. // TODO: remove this guard which is used for pybind11 implicit conversion
  12543. py::detail::loader_life_support guard{};
  12544. reinterpret_cast<PyOp(Pooling)*>(self)->inst().workspace_limit =
  12545. py::cast<decltype(Pooling::workspace_limit)>(py::handle(workspace_limit));
  12546. } CATCH_ALL(-1)
  12547. }
  12548. if (scope) {
  12549. try {
  12550. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12551. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12552. } CATCH_ALL(-1)
  12553. }
  12554. return 0;
  12555. }
  12556. PyGetSetDef PyOp(Pooling)::py_getsetters[] = {
  12557. {const_cast<char*>("mode"), py_get_generic(Pooling, mode), py_set_generic(Pooling, mode), const_cast<char*>("mode"), NULL},
  12558. {const_cast<char*>("pad_h"), py_get_generic(Pooling, pad_h), py_set_generic(Pooling, pad_h), const_cast<char*>("pad_h"), NULL},
  12559. {const_cast<char*>("pad_w"), py_get_generic(Pooling, pad_w), py_set_generic(Pooling, pad_w), const_cast<char*>("pad_w"), NULL},
  12560. {const_cast<char*>("stride_h"), py_get_generic(Pooling, stride_h), py_set_generic(Pooling, stride_h), const_cast<char*>("stride_h"), NULL},
  12561. {const_cast<char*>("stride_w"), py_get_generic(Pooling, stride_w), py_set_generic(Pooling, stride_w), const_cast<char*>("stride_w"), NULL},
  12562. {const_cast<char*>("window_h"), py_get_generic(Pooling, window_h), py_set_generic(Pooling, window_h), const_cast<char*>("window_h"), NULL},
  12563. {const_cast<char*>("window_w"), py_get_generic(Pooling, window_w), py_set_generic(Pooling, window_w), const_cast<char*>("window_w"), NULL},
  12564. {const_cast<char*>("format"), py_get_generic(Pooling, format), py_set_generic(Pooling, format), const_cast<char*>("format"), NULL},
  12565. {const_cast<char*>("strategy"), py_get_generic(Pooling, strategy), py_set_generic(Pooling, strategy), const_cast<char*>("strategy"), NULL},
  12566. {const_cast<char*>("workspace_limit"), py_get_generic(Pooling, workspace_limit), py_set_generic(Pooling, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  12567. {NULL} /* Sentinel */
  12568. };
  12569. PyMethodDef PyOp(Pooling)::tp_methods[] = {
  12570. {const_cast<char*>("__getstate__"), PyOp(Pooling)::getstate, METH_NOARGS, "Pooling getstate"},
  12571. {const_cast<char*>("__setstate__"), PyOp(Pooling)::setstate, METH_VARARGS, "Pooling setstate"},
  12572. {NULL} /* Sentinel */
  12573. };
  12574. void _init_py_Pooling(py::module m) {
  12575. using py_op = PyOp(Pooling);
  12576. auto& py_type = PyOpType(Pooling);
  12577. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12578. py_type.tp_name = "megengine.core._imperative_rt.ops.Pooling";
  12579. py_type.tp_basicsize = sizeof(PyOp(Pooling));
  12580. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12581. py_type.tp_doc = "Pooling";
  12582. py_type.tp_base = &PyOpType(OpDef);
  12583. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12584. py_type.tp_new = py_new_generic<py_op>;
  12585. py_type.tp_init = py_op::py_init;
  12586. py_type.tp_methods = py_op::tp_methods;
  12587. py_type.tp_getset = py_op::py_getsetters;
  12588. mgb_assert(PyType_Ready(&py_type) >= 0);
  12589. _init_py_Pooling_Mode(py_type);
  12590. _init_py_Pooling_Format(py_type);
  12591. _init_py_Pooling_Strategy(py_type);
  12592. PyType_Modified(&py_type);
  12593. m.add_object("Pooling", reinterpret_cast<PyObject*>(&py_type));
  12594. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Pooling::typeinfo(), &py_type).second);
  12595. }
  12596. template<> struct EnumTrait<RNN::NonlineMode> {
  12597. static constexpr const char *name = "RNN.NonlineMode";
  12598. static constexpr std::underlying_type_t<RNN::NonlineMode> max = 3 - 1;
  12599. };
  12600. template<> PyTypeObject* EnumWrapper<RNN::NonlineMode>::type = nullptr;
  12601. template<> const char*
  12602. EnumWrapper<RNN::NonlineMode>::members[] = {"IDENTITY", "RELU", "TANH"};
  12603. template<> std::unordered_map<std::string, RNN::NonlineMode>
  12604. EnumWrapper<RNN::NonlineMode>::mem2value = {{normalize_enum("IDENTITY"), RNN::NonlineMode::IDENTITY}, {normalize_enum("RELU"), RNN::NonlineMode::RELU}, {normalize_enum("TANH"), RNN::NonlineMode::TANH}};
  12605. template<> PyObject* EnumWrapper<RNN::NonlineMode>::pyobj_insts[3] = {nullptr};
  12606. void _init_py_RNN_NonlineMode(PyTypeObject& py_type) {
  12607. auto& e_type = EnumWrapper<RNN::NonlineMode>::type;
  12608. static PyMethodDef tp_methods[] = {
  12609. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<RNN::NonlineMode>::py_dump, METH_NOARGS, NULL},
  12610. {NULL} /* Sentinel */
  12611. };
  12612. static PyType_Slot slots[] = {
  12613. {Py_tp_repr, (void*)EnumWrapper<RNN::NonlineMode>::py_repr},
  12614. {Py_tp_richcompare, (void*)EnumWrapper<RNN::NonlineMode>::tp_richcompare},
  12615. {Py_tp_methods, tp_methods},
  12616. {0, NULL}
  12617. };
  12618. static PyType_Spec spec = {
  12619. // name
  12620. "megengine.core._imperative_rt.ops.RNN.NonlineMode",
  12621. // basicsize
  12622. sizeof(EnumWrapper<RNN::NonlineMode>),
  12623. // itemsize
  12624. 0,
  12625. // flags
  12626. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  12627. // slots
  12628. slots
  12629. };
  12630. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  12631. mgb_assert(
  12632. e_type->tp_setattro(
  12633. reinterpret_cast<PyObject*>(e_type),
  12634. py::cast("__name__").release().ptr(),
  12635. py::cast("NonlineMode").release().ptr()) >= 0);
  12636. mgb_assert(
  12637. e_type->tp_setattro(
  12638. reinterpret_cast<PyObject*>(e_type),
  12639. py::cast("__module__").release().ptr(),
  12640. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  12641. mgb_assert(
  12642. e_type->tp_setattro(
  12643. reinterpret_cast<PyObject*>(e_type),
  12644. py::cast("__qualname__").release().ptr(),
  12645. py::cast("RNN.NonlineMode").release().ptr()) >= 0);
  12646. {
  12647. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12648. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::IDENTITY;
  12649. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "IDENTITY", inst) >= 0);
  12650. EnumWrapper<RNN::NonlineMode>::pyobj_insts[0] = inst;
  12651. }{
  12652. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12653. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::RELU;
  12654. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  12655. EnumWrapper<RNN::NonlineMode>::pyobj_insts[1] = inst;
  12656. }{
  12657. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12658. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::TANH;
  12659. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0);
  12660. EnumWrapper<RNN::NonlineMode>::pyobj_insts[2] = inst;
  12661. }
  12662. Py_INCREF(e_type);
  12663. mgb_assert(PyDict_SetItemString(
  12664. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12665. }
  12666. void _init_py_RNN_FwdMode(PyTypeObject& py_type) {
  12667. auto& e_type = EnumWrapper<RNN::FwdMode>::type;
  12668. Py_INCREF(e_type);
  12669. mgb_assert(PyDict_SetItemString(
  12670. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12671. }
  12672. PyOpDefBegin(RNN) // {
  12673. static PyGetSetDef py_getsetters[];
  12674. static PyMethodDef tp_methods[];
  12675. static PyObject* getstate(PyObject* self, PyObject*) {
  12676. auto& opdef = reinterpret_cast<PyOp(RNN)*>(self)->inst();
  12677. static_cast<void>(opdef);
  12678. std::unordered_map<std::string, py::object> state {
  12679. {"num_layers", serialization<decltype(opdef.num_layers)>::dump(opdef.num_layers)},
  12680. {"bidirectional", serialization<decltype(opdef.bidirectional)>::dump(opdef.bidirectional)},
  12681. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)},
  12682. {"hidden_size", serialization<decltype(opdef.hidden_size)>::dump(opdef.hidden_size)},
  12683. {"dropout", serialization<decltype(opdef.dropout)>::dump(opdef.dropout)},
  12684. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)},
  12685. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)}
  12686. };
  12687. return py::cast(state).release().ptr();
  12688. }
  12689. static PyObject* setstate(PyObject* self, PyObject* args) {
  12690. PyObject* dict = PyTuple_GetItem(args, 0);
  12691. if (!dict) return NULL;
  12692. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12693. auto& opdef = reinterpret_cast<PyOp(RNN)*>(self)->inst();
  12694. static_cast<void>(opdef);
  12695. {
  12696. auto&& iter = state.find("num_layers");
  12697. if (iter != state.end()) {
  12698. opdef.num_layers = serialization<decltype(opdef.num_layers)>::load(iter->second);
  12699. }
  12700. }
  12701. {
  12702. auto&& iter = state.find("bidirectional");
  12703. if (iter != state.end()) {
  12704. opdef.bidirectional = serialization<decltype(opdef.bidirectional)>::load(iter->second);
  12705. }
  12706. }
  12707. {
  12708. auto&& iter = state.find("bias");
  12709. if (iter != state.end()) {
  12710. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  12711. }
  12712. }
  12713. {
  12714. auto&& iter = state.find("hidden_size");
  12715. if (iter != state.end()) {
  12716. opdef.hidden_size = serialization<decltype(opdef.hidden_size)>::load(iter->second);
  12717. }
  12718. }
  12719. {
  12720. auto&& iter = state.find("dropout");
  12721. if (iter != state.end()) {
  12722. opdef.dropout = serialization<decltype(opdef.dropout)>::load(iter->second);
  12723. }
  12724. }
  12725. {
  12726. auto&& iter = state.find("nonlineMode");
  12727. if (iter != state.end()) {
  12728. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  12729. }
  12730. }
  12731. {
  12732. auto&& iter = state.find("fwd_mode");
  12733. if (iter != state.end()) {
  12734. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  12735. }
  12736. }
  12737. Py_RETURN_NONE;
  12738. }
  12739. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12740. // };
  12741. PyOpDefEnd(RNN)
  12742. int PyOp(RNN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12743. static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "dropout", "nonlineMode", "fwd_mode", "scope", NULL};
  12744. PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *dropout = NULL, *nonlineMode = NULL, *fwd_mode = NULL, *scope = NULL;
  12745. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &dropout, &nonlineMode, &fwd_mode, &scope))
  12746. return -1;
  12747. if (num_layers) {
  12748. try {
  12749. // TODO: remove this guard which is used for pybind11 implicit conversion
  12750. py::detail::loader_life_support guard{};
  12751. reinterpret_cast<PyOp(RNN)*>(self)->inst().num_layers =
  12752. py::cast<decltype(RNN::num_layers)>(py::handle(num_layers));
  12753. } CATCH_ALL(-1)
  12754. }
  12755. if (bidirectional) {
  12756. try {
  12757. // TODO: remove this guard which is used for pybind11 implicit conversion
  12758. py::detail::loader_life_support guard{};
  12759. reinterpret_cast<PyOp(RNN)*>(self)->inst().bidirectional =
  12760. py::cast<decltype(RNN::bidirectional)>(py::handle(bidirectional));
  12761. } CATCH_ALL(-1)
  12762. }
  12763. if (bias) {
  12764. try {
  12765. // TODO: remove this guard which is used for pybind11 implicit conversion
  12766. py::detail::loader_life_support guard{};
  12767. reinterpret_cast<PyOp(RNN)*>(self)->inst().bias =
  12768. py::cast<decltype(RNN::bias)>(py::handle(bias));
  12769. } CATCH_ALL(-1)
  12770. }
  12771. if (hidden_size) {
  12772. try {
  12773. // TODO: remove this guard which is used for pybind11 implicit conversion
  12774. py::detail::loader_life_support guard{};
  12775. reinterpret_cast<PyOp(RNN)*>(self)->inst().hidden_size =
  12776. py::cast<decltype(RNN::hidden_size)>(py::handle(hidden_size));
  12777. } CATCH_ALL(-1)
  12778. }
  12779. if (dropout) {
  12780. try {
  12781. // TODO: remove this guard which is used for pybind11 implicit conversion
  12782. py::detail::loader_life_support guard{};
  12783. reinterpret_cast<PyOp(RNN)*>(self)->inst().dropout =
  12784. py::cast<decltype(RNN::dropout)>(py::handle(dropout));
  12785. } CATCH_ALL(-1)
  12786. }
  12787. if (nonlineMode) {
  12788. try {
  12789. // TODO: remove this guard which is used for pybind11 implicit conversion
  12790. py::detail::loader_life_support guard{};
  12791. reinterpret_cast<PyOp(RNN)*>(self)->inst().nonlineMode =
  12792. py::cast<decltype(RNN::nonlineMode)>(py::handle(nonlineMode));
  12793. } CATCH_ALL(-1)
  12794. }
  12795. if (fwd_mode) {
  12796. try {
  12797. // TODO: remove this guard which is used for pybind11 implicit conversion
  12798. py::detail::loader_life_support guard{};
  12799. reinterpret_cast<PyOp(RNN)*>(self)->inst().fwd_mode =
  12800. py::cast<decltype(RNN::fwd_mode)>(py::handle(fwd_mode));
  12801. } CATCH_ALL(-1)
  12802. }
  12803. if (scope) {
  12804. try {
  12805. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12806. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12807. } CATCH_ALL(-1)
  12808. }
  12809. return 0;
  12810. }
  12811. PyGetSetDef PyOp(RNN)::py_getsetters[] = {
  12812. {const_cast<char*>("num_layers"), py_get_generic(RNN, num_layers), py_set_generic(RNN, num_layers), const_cast<char*>("num_layers"), NULL},
  12813. {const_cast<char*>("bidirectional"), py_get_generic(RNN, bidirectional), py_set_generic(RNN, bidirectional), const_cast<char*>("bidirectional"), NULL},
  12814. {const_cast<char*>("bias"), py_get_generic(RNN, bias), py_set_generic(RNN, bias), const_cast<char*>("bias"), NULL},
  12815. {const_cast<char*>("hidden_size"), py_get_generic(RNN, hidden_size), py_set_generic(RNN, hidden_size), const_cast<char*>("hidden_size"), NULL},
  12816. {const_cast<char*>("dropout"), py_get_generic(RNN, dropout), py_set_generic(RNN, dropout), const_cast<char*>("dropout"), NULL},
  12817. {const_cast<char*>("nonlineMode"), py_get_generic(RNN, nonlineMode), py_set_generic(RNN, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  12818. {const_cast<char*>("fwd_mode"), py_get_generic(RNN, fwd_mode), py_set_generic(RNN, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  12819. {NULL} /* Sentinel */
  12820. };
  12821. PyMethodDef PyOp(RNN)::tp_methods[] = {
  12822. {const_cast<char*>("__getstate__"), PyOp(RNN)::getstate, METH_NOARGS, "RNN getstate"},
  12823. {const_cast<char*>("__setstate__"), PyOp(RNN)::setstate, METH_VARARGS, "RNN setstate"},
  12824. {NULL} /* Sentinel */
  12825. };
  12826. void _init_py_RNN(py::module m) {
  12827. using py_op = PyOp(RNN);
  12828. auto& py_type = PyOpType(RNN);
  12829. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12830. py_type.tp_name = "megengine.core._imperative_rt.ops.RNN";
  12831. py_type.tp_basicsize = sizeof(PyOp(RNN));
  12832. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12833. py_type.tp_doc = "RNN";
  12834. py_type.tp_base = &PyOpType(OpDef);
  12835. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12836. py_type.tp_new = py_new_generic<py_op>;
  12837. py_type.tp_init = py_op::py_init;
  12838. py_type.tp_methods = py_op::tp_methods;
  12839. py_type.tp_getset = py_op::py_getsetters;
  12840. mgb_assert(PyType_Ready(&py_type) >= 0);
  12841. _init_py_RNN_NonlineMode(py_type);
  12842. _init_py_RNN_FwdMode(py_type);
  12843. PyType_Modified(&py_type);
  12844. m.add_object("RNN", reinterpret_cast<PyObject*>(&py_type));
  12845. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNN::typeinfo(), &py_type).second);
  12846. }
  12847. void _init_py_RNNCell_NonlineMode(PyTypeObject& py_type) {
  12848. auto& e_type = EnumWrapper<RNNCell::NonlineMode>::type;
  12849. Py_INCREF(e_type);
  12850. mgb_assert(PyDict_SetItemString(
  12851. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12852. }
  12853. PyOpDefBegin(RNNCell) // {
  12854. static PyGetSetDef py_getsetters[];
  12855. static PyMethodDef tp_methods[];
  12856. static PyObject* getstate(PyObject* self, PyObject*) {
  12857. auto& opdef = reinterpret_cast<PyOp(RNNCell)*>(self)->inst();
  12858. static_cast<void>(opdef);
  12859. std::unordered_map<std::string, py::object> state {
  12860. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)}
  12861. };
  12862. return py::cast(state).release().ptr();
  12863. }
  12864. static PyObject* setstate(PyObject* self, PyObject* args) {
  12865. PyObject* dict = PyTuple_GetItem(args, 0);
  12866. if (!dict) return NULL;
  12867. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12868. auto& opdef = reinterpret_cast<PyOp(RNNCell)*>(self)->inst();
  12869. static_cast<void>(opdef);
  12870. {
  12871. auto&& iter = state.find("nonlineMode");
  12872. if (iter != state.end()) {
  12873. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  12874. }
  12875. }
  12876. Py_RETURN_NONE;
  12877. }
  12878. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12879. // };
  12880. PyOpDefEnd(RNNCell)
  12881. int PyOp(RNNCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12882. static const char* kwlist[] = {"nonlineMode", "scope", NULL};
  12883. PyObject *nonlineMode = NULL, *scope = NULL;
  12884. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &nonlineMode, &scope))
  12885. return -1;
  12886. if (nonlineMode) {
  12887. try {
  12888. // TODO: remove this guard which is used for pybind11 implicit conversion
  12889. py::detail::loader_life_support guard{};
  12890. reinterpret_cast<PyOp(RNNCell)*>(self)->inst().nonlineMode =
  12891. py::cast<decltype(RNNCell::nonlineMode)>(py::handle(nonlineMode));
  12892. } CATCH_ALL(-1)
  12893. }
  12894. if (scope) {
  12895. try {
  12896. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12897. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12898. } CATCH_ALL(-1)
  12899. }
  12900. return 0;
  12901. }
  12902. PyGetSetDef PyOp(RNNCell)::py_getsetters[] = {
  12903. {const_cast<char*>("nonlineMode"), py_get_generic(RNNCell, nonlineMode), py_set_generic(RNNCell, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  12904. {NULL} /* Sentinel */
  12905. };
  12906. PyMethodDef PyOp(RNNCell)::tp_methods[] = {
  12907. {const_cast<char*>("__getstate__"), PyOp(RNNCell)::getstate, METH_NOARGS, "RNNCell getstate"},
  12908. {const_cast<char*>("__setstate__"), PyOp(RNNCell)::setstate, METH_VARARGS, "RNNCell setstate"},
  12909. {NULL} /* Sentinel */
  12910. };
  12911. void _init_py_RNNCell(py::module m) {
  12912. using py_op = PyOp(RNNCell);
  12913. auto& py_type = PyOpType(RNNCell);
  12914. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12915. py_type.tp_name = "megengine.core._imperative_rt.ops.RNNCell";
  12916. py_type.tp_basicsize = sizeof(PyOp(RNNCell));
  12917. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12918. py_type.tp_doc = "RNNCell";
  12919. py_type.tp_base = &PyOpType(OpDef);
  12920. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12921. py_type.tp_new = py_new_generic<py_op>;
  12922. py_type.tp_init = py_op::py_init;
  12923. py_type.tp_methods = py_op::tp_methods;
  12924. py_type.tp_getset = py_op::py_getsetters;
  12925. mgb_assert(PyType_Ready(&py_type) >= 0);
  12926. _init_py_RNNCell_NonlineMode(py_type);
  12927. PyType_Modified(&py_type);
  12928. m.add_object("RNNCell", reinterpret_cast<PyObject*>(&py_type));
  12929. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNNCell::typeinfo(), &py_type).second);
  12930. }
  12931. template<> struct EnumTrait<ROIAlign::Mode> {
  12932. static constexpr const char *name = "ROIAlign.Mode";
  12933. static constexpr std::underlying_type_t<ROIAlign::Mode> max = 2 - 1;
  12934. };
  12935. template<> PyTypeObject* EnumWrapper<ROIAlign::Mode>::type = nullptr;
  12936. template<> const char*
  12937. EnumWrapper<ROIAlign::Mode>::members[] = {"MAX", "AVERAGE"};
  12938. template<> std::unordered_map<std::string, ROIAlign::Mode>
  12939. EnumWrapper<ROIAlign::Mode>::mem2value = {{normalize_enum("MAX"), ROIAlign::Mode::MAX}, {normalize_enum("AVERAGE"), ROIAlign::Mode::AVERAGE}};
  12940. template<> PyObject* EnumWrapper<ROIAlign::Mode>::pyobj_insts[2] = {nullptr};
  12941. void _init_py_ROIAlign_Mode(PyTypeObject& py_type) {
  12942. auto& e_type = EnumWrapper<ROIAlign::Mode>::type;
  12943. static PyMethodDef tp_methods[] = {
  12944. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ROIAlign::Mode>::py_dump, METH_NOARGS, NULL},
  12945. {NULL} /* Sentinel */
  12946. };
  12947. static PyType_Slot slots[] = {
  12948. {Py_tp_repr, (void*)EnumWrapper<ROIAlign::Mode>::py_repr},
  12949. {Py_tp_richcompare, (void*)EnumWrapper<ROIAlign::Mode>::tp_richcompare},
  12950. {Py_tp_methods, tp_methods},
  12951. {0, NULL}
  12952. };
  12953. static PyType_Spec spec = {
  12954. // name
  12955. "megengine.core._imperative_rt.ops.ROIAlign.Mode",
  12956. // basicsize
  12957. sizeof(EnumWrapper<ROIAlign::Mode>),
  12958. // itemsize
  12959. 0,
  12960. // flags
  12961. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  12962. // slots
  12963. slots
  12964. };
  12965. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  12966. mgb_assert(
  12967. e_type->tp_setattro(
  12968. reinterpret_cast<PyObject*>(e_type),
  12969. py::cast("__name__").release().ptr(),
  12970. py::cast("Mode").release().ptr()) >= 0);
  12971. mgb_assert(
  12972. e_type->tp_setattro(
  12973. reinterpret_cast<PyObject*>(e_type),
  12974. py::cast("__module__").release().ptr(),
  12975. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  12976. mgb_assert(
  12977. e_type->tp_setattro(
  12978. reinterpret_cast<PyObject*>(e_type),
  12979. py::cast("__qualname__").release().ptr(),
  12980. py::cast("ROIAlign.Mode").release().ptr()) >= 0);
  12981. {
  12982. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12983. reinterpret_cast<EnumWrapper<ROIAlign::Mode>*>(inst)->value = ROIAlign::Mode::MAX;
  12984. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  12985. EnumWrapper<ROIAlign::Mode>::pyobj_insts[0] = inst;
  12986. }{
  12987. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12988. reinterpret_cast<EnumWrapper<ROIAlign::Mode>*>(inst)->value = ROIAlign::Mode::AVERAGE;
  12989. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  12990. EnumWrapper<ROIAlign::Mode>::pyobj_insts[1] = inst;
  12991. }
  12992. Py_INCREF(e_type);
  12993. mgb_assert(PyDict_SetItemString(
  12994. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12995. }
  12996. void _init_py_ROIAlign_Format(PyTypeObject& py_type) {
  12997. auto& e_type = EnumWrapper<ROIAlign::Format>::type;
  12998. Py_INCREF(e_type);
  12999. mgb_assert(PyDict_SetItemString(
  13000. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13001. }
  13002. PyOpDefBegin(ROIAlign) // {
  13003. static PyGetSetDef py_getsetters[];
  13004. static PyMethodDef tp_methods[];
  13005. static PyObject* getstate(PyObject* self, PyObject*) {
  13006. auto& opdef = reinterpret_cast<PyOp(ROIAlign)*>(self)->inst();
  13007. static_cast<void>(opdef);
  13008. std::unordered_map<std::string, py::object> state {
  13009. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13010. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  13011. {"spatial_scale", serialization<decltype(opdef.spatial_scale)>::dump(opdef.spatial_scale)},
  13012. {"offset", serialization<decltype(opdef.offset)>::dump(opdef.offset)},
  13013. {"pooled_height", serialization<decltype(opdef.pooled_height)>::dump(opdef.pooled_height)},
  13014. {"pooled_width", serialization<decltype(opdef.pooled_width)>::dump(opdef.pooled_width)},
  13015. {"sample_height", serialization<decltype(opdef.sample_height)>::dump(opdef.sample_height)},
  13016. {"sample_width", serialization<decltype(opdef.sample_width)>::dump(opdef.sample_width)}
  13017. };
  13018. return py::cast(state).release().ptr();
  13019. }
  13020. static PyObject* setstate(PyObject* self, PyObject* args) {
  13021. PyObject* dict = PyTuple_GetItem(args, 0);
  13022. if (!dict) return NULL;
  13023. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13024. auto& opdef = reinterpret_cast<PyOp(ROIAlign)*>(self)->inst();
  13025. static_cast<void>(opdef);
  13026. {
  13027. auto&& iter = state.find("mode");
  13028. if (iter != state.end()) {
  13029. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13030. }
  13031. }
  13032. {
  13033. auto&& iter = state.find("format");
  13034. if (iter != state.end()) {
  13035. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  13036. }
  13037. }
  13038. {
  13039. auto&& iter = state.find("spatial_scale");
  13040. if (iter != state.end()) {
  13041. opdef.spatial_scale = serialization<decltype(opdef.spatial_scale)>::load(iter->second);
  13042. }
  13043. }
  13044. {
  13045. auto&& iter = state.find("offset");
  13046. if (iter != state.end()) {
  13047. opdef.offset = serialization<decltype(opdef.offset)>::load(iter->second);
  13048. }
  13049. }
  13050. {
  13051. auto&& iter = state.find("pooled_height");
  13052. if (iter != state.end()) {
  13053. opdef.pooled_height = serialization<decltype(opdef.pooled_height)>::load(iter->second);
  13054. }
  13055. }
  13056. {
  13057. auto&& iter = state.find("pooled_width");
  13058. if (iter != state.end()) {
  13059. opdef.pooled_width = serialization<decltype(opdef.pooled_width)>::load(iter->second);
  13060. }
  13061. }
  13062. {
  13063. auto&& iter = state.find("sample_height");
  13064. if (iter != state.end()) {
  13065. opdef.sample_height = serialization<decltype(opdef.sample_height)>::load(iter->second);
  13066. }
  13067. }
  13068. {
  13069. auto&& iter = state.find("sample_width");
  13070. if (iter != state.end()) {
  13071. opdef.sample_width = serialization<decltype(opdef.sample_width)>::load(iter->second);
  13072. }
  13073. }
  13074. Py_RETURN_NONE;
  13075. }
  13076. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13077. // };
  13078. PyOpDefEnd(ROIAlign)
  13079. int PyOp(ROIAlign)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13080. static const char* kwlist[] = {"mode", "format", "spatial_scale", "offset", "pooled_height", "pooled_width", "sample_height", "sample_width", "scope", NULL};
  13081. PyObject *mode = NULL, *format = NULL, *spatial_scale = NULL, *offset = NULL, *pooled_height = NULL, *pooled_width = NULL, *sample_height = NULL, *sample_width = NULL, *scope = NULL;
  13082. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &mode, &format, &spatial_scale, &offset, &pooled_height, &pooled_width, &sample_height, &sample_width, &scope))
  13083. return -1;
  13084. if (mode) {
  13085. try {
  13086. // TODO: remove this guard which is used for pybind11 implicit conversion
  13087. py::detail::loader_life_support guard{};
  13088. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().mode =
  13089. py::cast<decltype(ROIAlign::mode)>(py::handle(mode));
  13090. } CATCH_ALL(-1)
  13091. }
  13092. if (format) {
  13093. try {
  13094. // TODO: remove this guard which is used for pybind11 implicit conversion
  13095. py::detail::loader_life_support guard{};
  13096. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().format =
  13097. py::cast<decltype(ROIAlign::format)>(py::handle(format));
  13098. } CATCH_ALL(-1)
  13099. }
  13100. if (spatial_scale) {
  13101. try {
  13102. // TODO: remove this guard which is used for pybind11 implicit conversion
  13103. py::detail::loader_life_support guard{};
  13104. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().spatial_scale =
  13105. py::cast<decltype(ROIAlign::spatial_scale)>(py::handle(spatial_scale));
  13106. } CATCH_ALL(-1)
  13107. }
  13108. if (offset) {
  13109. try {
  13110. // TODO: remove this guard which is used for pybind11 implicit conversion
  13111. py::detail::loader_life_support guard{};
  13112. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().offset =
  13113. py::cast<decltype(ROIAlign::offset)>(py::handle(offset));
  13114. } CATCH_ALL(-1)
  13115. }
  13116. if (pooled_height) {
  13117. try {
  13118. // TODO: remove this guard which is used for pybind11 implicit conversion
  13119. py::detail::loader_life_support guard{};
  13120. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().pooled_height =
  13121. py::cast<decltype(ROIAlign::pooled_height)>(py::handle(pooled_height));
  13122. } CATCH_ALL(-1)
  13123. }
  13124. if (pooled_width) {
  13125. try {
  13126. // TODO: remove this guard which is used for pybind11 implicit conversion
  13127. py::detail::loader_life_support guard{};
  13128. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().pooled_width =
  13129. py::cast<decltype(ROIAlign::pooled_width)>(py::handle(pooled_width));
  13130. } CATCH_ALL(-1)
  13131. }
  13132. if (sample_height) {
  13133. try {
  13134. // TODO: remove this guard which is used for pybind11 implicit conversion
  13135. py::detail::loader_life_support guard{};
  13136. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().sample_height =
  13137. py::cast<decltype(ROIAlign::sample_height)>(py::handle(sample_height));
  13138. } CATCH_ALL(-1)
  13139. }
  13140. if (sample_width) {
  13141. try {
  13142. // TODO: remove this guard which is used for pybind11 implicit conversion
  13143. py::detail::loader_life_support guard{};
  13144. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().sample_width =
  13145. py::cast<decltype(ROIAlign::sample_width)>(py::handle(sample_width));
  13146. } CATCH_ALL(-1)
  13147. }
  13148. if (scope) {
  13149. try {
  13150. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13151. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13152. } CATCH_ALL(-1)
  13153. }
  13154. return 0;
  13155. }
  13156. PyGetSetDef PyOp(ROIAlign)::py_getsetters[] = {
  13157. {const_cast<char*>("mode"), py_get_generic(ROIAlign, mode), py_set_generic(ROIAlign, mode), const_cast<char*>("mode"), NULL},
  13158. {const_cast<char*>("format"), py_get_generic(ROIAlign, format), py_set_generic(ROIAlign, format), const_cast<char*>("format"), NULL},
  13159. {const_cast<char*>("spatial_scale"), py_get_generic(ROIAlign, spatial_scale), py_set_generic(ROIAlign, spatial_scale), const_cast<char*>("spatial_scale"), NULL},
  13160. {const_cast<char*>("offset"), py_get_generic(ROIAlign, offset), py_set_generic(ROIAlign, offset), const_cast<char*>("offset"), NULL},
  13161. {const_cast<char*>("pooled_height"), py_get_generic(ROIAlign, pooled_height), py_set_generic(ROIAlign, pooled_height), const_cast<char*>("pooled_height"), NULL},
  13162. {const_cast<char*>("pooled_width"), py_get_generic(ROIAlign, pooled_width), py_set_generic(ROIAlign, pooled_width), const_cast<char*>("pooled_width"), NULL},
  13163. {const_cast<char*>("sample_height"), py_get_generic(ROIAlign, sample_height), py_set_generic(ROIAlign, sample_height), const_cast<char*>("sample_height"), NULL},
  13164. {const_cast<char*>("sample_width"), py_get_generic(ROIAlign, sample_width), py_set_generic(ROIAlign, sample_width), const_cast<char*>("sample_width"), NULL},
  13165. {NULL} /* Sentinel */
  13166. };
  13167. PyMethodDef PyOp(ROIAlign)::tp_methods[] = {
  13168. {const_cast<char*>("__getstate__"), PyOp(ROIAlign)::getstate, METH_NOARGS, "ROIAlign getstate"},
  13169. {const_cast<char*>("__setstate__"), PyOp(ROIAlign)::setstate, METH_VARARGS, "ROIAlign setstate"},
  13170. {NULL} /* Sentinel */
  13171. };
  13172. void _init_py_ROIAlign(py::module m) {
  13173. using py_op = PyOp(ROIAlign);
  13174. auto& py_type = PyOpType(ROIAlign);
  13175. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13176. py_type.tp_name = "megengine.core._imperative_rt.ops.ROIAlign";
  13177. py_type.tp_basicsize = sizeof(PyOp(ROIAlign));
  13178. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13179. py_type.tp_doc = "ROIAlign";
  13180. py_type.tp_base = &PyOpType(OpDef);
  13181. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13182. py_type.tp_new = py_new_generic<py_op>;
  13183. py_type.tp_init = py_op::py_init;
  13184. py_type.tp_methods = py_op::tp_methods;
  13185. py_type.tp_getset = py_op::py_getsetters;
  13186. mgb_assert(PyType_Ready(&py_type) >= 0);
  13187. _init_py_ROIAlign_Mode(py_type);
  13188. _init_py_ROIAlign_Format(py_type);
  13189. PyType_Modified(&py_type);
  13190. m.add_object("ROIAlign", reinterpret_cast<PyObject*>(&py_type));
  13191. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIAlign::typeinfo(), &py_type).second);
  13192. }
  13193. template<> struct EnumTrait<ROIPooling::Mode> {
  13194. static constexpr const char *name = "ROIPooling.Mode";
  13195. static constexpr std::underlying_type_t<ROIPooling::Mode> max = 2 - 1;
  13196. };
  13197. template<> PyTypeObject* EnumWrapper<ROIPooling::Mode>::type = nullptr;
  13198. template<> const char*
  13199. EnumWrapper<ROIPooling::Mode>::members[] = {"MAX", "AVERAGE"};
  13200. template<> std::unordered_map<std::string, ROIPooling::Mode>
  13201. EnumWrapper<ROIPooling::Mode>::mem2value = {{normalize_enum("MAX"), ROIPooling::Mode::MAX}, {normalize_enum("AVERAGE"), ROIPooling::Mode::AVERAGE}};
  13202. template<> PyObject* EnumWrapper<ROIPooling::Mode>::pyobj_insts[2] = {nullptr};
  13203. void _init_py_ROIPooling_Mode(PyTypeObject& py_type) {
  13204. auto& e_type = EnumWrapper<ROIPooling::Mode>::type;
  13205. static PyMethodDef tp_methods[] = {
  13206. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ROIPooling::Mode>::py_dump, METH_NOARGS, NULL},
  13207. {NULL} /* Sentinel */
  13208. };
  13209. static PyType_Slot slots[] = {
  13210. {Py_tp_repr, (void*)EnumWrapper<ROIPooling::Mode>::py_repr},
  13211. {Py_tp_richcompare, (void*)EnumWrapper<ROIPooling::Mode>::tp_richcompare},
  13212. {Py_tp_methods, tp_methods},
  13213. {0, NULL}
  13214. };
  13215. static PyType_Spec spec = {
  13216. // name
  13217. "megengine.core._imperative_rt.ops.ROIPooling.Mode",
  13218. // basicsize
  13219. sizeof(EnumWrapper<ROIPooling::Mode>),
  13220. // itemsize
  13221. 0,
  13222. // flags
  13223. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13224. // slots
  13225. slots
  13226. };
  13227. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13228. mgb_assert(
  13229. e_type->tp_setattro(
  13230. reinterpret_cast<PyObject*>(e_type),
  13231. py::cast("__name__").release().ptr(),
  13232. py::cast("Mode").release().ptr()) >= 0);
  13233. mgb_assert(
  13234. e_type->tp_setattro(
  13235. reinterpret_cast<PyObject*>(e_type),
  13236. py::cast("__module__").release().ptr(),
  13237. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13238. mgb_assert(
  13239. e_type->tp_setattro(
  13240. reinterpret_cast<PyObject*>(e_type),
  13241. py::cast("__qualname__").release().ptr(),
  13242. py::cast("ROIPooling.Mode").release().ptr()) >= 0);
  13243. {
  13244. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13245. reinterpret_cast<EnumWrapper<ROIPooling::Mode>*>(inst)->value = ROIPooling::Mode::MAX;
  13246. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  13247. EnumWrapper<ROIPooling::Mode>::pyobj_insts[0] = inst;
  13248. }{
  13249. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13250. reinterpret_cast<EnumWrapper<ROIPooling::Mode>*>(inst)->value = ROIPooling::Mode::AVERAGE;
  13251. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  13252. EnumWrapper<ROIPooling::Mode>::pyobj_insts[1] = inst;
  13253. }
  13254. Py_INCREF(e_type);
  13255. mgb_assert(PyDict_SetItemString(
  13256. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13257. }
  13258. PyOpDefBegin(ROIPooling) // {
  13259. static PyGetSetDef py_getsetters[];
  13260. static PyMethodDef tp_methods[];
  13261. static PyObject* getstate(PyObject* self, PyObject*) {
  13262. auto& opdef = reinterpret_cast<PyOp(ROIPooling)*>(self)->inst();
  13263. static_cast<void>(opdef);
  13264. std::unordered_map<std::string, py::object> state {
  13265. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13266. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)}
  13267. };
  13268. return py::cast(state).release().ptr();
  13269. }
  13270. static PyObject* setstate(PyObject* self, PyObject* args) {
  13271. PyObject* dict = PyTuple_GetItem(args, 0);
  13272. if (!dict) return NULL;
  13273. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13274. auto& opdef = reinterpret_cast<PyOp(ROIPooling)*>(self)->inst();
  13275. static_cast<void>(opdef);
  13276. {
  13277. auto&& iter = state.find("mode");
  13278. if (iter != state.end()) {
  13279. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13280. }
  13281. }
  13282. {
  13283. auto&& iter = state.find("scale");
  13284. if (iter != state.end()) {
  13285. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  13286. }
  13287. }
  13288. Py_RETURN_NONE;
  13289. }
  13290. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13291. // };
  13292. PyOpDefEnd(ROIPooling)
  13293. int PyOp(ROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13294. static const char* kwlist[] = {"mode", "scale", "scope", NULL};
  13295. PyObject *mode = NULL, *scale = NULL, *scope = NULL;
  13296. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &mode, &scale, &scope))
  13297. return -1;
  13298. if (mode) {
  13299. try {
  13300. // TODO: remove this guard which is used for pybind11 implicit conversion
  13301. py::detail::loader_life_support guard{};
  13302. reinterpret_cast<PyOp(ROIPooling)*>(self)->inst().mode =
  13303. py::cast<decltype(ROIPooling::mode)>(py::handle(mode));
  13304. } CATCH_ALL(-1)
  13305. }
  13306. if (scale) {
  13307. try {
  13308. // TODO: remove this guard which is used for pybind11 implicit conversion
  13309. py::detail::loader_life_support guard{};
  13310. reinterpret_cast<PyOp(ROIPooling)*>(self)->inst().scale =
  13311. py::cast<decltype(ROIPooling::scale)>(py::handle(scale));
  13312. } CATCH_ALL(-1)
  13313. }
  13314. if (scope) {
  13315. try {
  13316. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13317. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13318. } CATCH_ALL(-1)
  13319. }
  13320. return 0;
  13321. }
  13322. PyGetSetDef PyOp(ROIPooling)::py_getsetters[] = {
  13323. {const_cast<char*>("mode"), py_get_generic(ROIPooling, mode), py_set_generic(ROIPooling, mode), const_cast<char*>("mode"), NULL},
  13324. {const_cast<char*>("scale"), py_get_generic(ROIPooling, scale), py_set_generic(ROIPooling, scale), const_cast<char*>("scale"), NULL},
  13325. {NULL} /* Sentinel */
  13326. };
  13327. PyMethodDef PyOp(ROIPooling)::tp_methods[] = {
  13328. {const_cast<char*>("__getstate__"), PyOp(ROIPooling)::getstate, METH_NOARGS, "ROIPooling getstate"},
  13329. {const_cast<char*>("__setstate__"), PyOp(ROIPooling)::setstate, METH_VARARGS, "ROIPooling setstate"},
  13330. {NULL} /* Sentinel */
  13331. };
  13332. void _init_py_ROIPooling(py::module m) {
  13333. using py_op = PyOp(ROIPooling);
  13334. auto& py_type = PyOpType(ROIPooling);
  13335. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13336. py_type.tp_name = "megengine.core._imperative_rt.ops.ROIPooling";
  13337. py_type.tp_basicsize = sizeof(PyOp(ROIPooling));
  13338. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13339. py_type.tp_doc = "ROIPooling";
  13340. py_type.tp_base = &PyOpType(OpDef);
  13341. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13342. py_type.tp_new = py_new_generic<py_op>;
  13343. py_type.tp_init = py_op::py_init;
  13344. py_type.tp_methods = py_op::tp_methods;
  13345. py_type.tp_getset = py_op::py_getsetters;
  13346. mgb_assert(PyType_Ready(&py_type) >= 0);
  13347. _init_py_ROIPooling_Mode(py_type);
  13348. PyType_Modified(&py_type);
  13349. m.add_object("ROIPooling", reinterpret_cast<PyObject*>(&py_type));
  13350. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIPooling::typeinfo(), &py_type).second);
  13351. }
  13352. template<> struct EnumTrait<Reduce::Mode> {
  13353. static constexpr const char *name = "Reduce.Mode";
  13354. static constexpr std::underlying_type_t<Reduce::Mode> max = 6 - 1;
  13355. };
  13356. template<> PyTypeObject* EnumWrapper<Reduce::Mode>::type = nullptr;
  13357. template<> const char*
  13358. EnumWrapper<Reduce::Mode>::members[] = {"SUM", "SUM_SQR", "PRODUCT", "MIN", "MAX", "MEAN"};
  13359. template<> std::unordered_map<std::string, Reduce::Mode>
  13360. EnumWrapper<Reduce::Mode>::mem2value = {{normalize_enum("SUM"), Reduce::Mode::SUM}, {normalize_enum("SUM_SQR"), Reduce::Mode::SUM_SQR}, {normalize_enum("PRODUCT"), Reduce::Mode::PRODUCT}, {normalize_enum("MIN"), Reduce::Mode::MIN}, {normalize_enum("MAX"), Reduce::Mode::MAX}, {normalize_enum("MEAN"), Reduce::Mode::MEAN}};
  13361. template<> PyObject* EnumWrapper<Reduce::Mode>::pyobj_insts[6] = {nullptr};
  13362. void _init_py_Reduce_Mode(PyTypeObject& py_type) {
  13363. auto& e_type = EnumWrapper<Reduce::Mode>::type;
  13364. static PyMethodDef tp_methods[] = {
  13365. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Reduce::Mode>::py_dump, METH_NOARGS, NULL},
  13366. {NULL} /* Sentinel */
  13367. };
  13368. static PyType_Slot slots[] = {
  13369. {Py_tp_repr, (void*)EnumWrapper<Reduce::Mode>::py_repr},
  13370. {Py_tp_richcompare, (void*)EnumWrapper<Reduce::Mode>::tp_richcompare},
  13371. {Py_tp_methods, tp_methods},
  13372. {0, NULL}
  13373. };
  13374. static PyType_Spec spec = {
  13375. // name
  13376. "megengine.core._imperative_rt.ops.Reduce.Mode",
  13377. // basicsize
  13378. sizeof(EnumWrapper<Reduce::Mode>),
  13379. // itemsize
  13380. 0,
  13381. // flags
  13382. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13383. // slots
  13384. slots
  13385. };
  13386. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13387. mgb_assert(
  13388. e_type->tp_setattro(
  13389. reinterpret_cast<PyObject*>(e_type),
  13390. py::cast("__name__").release().ptr(),
  13391. py::cast("Mode").release().ptr()) >= 0);
  13392. mgb_assert(
  13393. e_type->tp_setattro(
  13394. reinterpret_cast<PyObject*>(e_type),
  13395. py::cast("__module__").release().ptr(),
  13396. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13397. mgb_assert(
  13398. e_type->tp_setattro(
  13399. reinterpret_cast<PyObject*>(e_type),
  13400. py::cast("__qualname__").release().ptr(),
  13401. py::cast("Reduce.Mode").release().ptr()) >= 0);
  13402. {
  13403. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13404. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::SUM;
  13405. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM", inst) >= 0);
  13406. EnumWrapper<Reduce::Mode>::pyobj_insts[0] = inst;
  13407. }{
  13408. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13409. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::SUM_SQR;
  13410. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM_SQR", inst) >= 0);
  13411. EnumWrapper<Reduce::Mode>::pyobj_insts[1] = inst;
  13412. }{
  13413. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13414. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::PRODUCT;
  13415. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PRODUCT", inst) >= 0);
  13416. EnumWrapper<Reduce::Mode>::pyobj_insts[2] = inst;
  13417. }{
  13418. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13419. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MIN;
  13420. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0);
  13421. EnumWrapper<Reduce::Mode>::pyobj_insts[3] = inst;
  13422. }{
  13423. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13424. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MAX;
  13425. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  13426. EnumWrapper<Reduce::Mode>::pyobj_insts[4] = inst;
  13427. }{
  13428. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13429. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MEAN;
  13430. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MEAN", inst) >= 0);
  13431. EnumWrapper<Reduce::Mode>::pyobj_insts[5] = inst;
  13432. }
  13433. Py_INCREF(e_type);
  13434. mgb_assert(PyDict_SetItemString(
  13435. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13436. }
  13437. template<> struct EnumTrait<Reduce::DataType> {
  13438. static constexpr const char *name = "Reduce.DataType";
  13439. static constexpr std::underlying_type_t<Reduce::DataType> max = 6 - 1;
  13440. };
  13441. template<> PyTypeObject* EnumWrapper<Reduce::DataType>::type = nullptr;
  13442. template<> const char*
  13443. EnumWrapper<Reduce::DataType>::members[] = {"DEFAULT", "FLOAT_IO16xC32", "FLOAT_O32xC32", "FLOAT_O16xC32", "QUINT_I8xO32", "QINT_I8xO32"};
  13444. template<> std::unordered_map<std::string, Reduce::DataType>
  13445. EnumWrapper<Reduce::DataType>::mem2value = {{normalize_enum("DEFAULT"), Reduce::DataType::DEFAULT}, {normalize_enum("FLOAT_IO16xC32"), Reduce::DataType::FLOAT_IO16xC32}, {normalize_enum("FLOAT_O32xC32"), Reduce::DataType::FLOAT_O32xC32}, {normalize_enum("FLOAT_O16xC32"), Reduce::DataType::FLOAT_O16xC32}, {normalize_enum("QUINT_I8xO32"), Reduce::DataType::QUINT_I8xO32}, {normalize_enum("QINT_I8xO32"), Reduce::DataType::QINT_I8xO32}};
  13446. template<> PyObject* EnumWrapper<Reduce::DataType>::pyobj_insts[6] = {nullptr};
  13447. void _init_py_Reduce_DataType(PyTypeObject& py_type) {
  13448. auto& e_type = EnumWrapper<Reduce::DataType>::type;
  13449. static PyMethodDef tp_methods[] = {
  13450. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Reduce::DataType>::py_dump, METH_NOARGS, NULL},
  13451. {NULL} /* Sentinel */
  13452. };
  13453. static PyType_Slot slots[] = {
  13454. {Py_tp_repr, (void*)EnumWrapper<Reduce::DataType>::py_repr},
  13455. {Py_tp_richcompare, (void*)EnumWrapper<Reduce::DataType>::tp_richcompare},
  13456. {Py_tp_methods, tp_methods},
  13457. {0, NULL}
  13458. };
  13459. static PyType_Spec spec = {
  13460. // name
  13461. "megengine.core._imperative_rt.ops.Reduce.DataType",
  13462. // basicsize
  13463. sizeof(EnumWrapper<Reduce::DataType>),
  13464. // itemsize
  13465. 0,
  13466. // flags
  13467. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13468. // slots
  13469. slots
  13470. };
  13471. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13472. mgb_assert(
  13473. e_type->tp_setattro(
  13474. reinterpret_cast<PyObject*>(e_type),
  13475. py::cast("__name__").release().ptr(),
  13476. py::cast("DataType").release().ptr()) >= 0);
  13477. mgb_assert(
  13478. e_type->tp_setattro(
  13479. reinterpret_cast<PyObject*>(e_type),
  13480. py::cast("__module__").release().ptr(),
  13481. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13482. mgb_assert(
  13483. e_type->tp_setattro(
  13484. reinterpret_cast<PyObject*>(e_type),
  13485. py::cast("__qualname__").release().ptr(),
  13486. py::cast("Reduce.DataType").release().ptr()) >= 0);
  13487. {
  13488. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13489. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::DEFAULT;
  13490. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  13491. EnumWrapper<Reduce::DataType>::pyobj_insts[0] = inst;
  13492. }{
  13493. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13494. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_IO16xC32;
  13495. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_IO16xC32", inst) >= 0);
  13496. EnumWrapper<Reduce::DataType>::pyobj_insts[1] = inst;
  13497. }{
  13498. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13499. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_O32xC32;
  13500. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O32xC32", inst) >= 0);
  13501. EnumWrapper<Reduce::DataType>::pyobj_insts[2] = inst;
  13502. }{
  13503. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13504. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_O16xC32;
  13505. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O16xC32", inst) >= 0);
  13506. EnumWrapper<Reduce::DataType>::pyobj_insts[3] = inst;
  13507. }{
  13508. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13509. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::QUINT_I8xO32;
  13510. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QUINT_I8xO32", inst) >= 0);
  13511. EnumWrapper<Reduce::DataType>::pyobj_insts[4] = inst;
  13512. }{
  13513. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13514. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::QINT_I8xO32;
  13515. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QINT_I8xO32", inst) >= 0);
  13516. EnumWrapper<Reduce::DataType>::pyobj_insts[5] = inst;
  13517. }
  13518. Py_INCREF(e_type);
  13519. mgb_assert(PyDict_SetItemString(
  13520. py_type.tp_dict, "DataType", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13521. }
  13522. PyOpDefBegin(Reduce) // {
  13523. static PyGetSetDef py_getsetters[];
  13524. static PyMethodDef tp_methods[];
  13525. static PyObject* getstate(PyObject* self, PyObject*) {
  13526. auto& opdef = reinterpret_cast<PyOp(Reduce)*>(self)->inst();
  13527. static_cast<void>(opdef);
  13528. std::unordered_map<std::string, py::object> state {
  13529. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13530. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  13531. {"data_type", serialization<decltype(opdef.data_type)>::dump(opdef.data_type)},
  13532. {"keepdim", serialization<decltype(opdef.keepdim)>::dump(opdef.keepdim)}
  13533. };
  13534. return py::cast(state).release().ptr();
  13535. }
  13536. static PyObject* setstate(PyObject* self, PyObject* args) {
  13537. PyObject* dict = PyTuple_GetItem(args, 0);
  13538. if (!dict) return NULL;
  13539. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13540. auto& opdef = reinterpret_cast<PyOp(Reduce)*>(self)->inst();
  13541. static_cast<void>(opdef);
  13542. {
  13543. auto&& iter = state.find("mode");
  13544. if (iter != state.end()) {
  13545. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13546. }
  13547. }
  13548. {
  13549. auto&& iter = state.find("axis");
  13550. if (iter != state.end()) {
  13551. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  13552. }
  13553. }
  13554. {
  13555. auto&& iter = state.find("data_type");
  13556. if (iter != state.end()) {
  13557. opdef.data_type = serialization<decltype(opdef.data_type)>::load(iter->second);
  13558. }
  13559. }
  13560. {
  13561. auto&& iter = state.find("keepdim");
  13562. if (iter != state.end()) {
  13563. opdef.keepdim = serialization<decltype(opdef.keepdim)>::load(iter->second);
  13564. }
  13565. }
  13566. Py_RETURN_NONE;
  13567. }
  13568. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13569. // };
  13570. PyOpDefEnd(Reduce)
  13571. int PyOp(Reduce)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13572. static const char* kwlist[] = {"mode", "axis", "data_type", "keepdim", "scope", NULL};
  13573. PyObject *mode = NULL, *axis = NULL, *data_type = NULL, *keepdim = NULL, *scope = NULL;
  13574. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &mode, &axis, &data_type, &keepdim, &scope))
  13575. return -1;
  13576. if (mode) {
  13577. try {
  13578. // TODO: remove this guard which is used for pybind11 implicit conversion
  13579. py::detail::loader_life_support guard{};
  13580. reinterpret_cast<PyOp(Reduce)*>(self)->inst().mode =
  13581. py::cast<decltype(Reduce::mode)>(py::handle(mode));
  13582. } CATCH_ALL(-1)
  13583. }
  13584. if (axis) {
  13585. try {
  13586. // TODO: remove this guard which is used for pybind11 implicit conversion
  13587. py::detail::loader_life_support guard{};
  13588. reinterpret_cast<PyOp(Reduce)*>(self)->inst().axis =
  13589. py::cast<decltype(Reduce::axis)>(py::handle(axis));
  13590. } CATCH_ALL(-1)
  13591. }
  13592. if (data_type) {
  13593. try {
  13594. // TODO: remove this guard which is used for pybind11 implicit conversion
  13595. py::detail::loader_life_support guard{};
  13596. reinterpret_cast<PyOp(Reduce)*>(self)->inst().data_type =
  13597. py::cast<decltype(Reduce::data_type)>(py::handle(data_type));
  13598. } CATCH_ALL(-1)
  13599. }
  13600. if (keepdim) {
  13601. try {
  13602. // TODO: remove this guard which is used for pybind11 implicit conversion
  13603. py::detail::loader_life_support guard{};
  13604. reinterpret_cast<PyOp(Reduce)*>(self)->inst().keepdim =
  13605. py::cast<decltype(Reduce::keepdim)>(py::handle(keepdim));
  13606. } CATCH_ALL(-1)
  13607. }
  13608. if (scope) {
  13609. try {
  13610. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13611. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13612. } CATCH_ALL(-1)
  13613. }
  13614. return 0;
  13615. }
  13616. PyGetSetDef PyOp(Reduce)::py_getsetters[] = {
  13617. {const_cast<char*>("mode"), py_get_generic(Reduce, mode), py_set_generic(Reduce, mode), const_cast<char*>("mode"), NULL},
  13618. {const_cast<char*>("axis"), py_get_generic(Reduce, axis), py_set_generic(Reduce, axis), const_cast<char*>("axis"), NULL},
  13619. {const_cast<char*>("data_type"), py_get_generic(Reduce, data_type), py_set_generic(Reduce, data_type), const_cast<char*>("data_type"), NULL},
  13620. {const_cast<char*>("keepdim"), py_get_generic(Reduce, keepdim), py_set_generic(Reduce, keepdim), const_cast<char*>("keepdim"), NULL},
  13621. {NULL} /* Sentinel */
  13622. };
  13623. PyMethodDef PyOp(Reduce)::tp_methods[] = {
  13624. {const_cast<char*>("__getstate__"), PyOp(Reduce)::getstate, METH_NOARGS, "Reduce getstate"},
  13625. {const_cast<char*>("__setstate__"), PyOp(Reduce)::setstate, METH_VARARGS, "Reduce setstate"},
  13626. {NULL} /* Sentinel */
  13627. };
  13628. void _init_py_Reduce(py::module m) {
  13629. using py_op = PyOp(Reduce);
  13630. auto& py_type = PyOpType(Reduce);
  13631. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13632. py_type.tp_name = "megengine.core._imperative_rt.ops.Reduce";
  13633. py_type.tp_basicsize = sizeof(PyOp(Reduce));
  13634. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13635. py_type.tp_doc = "Reduce";
  13636. py_type.tp_base = &PyOpType(OpDef);
  13637. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13638. py_type.tp_new = py_new_generic<py_op>;
  13639. py_type.tp_init = py_op::py_init;
  13640. py_type.tp_methods = py_op::tp_methods;
  13641. py_type.tp_getset = py_op::py_getsetters;
  13642. mgb_assert(PyType_Ready(&py_type) >= 0);
  13643. _init_py_Reduce_Mode(py_type);
  13644. _init_py_Reduce_DataType(py_type);
  13645. PyType_Modified(&py_type);
  13646. m.add_object("Reduce", reinterpret_cast<PyObject*>(&py_type));
  13647. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reduce::typeinfo(), &py_type).second);
  13648. }
  13649. template<> struct EnumTrait<Remap::InterpolationMode> {
  13650. static constexpr const char *name = "Remap.InterpolationMode";
  13651. static constexpr std::underlying_type_t<Remap::InterpolationMode> max = 5 - 1;
  13652. };
  13653. template<> PyTypeObject* EnumWrapper<Remap::InterpolationMode>::type = nullptr;
  13654. template<> const char*
  13655. EnumWrapper<Remap::InterpolationMode>::members[] = {"NEAREST", "LINEAR", "AREA", "CUBIC", "LANCZOS4"};
  13656. template<> std::unordered_map<std::string, Remap::InterpolationMode>
  13657. EnumWrapper<Remap::InterpolationMode>::mem2value = {{normalize_enum("NEAREST"), Remap::InterpolationMode::NEAREST}, {normalize_enum("LINEAR"), Remap::InterpolationMode::LINEAR}, {normalize_enum("AREA"), Remap::InterpolationMode::AREA}, {normalize_enum("CUBIC"), Remap::InterpolationMode::CUBIC}, {normalize_enum("LANCZOS4"), Remap::InterpolationMode::LANCZOS4}};
  13658. template<> PyObject* EnumWrapper<Remap::InterpolationMode>::pyobj_insts[5] = {nullptr};
  13659. void _init_py_Remap_InterpolationMode(PyTypeObject& py_type) {
  13660. auto& e_type = EnumWrapper<Remap::InterpolationMode>::type;
  13661. static PyMethodDef tp_methods[] = {
  13662. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Remap::InterpolationMode>::py_dump, METH_NOARGS, NULL},
  13663. {NULL} /* Sentinel */
  13664. };
  13665. static PyType_Slot slots[] = {
  13666. {Py_tp_repr, (void*)EnumWrapper<Remap::InterpolationMode>::py_repr},
  13667. {Py_tp_richcompare, (void*)EnumWrapper<Remap::InterpolationMode>::tp_richcompare},
  13668. {Py_tp_methods, tp_methods},
  13669. {0, NULL}
  13670. };
  13671. static PyType_Spec spec = {
  13672. // name
  13673. "megengine.core._imperative_rt.ops.Remap.InterpolationMode",
  13674. // basicsize
  13675. sizeof(EnumWrapper<Remap::InterpolationMode>),
  13676. // itemsize
  13677. 0,
  13678. // flags
  13679. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13680. // slots
  13681. slots
  13682. };
  13683. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13684. mgb_assert(
  13685. e_type->tp_setattro(
  13686. reinterpret_cast<PyObject*>(e_type),
  13687. py::cast("__name__").release().ptr(),
  13688. py::cast("InterpolationMode").release().ptr()) >= 0);
  13689. mgb_assert(
  13690. e_type->tp_setattro(
  13691. reinterpret_cast<PyObject*>(e_type),
  13692. py::cast("__module__").release().ptr(),
  13693. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13694. mgb_assert(
  13695. e_type->tp_setattro(
  13696. reinterpret_cast<PyObject*>(e_type),
  13697. py::cast("__qualname__").release().ptr(),
  13698. py::cast("Remap.InterpolationMode").release().ptr()) >= 0);
  13699. {
  13700. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13701. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::NEAREST;
  13702. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEAREST", inst) >= 0);
  13703. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[0] = inst;
  13704. }{
  13705. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13706. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::LINEAR;
  13707. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LINEAR", inst) >= 0);
  13708. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[1] = inst;
  13709. }{
  13710. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13711. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::AREA;
  13712. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AREA", inst) >= 0);
  13713. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[2] = inst;
  13714. }{
  13715. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13716. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::CUBIC;
  13717. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CUBIC", inst) >= 0);
  13718. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[3] = inst;
  13719. }{
  13720. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13721. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::LANCZOS4;
  13722. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LANCZOS4", inst) >= 0);
  13723. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[4] = inst;
  13724. }
  13725. Py_INCREF(e_type);
  13726. mgb_assert(PyDict_SetItemString(
  13727. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13728. }
  13729. template<> struct EnumTrait<Remap::BorderMode> {
  13730. static constexpr const char *name = "Remap.BorderMode";
  13731. static constexpr std::underlying_type_t<Remap::BorderMode> max = 7 - 1;
  13732. };
  13733. template<> PyTypeObject* EnumWrapper<Remap::BorderMode>::type = nullptr;
  13734. template<> const char*
  13735. EnumWrapper<Remap::BorderMode>::members[] = {"REPLICATE", "REFLECT", "REFLECT_101", "WRAP", "CONSTANT", "TRANSPARENT", "ISOLATED"};
  13736. template<> std::unordered_map<std::string, Remap::BorderMode>
  13737. EnumWrapper<Remap::BorderMode>::mem2value = {{normalize_enum("REPLICATE"), Remap::BorderMode::REPLICATE}, {normalize_enum("REFLECT"), Remap::BorderMode::REFLECT}, {normalize_enum("REFLECT_101"), Remap::BorderMode::REFLECT_101}, {normalize_enum("WRAP"), Remap::BorderMode::WRAP}, {normalize_enum("CONSTANT"), Remap::BorderMode::CONSTANT}, {normalize_enum("TRANSPARENT"), Remap::BorderMode::TRANSPARENT}, {normalize_enum("ISOLATED"), Remap::BorderMode::ISOLATED}};
  13738. template<> PyObject* EnumWrapper<Remap::BorderMode>::pyobj_insts[7] = {nullptr};
  13739. void _init_py_Remap_BorderMode(PyTypeObject& py_type) {
  13740. auto& e_type = EnumWrapper<Remap::BorderMode>::type;
  13741. static PyMethodDef tp_methods[] = {
  13742. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Remap::BorderMode>::py_dump, METH_NOARGS, NULL},
  13743. {NULL} /* Sentinel */
  13744. };
  13745. static PyType_Slot slots[] = {
  13746. {Py_tp_repr, (void*)EnumWrapper<Remap::BorderMode>::py_repr},
  13747. {Py_tp_richcompare, (void*)EnumWrapper<Remap::BorderMode>::tp_richcompare},
  13748. {Py_tp_methods, tp_methods},
  13749. {0, NULL}
  13750. };
  13751. static PyType_Spec spec = {
  13752. // name
  13753. "megengine.core._imperative_rt.ops.Remap.BorderMode",
  13754. // basicsize
  13755. sizeof(EnumWrapper<Remap::BorderMode>),
  13756. // itemsize
  13757. 0,
  13758. // flags
  13759. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13760. // slots
  13761. slots
  13762. };
  13763. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13764. mgb_assert(
  13765. e_type->tp_setattro(
  13766. reinterpret_cast<PyObject*>(e_type),
  13767. py::cast("__name__").release().ptr(),
  13768. py::cast("BorderMode").release().ptr()) >= 0);
  13769. mgb_assert(
  13770. e_type->tp_setattro(
  13771. reinterpret_cast<PyObject*>(e_type),
  13772. py::cast("__module__").release().ptr(),
  13773. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13774. mgb_assert(
  13775. e_type->tp_setattro(
  13776. reinterpret_cast<PyObject*>(e_type),
  13777. py::cast("__qualname__").release().ptr(),
  13778. py::cast("Remap.BorderMode").release().ptr()) >= 0);
  13779. {
  13780. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13781. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REPLICATE;
  13782. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0);
  13783. EnumWrapper<Remap::BorderMode>::pyobj_insts[0] = inst;
  13784. }{
  13785. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13786. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REFLECT;
  13787. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0);
  13788. EnumWrapper<Remap::BorderMode>::pyobj_insts[1] = inst;
  13789. }{
  13790. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13791. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REFLECT_101;
  13792. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT_101", inst) >= 0);
  13793. EnumWrapper<Remap::BorderMode>::pyobj_insts[2] = inst;
  13794. }{
  13795. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13796. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::WRAP;
  13797. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "WRAP", inst) >= 0);
  13798. EnumWrapper<Remap::BorderMode>::pyobj_insts[3] = inst;
  13799. }{
  13800. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13801. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::CONSTANT;
  13802. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0);
  13803. EnumWrapper<Remap::BorderMode>::pyobj_insts[4] = inst;
  13804. }{
  13805. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13806. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::TRANSPARENT;
  13807. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRANSPARENT", inst) >= 0);
  13808. EnumWrapper<Remap::BorderMode>::pyobj_insts[5] = inst;
  13809. }{
  13810. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13811. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::ISOLATED;
  13812. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISOLATED", inst) >= 0);
  13813. EnumWrapper<Remap::BorderMode>::pyobj_insts[6] = inst;
  13814. }
  13815. Py_INCREF(e_type);
  13816. mgb_assert(PyDict_SetItemString(
  13817. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13818. }
  13819. void _init_py_Remap_Format(PyTypeObject& py_type) {
  13820. auto& e_type = EnumWrapper<Remap::Format>::type;
  13821. Py_INCREF(e_type);
  13822. mgb_assert(PyDict_SetItemString(
  13823. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13824. }
  13825. PyOpDefBegin(Remap) // {
  13826. static PyGetSetDef py_getsetters[];
  13827. static PyMethodDef tp_methods[];
  13828. static PyObject* getstate(PyObject* self, PyObject*) {
  13829. auto& opdef = reinterpret_cast<PyOp(Remap)*>(self)->inst();
  13830. static_cast<void>(opdef);
  13831. std::unordered_map<std::string, py::object> state {
  13832. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  13833. {"border_type", serialization<decltype(opdef.border_type)>::dump(opdef.border_type)},
  13834. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  13835. {"scalar", serialization<decltype(opdef.scalar)>::dump(opdef.scalar)}
  13836. };
  13837. return py::cast(state).release().ptr();
  13838. }
  13839. static PyObject* setstate(PyObject* self, PyObject* args) {
  13840. PyObject* dict = PyTuple_GetItem(args, 0);
  13841. if (!dict) return NULL;
  13842. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13843. auto& opdef = reinterpret_cast<PyOp(Remap)*>(self)->inst();
  13844. static_cast<void>(opdef);
  13845. {
  13846. auto&& iter = state.find("imode");
  13847. if (iter != state.end()) {
  13848. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  13849. }
  13850. }
  13851. {
  13852. auto&& iter = state.find("border_type");
  13853. if (iter != state.end()) {
  13854. opdef.border_type = serialization<decltype(opdef.border_type)>::load(iter->second);
  13855. }
  13856. }
  13857. {
  13858. auto&& iter = state.find("format");
  13859. if (iter != state.end()) {
  13860. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  13861. }
  13862. }
  13863. {
  13864. auto&& iter = state.find("scalar");
  13865. if (iter != state.end()) {
  13866. opdef.scalar = serialization<decltype(opdef.scalar)>::load(iter->second);
  13867. }
  13868. }
  13869. Py_RETURN_NONE;
  13870. }
  13871. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13872. // };
  13873. PyOpDefEnd(Remap)
  13874. int PyOp(Remap)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13875. static const char* kwlist[] = {"imode", "border_type", "format", "scalar", "scope", NULL};
  13876. PyObject *imode = NULL, *border_type = NULL, *format = NULL, *scalar = NULL, *scope = NULL;
  13877. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &border_type, &format, &scalar, &scope))
  13878. return -1;
  13879. if (imode) {
  13880. try {
  13881. // TODO: remove this guard which is used for pybind11 implicit conversion
  13882. py::detail::loader_life_support guard{};
  13883. reinterpret_cast<PyOp(Remap)*>(self)->inst().imode =
  13884. py::cast<decltype(Remap::imode)>(py::handle(imode));
  13885. } CATCH_ALL(-1)
  13886. }
  13887. if (border_type) {
  13888. try {
  13889. // TODO: remove this guard which is used for pybind11 implicit conversion
  13890. py::detail::loader_life_support guard{};
  13891. reinterpret_cast<PyOp(Remap)*>(self)->inst().border_type =
  13892. py::cast<decltype(Remap::border_type)>(py::handle(border_type));
  13893. } CATCH_ALL(-1)
  13894. }
  13895. if (format) {
  13896. try {
  13897. // TODO: remove this guard which is used for pybind11 implicit conversion
  13898. py::detail::loader_life_support guard{};
  13899. reinterpret_cast<PyOp(Remap)*>(self)->inst().format =
  13900. py::cast<decltype(Remap::format)>(py::handle(format));
  13901. } CATCH_ALL(-1)
  13902. }
  13903. if (scalar) {
  13904. try {
  13905. // TODO: remove this guard which is used for pybind11 implicit conversion
  13906. py::detail::loader_life_support guard{};
  13907. reinterpret_cast<PyOp(Remap)*>(self)->inst().scalar =
  13908. py::cast<decltype(Remap::scalar)>(py::handle(scalar));
  13909. } CATCH_ALL(-1)
  13910. }
  13911. if (scope) {
  13912. try {
  13913. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13914. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13915. } CATCH_ALL(-1)
  13916. }
  13917. return 0;
  13918. }
  13919. PyGetSetDef PyOp(Remap)::py_getsetters[] = {
  13920. {const_cast<char*>("imode"), py_get_generic(Remap, imode), py_set_generic(Remap, imode), const_cast<char*>("imode"), NULL},
  13921. {const_cast<char*>("border_type"), py_get_generic(Remap, border_type), py_set_generic(Remap, border_type), const_cast<char*>("border_type"), NULL},
  13922. {const_cast<char*>("format"), py_get_generic(Remap, format), py_set_generic(Remap, format), const_cast<char*>("format"), NULL},
  13923. {const_cast<char*>("scalar"), py_get_generic(Remap, scalar), py_set_generic(Remap, scalar), const_cast<char*>("scalar"), NULL},
  13924. {NULL} /* Sentinel */
  13925. };
  13926. PyMethodDef PyOp(Remap)::tp_methods[] = {
  13927. {const_cast<char*>("__getstate__"), PyOp(Remap)::getstate, METH_NOARGS, "Remap getstate"},
  13928. {const_cast<char*>("__setstate__"), PyOp(Remap)::setstate, METH_VARARGS, "Remap setstate"},
  13929. {NULL} /* Sentinel */
  13930. };
  13931. void _init_py_Remap(py::module m) {
  13932. using py_op = PyOp(Remap);
  13933. auto& py_type = PyOpType(Remap);
  13934. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13935. py_type.tp_name = "megengine.core._imperative_rt.ops.Remap";
  13936. py_type.tp_basicsize = sizeof(PyOp(Remap));
  13937. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13938. py_type.tp_doc = "Remap";
  13939. py_type.tp_base = &PyOpType(OpDef);
  13940. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13941. py_type.tp_new = py_new_generic<py_op>;
  13942. py_type.tp_init = py_op::py_init;
  13943. py_type.tp_methods = py_op::tp_methods;
  13944. py_type.tp_getset = py_op::py_getsetters;
  13945. mgb_assert(PyType_Ready(&py_type) >= 0);
  13946. _init_py_Remap_InterpolationMode(py_type);
  13947. _init_py_Remap_BorderMode(py_type);
  13948. _init_py_Remap_Format(py_type);
  13949. PyType_Modified(&py_type);
  13950. m.add_object("Remap", reinterpret_cast<PyObject*>(&py_type));
  13951. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Remap::typeinfo(), &py_type).second);
  13952. }
  13953. PyOpDefBegin(RemoteRecv) // {
  13954. static PyGetSetDef py_getsetters[];
  13955. static PyMethodDef tp_methods[];
  13956. static PyObject* getstate(PyObject* self, PyObject*) {
  13957. auto& opdef = reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst();
  13958. static_cast<void>(opdef);
  13959. std::unordered_map<std::string, py::object> state {
  13960. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  13961. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  13962. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  13963. {"rank_from", serialization<decltype(opdef.rank_from)>::dump(opdef.rank_from)},
  13964. {"cn", serialization<decltype(opdef.cn)>::dump(opdef.cn)},
  13965. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)},
  13966. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  13967. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)}
  13968. };
  13969. return py::cast(state).release().ptr();
  13970. }
  13971. static PyObject* setstate(PyObject* self, PyObject* args) {
  13972. PyObject* dict = PyTuple_GetItem(args, 0);
  13973. if (!dict) return NULL;
  13974. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13975. auto& opdef = reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst();
  13976. static_cast<void>(opdef);
  13977. {
  13978. auto&& iter = state.find("key");
  13979. if (iter != state.end()) {
  13980. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  13981. }
  13982. }
  13983. {
  13984. auto&& iter = state.find("addr");
  13985. if (iter != state.end()) {
  13986. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  13987. }
  13988. }
  13989. {
  13990. auto&& iter = state.find("port");
  13991. if (iter != state.end()) {
  13992. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  13993. }
  13994. }
  13995. {
  13996. auto&& iter = state.find("rank_from");
  13997. if (iter != state.end()) {
  13998. opdef.rank_from = serialization<decltype(opdef.rank_from)>::load(iter->second);
  13999. }
  14000. }
  14001. {
  14002. auto&& iter = state.find("cn");
  14003. if (iter != state.end()) {
  14004. opdef.cn = serialization<decltype(opdef.cn)>::load(iter->second);
  14005. }
  14006. }
  14007. {
  14008. auto&& iter = state.find("shape");
  14009. if (iter != state.end()) {
  14010. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  14011. }
  14012. }
  14013. {
  14014. auto&& iter = state.find("dtype");
  14015. if (iter != state.end()) {
  14016. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  14017. }
  14018. }
  14019. {
  14020. auto&& iter = state.find("backend");
  14021. if (iter != state.end()) {
  14022. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  14023. }
  14024. }
  14025. Py_RETURN_NONE;
  14026. }
  14027. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14028. // };
  14029. PyOpDefEnd(RemoteRecv)
  14030. int PyOp(RemoteRecv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14031. static const char* kwlist[] = {"key", "addr", "port", "rank_from", "cn", "shape", "dtype", "backend", "scope", NULL};
  14032. PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_from = NULL, *cn = NULL, *shape = NULL, *dtype = NULL, *backend = NULL, *scope = NULL;
  14033. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &key, &addr, &port, &rank_from, &cn, &shape, &dtype, &backend, &scope))
  14034. return -1;
  14035. if (key) {
  14036. try {
  14037. // TODO: remove this guard which is used for pybind11 implicit conversion
  14038. py::detail::loader_life_support guard{};
  14039. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().key =
  14040. py::cast<decltype(RemoteRecv::key)>(py::handle(key));
  14041. } CATCH_ALL(-1)
  14042. }
  14043. if (addr) {
  14044. try {
  14045. // TODO: remove this guard which is used for pybind11 implicit conversion
  14046. py::detail::loader_life_support guard{};
  14047. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().addr =
  14048. py::cast<decltype(RemoteRecv::addr)>(py::handle(addr));
  14049. } CATCH_ALL(-1)
  14050. }
  14051. if (port) {
  14052. try {
  14053. // TODO: remove this guard which is used for pybind11 implicit conversion
  14054. py::detail::loader_life_support guard{};
  14055. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().port =
  14056. py::cast<decltype(RemoteRecv::port)>(py::handle(port));
  14057. } CATCH_ALL(-1)
  14058. }
  14059. if (rank_from) {
  14060. try {
  14061. // TODO: remove this guard which is used for pybind11 implicit conversion
  14062. py::detail::loader_life_support guard{};
  14063. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().rank_from =
  14064. py::cast<decltype(RemoteRecv::rank_from)>(py::handle(rank_from));
  14065. } CATCH_ALL(-1)
  14066. }
  14067. if (cn) {
  14068. try {
  14069. // TODO: remove this guard which is used for pybind11 implicit conversion
  14070. py::detail::loader_life_support guard{};
  14071. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().cn =
  14072. py::cast<decltype(RemoteRecv::cn)>(py::handle(cn));
  14073. } CATCH_ALL(-1)
  14074. }
  14075. if (shape) {
  14076. try {
  14077. // TODO: remove this guard which is used for pybind11 implicit conversion
  14078. py::detail::loader_life_support guard{};
  14079. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().shape =
  14080. py::cast<decltype(RemoteRecv::shape)>(py::handle(shape));
  14081. } CATCH_ALL(-1)
  14082. }
  14083. if (dtype) {
  14084. try {
  14085. // TODO: remove this guard which is used for pybind11 implicit conversion
  14086. py::detail::loader_life_support guard{};
  14087. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().dtype =
  14088. py::cast<decltype(RemoteRecv::dtype)>(py::handle(dtype));
  14089. } CATCH_ALL(-1)
  14090. }
  14091. if (backend) {
  14092. try {
  14093. // TODO: remove this guard which is used for pybind11 implicit conversion
  14094. py::detail::loader_life_support guard{};
  14095. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().backend =
  14096. py::cast<decltype(RemoteRecv::backend)>(py::handle(backend));
  14097. } CATCH_ALL(-1)
  14098. }
  14099. if (scope) {
  14100. try {
  14101. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14102. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14103. } CATCH_ALL(-1)
  14104. }
  14105. return 0;
  14106. }
  14107. PyGetSetDef PyOp(RemoteRecv)::py_getsetters[] = {
  14108. {const_cast<char*>("key"), py_get_generic(RemoteRecv, key), py_set_generic(RemoteRecv, key), const_cast<char*>("key"), NULL},
  14109. {const_cast<char*>("addr"), py_get_generic(RemoteRecv, addr), py_set_generic(RemoteRecv, addr), const_cast<char*>("addr"), NULL},
  14110. {const_cast<char*>("port"), py_get_generic(RemoteRecv, port), py_set_generic(RemoteRecv, port), const_cast<char*>("port"), NULL},
  14111. {const_cast<char*>("rank_from"), py_get_generic(RemoteRecv, rank_from), py_set_generic(RemoteRecv, rank_from), const_cast<char*>("rank_from"), NULL},
  14112. {const_cast<char*>("cn"), py_get_generic(RemoteRecv, cn), py_set_generic(RemoteRecv, cn), const_cast<char*>("cn"), NULL},
  14113. {const_cast<char*>("shape"), py_get_generic(RemoteRecv, shape), py_set_generic(RemoteRecv, shape), const_cast<char*>("shape"), NULL},
  14114. {const_cast<char*>("dtype"), py_get_generic(RemoteRecv, dtype), py_set_generic(RemoteRecv, dtype), const_cast<char*>("dtype"), NULL},
  14115. {const_cast<char*>("backend"), py_get_generic(RemoteRecv, backend), py_set_generic(RemoteRecv, backend), const_cast<char*>("backend"), NULL},
  14116. {NULL} /* Sentinel */
  14117. };
  14118. PyMethodDef PyOp(RemoteRecv)::tp_methods[] = {
  14119. {const_cast<char*>("__getstate__"), PyOp(RemoteRecv)::getstate, METH_NOARGS, "RemoteRecv getstate"},
  14120. {const_cast<char*>("__setstate__"), PyOp(RemoteRecv)::setstate, METH_VARARGS, "RemoteRecv setstate"},
  14121. {NULL} /* Sentinel */
  14122. };
  14123. void _init_py_RemoteRecv(py::module m) {
  14124. using py_op = PyOp(RemoteRecv);
  14125. auto& py_type = PyOpType(RemoteRecv);
  14126. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14127. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteRecv";
  14128. py_type.tp_basicsize = sizeof(PyOp(RemoteRecv));
  14129. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14130. py_type.tp_doc = "RemoteRecv";
  14131. py_type.tp_base = &PyOpType(OpDef);
  14132. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14133. py_type.tp_new = py_new_generic<py_op>;
  14134. py_type.tp_init = py_op::py_init;
  14135. py_type.tp_methods = py_op::tp_methods;
  14136. py_type.tp_getset = py_op::py_getsetters;
  14137. mgb_assert(PyType_Ready(&py_type) >= 0);
  14138. PyType_Modified(&py_type);
  14139. m.add_object("RemoteRecv", reinterpret_cast<PyObject*>(&py_type));
  14140. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteRecv::typeinfo(), &py_type).second);
  14141. }
  14142. PyOpDefBegin(RemoteSend) // {
  14143. static PyGetSetDef py_getsetters[];
  14144. static PyMethodDef tp_methods[];
  14145. static PyObject* getstate(PyObject* self, PyObject*) {
  14146. auto& opdef = reinterpret_cast<PyOp(RemoteSend)*>(self)->inst();
  14147. static_cast<void>(opdef);
  14148. std::unordered_map<std::string, py::object> state {
  14149. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  14150. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  14151. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  14152. {"rank_to", serialization<decltype(opdef.rank_to)>::dump(opdef.rank_to)},
  14153. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)}
  14154. };
  14155. return py::cast(state).release().ptr();
  14156. }
  14157. static PyObject* setstate(PyObject* self, PyObject* args) {
  14158. PyObject* dict = PyTuple_GetItem(args, 0);
  14159. if (!dict) return NULL;
  14160. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14161. auto& opdef = reinterpret_cast<PyOp(RemoteSend)*>(self)->inst();
  14162. static_cast<void>(opdef);
  14163. {
  14164. auto&& iter = state.find("key");
  14165. if (iter != state.end()) {
  14166. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  14167. }
  14168. }
  14169. {
  14170. auto&& iter = state.find("addr");
  14171. if (iter != state.end()) {
  14172. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  14173. }
  14174. }
  14175. {
  14176. auto&& iter = state.find("port");
  14177. if (iter != state.end()) {
  14178. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  14179. }
  14180. }
  14181. {
  14182. auto&& iter = state.find("rank_to");
  14183. if (iter != state.end()) {
  14184. opdef.rank_to = serialization<decltype(opdef.rank_to)>::load(iter->second);
  14185. }
  14186. }
  14187. {
  14188. auto&& iter = state.find("backend");
  14189. if (iter != state.end()) {
  14190. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  14191. }
  14192. }
  14193. Py_RETURN_NONE;
  14194. }
  14195. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14196. // };
  14197. PyOpDefEnd(RemoteSend)
  14198. int PyOp(RemoteSend)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14199. static const char* kwlist[] = {"key", "addr", "port", "rank_to", "backend", "scope", NULL};
  14200. PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_to = NULL, *backend = NULL, *scope = NULL;
  14201. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &key, &addr, &port, &rank_to, &backend, &scope))
  14202. return -1;
  14203. if (key) {
  14204. try {
  14205. // TODO: remove this guard which is used for pybind11 implicit conversion
  14206. py::detail::loader_life_support guard{};
  14207. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().key =
  14208. py::cast<decltype(RemoteSend::key)>(py::handle(key));
  14209. } CATCH_ALL(-1)
  14210. }
  14211. if (addr) {
  14212. try {
  14213. // TODO: remove this guard which is used for pybind11 implicit conversion
  14214. py::detail::loader_life_support guard{};
  14215. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().addr =
  14216. py::cast<decltype(RemoteSend::addr)>(py::handle(addr));
  14217. } CATCH_ALL(-1)
  14218. }
  14219. if (port) {
  14220. try {
  14221. // TODO: remove this guard which is used for pybind11 implicit conversion
  14222. py::detail::loader_life_support guard{};
  14223. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().port =
  14224. py::cast<decltype(RemoteSend::port)>(py::handle(port));
  14225. } CATCH_ALL(-1)
  14226. }
  14227. if (rank_to) {
  14228. try {
  14229. // TODO: remove this guard which is used for pybind11 implicit conversion
  14230. py::detail::loader_life_support guard{};
  14231. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().rank_to =
  14232. py::cast<decltype(RemoteSend::rank_to)>(py::handle(rank_to));
  14233. } CATCH_ALL(-1)
  14234. }
  14235. if (backend) {
  14236. try {
  14237. // TODO: remove this guard which is used for pybind11 implicit conversion
  14238. py::detail::loader_life_support guard{};
  14239. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().backend =
  14240. py::cast<decltype(RemoteSend::backend)>(py::handle(backend));
  14241. } CATCH_ALL(-1)
  14242. }
  14243. if (scope) {
  14244. try {
  14245. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14246. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14247. } CATCH_ALL(-1)
  14248. }
  14249. return 0;
  14250. }
  14251. PyGetSetDef PyOp(RemoteSend)::py_getsetters[] = {
  14252. {const_cast<char*>("key"), py_get_generic(RemoteSend, key), py_set_generic(RemoteSend, key), const_cast<char*>("key"), NULL},
  14253. {const_cast<char*>("addr"), py_get_generic(RemoteSend, addr), py_set_generic(RemoteSend, addr), const_cast<char*>("addr"), NULL},
  14254. {const_cast<char*>("port"), py_get_generic(RemoteSend, port), py_set_generic(RemoteSend, port), const_cast<char*>("port"), NULL},
  14255. {const_cast<char*>("rank_to"), py_get_generic(RemoteSend, rank_to), py_set_generic(RemoteSend, rank_to), const_cast<char*>("rank_to"), NULL},
  14256. {const_cast<char*>("backend"), py_get_generic(RemoteSend, backend), py_set_generic(RemoteSend, backend), const_cast<char*>("backend"), NULL},
  14257. {NULL} /* Sentinel */
  14258. };
  14259. PyMethodDef PyOp(RemoteSend)::tp_methods[] = {
  14260. {const_cast<char*>("__getstate__"), PyOp(RemoteSend)::getstate, METH_NOARGS, "RemoteSend getstate"},
  14261. {const_cast<char*>("__setstate__"), PyOp(RemoteSend)::setstate, METH_VARARGS, "RemoteSend setstate"},
  14262. {NULL} /* Sentinel */
  14263. };
  14264. void _init_py_RemoteSend(py::module m) {
  14265. using py_op = PyOp(RemoteSend);
  14266. auto& py_type = PyOpType(RemoteSend);
  14267. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14268. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteSend";
  14269. py_type.tp_basicsize = sizeof(PyOp(RemoteSend));
  14270. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14271. py_type.tp_doc = "RemoteSend";
  14272. py_type.tp_base = &PyOpType(OpDef);
  14273. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14274. py_type.tp_new = py_new_generic<py_op>;
  14275. py_type.tp_init = py_op::py_init;
  14276. py_type.tp_methods = py_op::tp_methods;
  14277. py_type.tp_getset = py_op::py_getsetters;
  14278. mgb_assert(PyType_Ready(&py_type) >= 0);
  14279. PyType_Modified(&py_type);
  14280. m.add_object("RemoteSend", reinterpret_cast<PyObject*>(&py_type));
  14281. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteSend::typeinfo(), &py_type).second);
  14282. }
  14283. PyOpDefBegin(RemoveAxis) // {
  14284. static PyGetSetDef py_getsetters[];
  14285. static PyMethodDef tp_methods[];
  14286. static PyObject* getstate(PyObject* self, PyObject*) {
  14287. auto& opdef = reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst();
  14288. static_cast<void>(opdef);
  14289. std::unordered_map<std::string, py::object> state {
  14290. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  14291. };
  14292. return py::cast(state).release().ptr();
  14293. }
  14294. static PyObject* setstate(PyObject* self, PyObject* args) {
  14295. PyObject* dict = PyTuple_GetItem(args, 0);
  14296. if (!dict) return NULL;
  14297. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14298. auto& opdef = reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst();
  14299. static_cast<void>(opdef);
  14300. {
  14301. auto&& iter = state.find("axis");
  14302. if (iter != state.end()) {
  14303. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  14304. }
  14305. }
  14306. Py_RETURN_NONE;
  14307. }
  14308. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14309. // };
  14310. PyOpDefEnd(RemoveAxis)
  14311. int PyOp(RemoveAxis)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14312. static const char* kwlist[] = {"axis", "scope", NULL};
  14313. PyObject *axis = NULL, *scope = NULL;
  14314. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  14315. return -1;
  14316. if (axis) {
  14317. try {
  14318. // TODO: remove this guard which is used for pybind11 implicit conversion
  14319. py::detail::loader_life_support guard{};
  14320. reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst().axis =
  14321. py::cast<decltype(RemoveAxis::axis)>(py::handle(axis));
  14322. } CATCH_ALL(-1)
  14323. }
  14324. if (scope) {
  14325. try {
  14326. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14327. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14328. } CATCH_ALL(-1)
  14329. }
  14330. return 0;
  14331. }
  14332. PyGetSetDef PyOp(RemoveAxis)::py_getsetters[] = {
  14333. {const_cast<char*>("axis"), py_get_generic(RemoveAxis, axis), py_set_generic(RemoveAxis, axis), const_cast<char*>("axis"), NULL},
  14334. {NULL} /* Sentinel */
  14335. };
  14336. PyMethodDef PyOp(RemoveAxis)::tp_methods[] = {
  14337. {const_cast<char*>("__getstate__"), PyOp(RemoveAxis)::getstate, METH_NOARGS, "RemoveAxis getstate"},
  14338. {const_cast<char*>("__setstate__"), PyOp(RemoveAxis)::setstate, METH_VARARGS, "RemoveAxis setstate"},
  14339. {NULL} /* Sentinel */
  14340. };
  14341. void _init_py_RemoveAxis(py::module m) {
  14342. using py_op = PyOp(RemoveAxis);
  14343. auto& py_type = PyOpType(RemoveAxis);
  14344. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14345. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoveAxis";
  14346. py_type.tp_basicsize = sizeof(PyOp(RemoveAxis));
  14347. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14348. py_type.tp_doc = "RemoveAxis";
  14349. py_type.tp_base = &PyOpType(OpDef);
  14350. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14351. py_type.tp_new = py_new_generic<py_op>;
  14352. py_type.tp_init = py_op::py_init;
  14353. py_type.tp_methods = py_op::tp_methods;
  14354. py_type.tp_getset = py_op::py_getsetters;
  14355. mgb_assert(PyType_Ready(&py_type) >= 0);
  14356. PyType_Modified(&py_type);
  14357. m.add_object("RemoveAxis", reinterpret_cast<PyObject*>(&py_type));
  14358. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoveAxis::typeinfo(), &py_type).second);
  14359. }
  14360. PyOpDefBegin(Reshape) // {
  14361. static PyGetSetDef py_getsetters[];
  14362. static PyMethodDef tp_methods[];
  14363. static PyObject* getstate(PyObject* self, PyObject*) {
  14364. auto& opdef = reinterpret_cast<PyOp(Reshape)*>(self)->inst();
  14365. static_cast<void>(opdef);
  14366. std::unordered_map<std::string, py::object> state {
  14367. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  14368. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)}
  14369. };
  14370. return py::cast(state).release().ptr();
  14371. }
  14372. static PyObject* setstate(PyObject* self, PyObject* args) {
  14373. PyObject* dict = PyTuple_GetItem(args, 0);
  14374. if (!dict) return NULL;
  14375. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14376. auto& opdef = reinterpret_cast<PyOp(Reshape)*>(self)->inst();
  14377. static_cast<void>(opdef);
  14378. {
  14379. auto&& iter = state.find("axis");
  14380. if (iter != state.end()) {
  14381. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  14382. }
  14383. }
  14384. {
  14385. auto&& iter = state.find("shape");
  14386. if (iter != state.end()) {
  14387. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  14388. }
  14389. }
  14390. Py_RETURN_NONE;
  14391. }
  14392. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14393. // };
  14394. PyOpDefEnd(Reshape)
  14395. int PyOp(Reshape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14396. static const char* kwlist[] = {"axis", "shape", "scope", NULL};
  14397. PyObject *axis = NULL, *shape = NULL, *scope = NULL;
  14398. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &shape, &scope))
  14399. return -1;
  14400. if (axis) {
  14401. try {
  14402. // TODO: remove this guard which is used for pybind11 implicit conversion
  14403. py::detail::loader_life_support guard{};
  14404. reinterpret_cast<PyOp(Reshape)*>(self)->inst().axis =
  14405. py::cast<decltype(Reshape::axis)>(py::handle(axis));
  14406. } CATCH_ALL(-1)
  14407. }
  14408. if (shape) {
  14409. try {
  14410. // TODO: remove this guard which is used for pybind11 implicit conversion
  14411. py::detail::loader_life_support guard{};
  14412. reinterpret_cast<PyOp(Reshape)*>(self)->inst().shape =
  14413. py::cast<decltype(Reshape::shape)>(py::handle(shape));
  14414. } CATCH_ALL(-1)
  14415. }
  14416. if (scope) {
  14417. try {
  14418. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14419. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14420. } CATCH_ALL(-1)
  14421. }
  14422. return 0;
  14423. }
  14424. PyGetSetDef PyOp(Reshape)::py_getsetters[] = {
  14425. {const_cast<char*>("axis"), py_get_generic(Reshape, axis), py_set_generic(Reshape, axis), const_cast<char*>("axis"), NULL},
  14426. {const_cast<char*>("shape"), py_get_generic(Reshape, shape), py_set_generic(Reshape, shape), const_cast<char*>("shape"), NULL},
  14427. {NULL} /* Sentinel */
  14428. };
  14429. PyMethodDef PyOp(Reshape)::tp_methods[] = {
  14430. {const_cast<char*>("__getstate__"), PyOp(Reshape)::getstate, METH_NOARGS, "Reshape getstate"},
  14431. {const_cast<char*>("__setstate__"), PyOp(Reshape)::setstate, METH_VARARGS, "Reshape setstate"},
  14432. {NULL} /* Sentinel */
  14433. };
  14434. void _init_py_Reshape(py::module m) {
  14435. using py_op = PyOp(Reshape);
  14436. auto& py_type = PyOpType(Reshape);
  14437. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14438. py_type.tp_name = "megengine.core._imperative_rt.ops.Reshape";
  14439. py_type.tp_basicsize = sizeof(PyOp(Reshape));
  14440. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14441. py_type.tp_doc = "Reshape";
  14442. py_type.tp_base = &PyOpType(OpDef);
  14443. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14444. py_type.tp_new = py_new_generic<py_op>;
  14445. py_type.tp_init = py_op::py_init;
  14446. py_type.tp_methods = py_op::tp_methods;
  14447. py_type.tp_getset = py_op::py_getsetters;
  14448. mgb_assert(PyType_Ready(&py_type) >= 0);
  14449. PyType_Modified(&py_type);
  14450. m.add_object("Reshape", reinterpret_cast<PyObject*>(&py_type));
  14451. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reshape::typeinfo(), &py_type).second);
  14452. }
  14453. void _init_py_Resize_InterpolationMode(PyTypeObject& py_type) {
  14454. auto& e_type = EnumWrapper<Resize::InterpolationMode>::type;
  14455. Py_INCREF(e_type);
  14456. mgb_assert(PyDict_SetItemString(
  14457. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14458. }
  14459. void _init_py_Resize_Format(PyTypeObject& py_type) {
  14460. auto& e_type = EnumWrapper<Resize::Format>::type;
  14461. Py_INCREF(e_type);
  14462. mgb_assert(PyDict_SetItemString(
  14463. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14464. }
  14465. PyOpDefBegin(Resize) // {
  14466. static PyGetSetDef py_getsetters[];
  14467. static PyMethodDef tp_methods[];
  14468. static PyObject* getstate(PyObject* self, PyObject*) {
  14469. auto& opdef = reinterpret_cast<PyOp(Resize)*>(self)->inst();
  14470. static_cast<void>(opdef);
  14471. std::unordered_map<std::string, py::object> state {
  14472. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  14473. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  14474. };
  14475. return py::cast(state).release().ptr();
  14476. }
  14477. static PyObject* setstate(PyObject* self, PyObject* args) {
  14478. PyObject* dict = PyTuple_GetItem(args, 0);
  14479. if (!dict) return NULL;
  14480. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14481. auto& opdef = reinterpret_cast<PyOp(Resize)*>(self)->inst();
  14482. static_cast<void>(opdef);
  14483. {
  14484. auto&& iter = state.find("imode");
  14485. if (iter != state.end()) {
  14486. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  14487. }
  14488. }
  14489. {
  14490. auto&& iter = state.find("format");
  14491. if (iter != state.end()) {
  14492. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  14493. }
  14494. }
  14495. Py_RETURN_NONE;
  14496. }
  14497. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14498. // };
  14499. PyOpDefEnd(Resize)
  14500. int PyOp(Resize)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14501. static const char* kwlist[] = {"imode", "format", "scope", NULL};
  14502. PyObject *imode = NULL, *format = NULL, *scope = NULL;
  14503. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &imode, &format, &scope))
  14504. return -1;
  14505. if (imode) {
  14506. try {
  14507. // TODO: remove this guard which is used for pybind11 implicit conversion
  14508. py::detail::loader_life_support guard{};
  14509. reinterpret_cast<PyOp(Resize)*>(self)->inst().imode =
  14510. py::cast<decltype(Resize::imode)>(py::handle(imode));
  14511. } CATCH_ALL(-1)
  14512. }
  14513. if (format) {
  14514. try {
  14515. // TODO: remove this guard which is used for pybind11 implicit conversion
  14516. py::detail::loader_life_support guard{};
  14517. reinterpret_cast<PyOp(Resize)*>(self)->inst().format =
  14518. py::cast<decltype(Resize::format)>(py::handle(format));
  14519. } CATCH_ALL(-1)
  14520. }
  14521. if (scope) {
  14522. try {
  14523. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14524. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14525. } CATCH_ALL(-1)
  14526. }
  14527. return 0;
  14528. }
  14529. PyGetSetDef PyOp(Resize)::py_getsetters[] = {
  14530. {const_cast<char*>("imode"), py_get_generic(Resize, imode), py_set_generic(Resize, imode), const_cast<char*>("imode"), NULL},
  14531. {const_cast<char*>("format"), py_get_generic(Resize, format), py_set_generic(Resize, format), const_cast<char*>("format"), NULL},
  14532. {NULL} /* Sentinel */
  14533. };
  14534. PyMethodDef PyOp(Resize)::tp_methods[] = {
  14535. {const_cast<char*>("__getstate__"), PyOp(Resize)::getstate, METH_NOARGS, "Resize getstate"},
  14536. {const_cast<char*>("__setstate__"), PyOp(Resize)::setstate, METH_VARARGS, "Resize setstate"},
  14537. {NULL} /* Sentinel */
  14538. };
  14539. void _init_py_Resize(py::module m) {
  14540. using py_op = PyOp(Resize);
  14541. auto& py_type = PyOpType(Resize);
  14542. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14543. py_type.tp_name = "megengine.core._imperative_rt.ops.Resize";
  14544. py_type.tp_basicsize = sizeof(PyOp(Resize));
  14545. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14546. py_type.tp_doc = "Resize";
  14547. py_type.tp_base = &PyOpType(OpDef);
  14548. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14549. py_type.tp_new = py_new_generic<py_op>;
  14550. py_type.tp_init = py_op::py_init;
  14551. py_type.tp_methods = py_op::tp_methods;
  14552. py_type.tp_getset = py_op::py_getsetters;
  14553. mgb_assert(PyType_Ready(&py_type) >= 0);
  14554. _init_py_Resize_InterpolationMode(py_type);
  14555. _init_py_Resize_Format(py_type);
  14556. PyType_Modified(&py_type);
  14557. m.add_object("Resize", reinterpret_cast<PyObject*>(&py_type));
  14558. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Resize::typeinfo(), &py_type).second);
  14559. }
  14560. PyOpDefBegin(SVD) // {
  14561. static PyGetSetDef py_getsetters[];
  14562. static PyMethodDef tp_methods[];
  14563. static PyObject* getstate(PyObject* self, PyObject*) {
  14564. auto& opdef = reinterpret_cast<PyOp(SVD)*>(self)->inst();
  14565. static_cast<void>(opdef);
  14566. std::unordered_map<std::string, py::object> state {
  14567. {"full_matrices", serialization<decltype(opdef.full_matrices)>::dump(opdef.full_matrices)},
  14568. {"compute_uv", serialization<decltype(opdef.compute_uv)>::dump(opdef.compute_uv)}
  14569. };
  14570. return py::cast(state).release().ptr();
  14571. }
  14572. static PyObject* setstate(PyObject* self, PyObject* args) {
  14573. PyObject* dict = PyTuple_GetItem(args, 0);
  14574. if (!dict) return NULL;
  14575. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14576. auto& opdef = reinterpret_cast<PyOp(SVD)*>(self)->inst();
  14577. static_cast<void>(opdef);
  14578. {
  14579. auto&& iter = state.find("full_matrices");
  14580. if (iter != state.end()) {
  14581. opdef.full_matrices = serialization<decltype(opdef.full_matrices)>::load(iter->second);
  14582. }
  14583. }
  14584. {
  14585. auto&& iter = state.find("compute_uv");
  14586. if (iter != state.end()) {
  14587. opdef.compute_uv = serialization<decltype(opdef.compute_uv)>::load(iter->second);
  14588. }
  14589. }
  14590. Py_RETURN_NONE;
  14591. }
  14592. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14593. // };
  14594. PyOpDefEnd(SVD)
  14595. int PyOp(SVD)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14596. static const char* kwlist[] = {"full_matrices", "compute_uv", "scope", NULL};
  14597. PyObject *full_matrices = NULL, *compute_uv = NULL, *scope = NULL;
  14598. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &full_matrices, &compute_uv, &scope))
  14599. return -1;
  14600. if (full_matrices) {
  14601. try {
  14602. // TODO: remove this guard which is used for pybind11 implicit conversion
  14603. py::detail::loader_life_support guard{};
  14604. reinterpret_cast<PyOp(SVD)*>(self)->inst().full_matrices =
  14605. py::cast<decltype(SVD::full_matrices)>(py::handle(full_matrices));
  14606. } CATCH_ALL(-1)
  14607. }
  14608. if (compute_uv) {
  14609. try {
  14610. // TODO: remove this guard which is used for pybind11 implicit conversion
  14611. py::detail::loader_life_support guard{};
  14612. reinterpret_cast<PyOp(SVD)*>(self)->inst().compute_uv =
  14613. py::cast<decltype(SVD::compute_uv)>(py::handle(compute_uv));
  14614. } CATCH_ALL(-1)
  14615. }
  14616. if (scope) {
  14617. try {
  14618. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14619. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14620. } CATCH_ALL(-1)
  14621. }
  14622. return 0;
  14623. }
  14624. PyGetSetDef PyOp(SVD)::py_getsetters[] = {
  14625. {const_cast<char*>("full_matrices"), py_get_generic(SVD, full_matrices), py_set_generic(SVD, full_matrices), const_cast<char*>("full_matrices"), NULL},
  14626. {const_cast<char*>("compute_uv"), py_get_generic(SVD, compute_uv), py_set_generic(SVD, compute_uv), const_cast<char*>("compute_uv"), NULL},
  14627. {NULL} /* Sentinel */
  14628. };
  14629. PyMethodDef PyOp(SVD)::tp_methods[] = {
  14630. {const_cast<char*>("__getstate__"), PyOp(SVD)::getstate, METH_NOARGS, "SVD getstate"},
  14631. {const_cast<char*>("__setstate__"), PyOp(SVD)::setstate, METH_VARARGS, "SVD setstate"},
  14632. {NULL} /* Sentinel */
  14633. };
  14634. void _init_py_SVD(py::module m) {
  14635. using py_op = PyOp(SVD);
  14636. auto& py_type = PyOpType(SVD);
  14637. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14638. py_type.tp_name = "megengine.core._imperative_rt.ops.SVD";
  14639. py_type.tp_basicsize = sizeof(PyOp(SVD));
  14640. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14641. py_type.tp_doc = "SVD";
  14642. py_type.tp_base = &PyOpType(OpDef);
  14643. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14644. py_type.tp_new = py_new_generic<py_op>;
  14645. py_type.tp_init = py_op::py_init;
  14646. py_type.tp_methods = py_op::tp_methods;
  14647. py_type.tp_getset = py_op::py_getsetters;
  14648. mgb_assert(PyType_Ready(&py_type) >= 0);
  14649. PyType_Modified(&py_type);
  14650. m.add_object("SVD", reinterpret_cast<PyObject*>(&py_type));
  14651. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SVD::typeinfo(), &py_type).second);
  14652. }
  14653. PyOpDefBegin(SetMeshIndexing) // {
  14654. static PyGetSetDef py_getsetters[];
  14655. static PyMethodDef tp_methods[];
  14656. static PyObject* getstate(PyObject* self, PyObject*) {
  14657. auto& opdef = reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst();
  14658. static_cast<void>(opdef);
  14659. std::unordered_map<std::string, py::object> state {
  14660. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  14661. };
  14662. return py::cast(state).release().ptr();
  14663. }
  14664. static PyObject* setstate(PyObject* self, PyObject* args) {
  14665. PyObject* dict = PyTuple_GetItem(args, 0);
  14666. if (!dict) return NULL;
  14667. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14668. auto& opdef = reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst();
  14669. static_cast<void>(opdef);
  14670. {
  14671. auto&& iter = state.find("items");
  14672. if (iter != state.end()) {
  14673. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  14674. }
  14675. }
  14676. Py_RETURN_NONE;
  14677. }
  14678. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14679. // };
  14680. PyOpDefEnd(SetMeshIndexing)
  14681. int PyOp(SetMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14682. static const char* kwlist[] = {"items", "scope", NULL};
  14683. PyObject *items = NULL, *scope = NULL;
  14684. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  14685. return -1;
  14686. if (items) {
  14687. try {
  14688. // TODO: remove this guard which is used for pybind11 implicit conversion
  14689. py::detail::loader_life_support guard{};
  14690. reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst().items =
  14691. py::cast<decltype(SetMeshIndexing::items)>(py::handle(items));
  14692. } CATCH_ALL(-1)
  14693. }
  14694. if (scope) {
  14695. try {
  14696. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14697. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14698. } CATCH_ALL(-1)
  14699. }
  14700. return 0;
  14701. }
  14702. PyGetSetDef PyOp(SetMeshIndexing)::py_getsetters[] = {
  14703. {const_cast<char*>("items"), py_get_generic(SetMeshIndexing, items), py_set_generic(SetMeshIndexing, items), const_cast<char*>("items"), NULL},
  14704. {NULL} /* Sentinel */
  14705. };
  14706. PyMethodDef PyOp(SetMeshIndexing)::tp_methods[] = {
  14707. {const_cast<char*>("__getstate__"), PyOp(SetMeshIndexing)::getstate, METH_NOARGS, "SetMeshIndexing getstate"},
  14708. {const_cast<char*>("__setstate__"), PyOp(SetMeshIndexing)::setstate, METH_VARARGS, "SetMeshIndexing setstate"},
  14709. {NULL} /* Sentinel */
  14710. };
  14711. void _init_py_SetMeshIndexing(py::module m) {
  14712. using py_op = PyOp(SetMeshIndexing);
  14713. auto& py_type = PyOpType(SetMeshIndexing);
  14714. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14715. py_type.tp_name = "megengine.core._imperative_rt.ops.SetMeshIndexing";
  14716. py_type.tp_basicsize = sizeof(PyOp(SetMeshIndexing));
  14717. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14718. py_type.tp_doc = "SetMeshIndexing";
  14719. py_type.tp_base = &PyOpType(OpDef);
  14720. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14721. py_type.tp_new = py_new_generic<py_op>;
  14722. py_type.tp_init = py_op::py_init;
  14723. py_type.tp_methods = py_op::tp_methods;
  14724. py_type.tp_getset = py_op::py_getsetters;
  14725. mgb_assert(PyType_Ready(&py_type) >= 0);
  14726. PyType_Modified(&py_type);
  14727. m.add_object("SetMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  14728. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetMeshIndexing::typeinfo(), &py_type).second);
  14729. }
  14730. PyOpDefBegin(SetSubtensor) // {
  14731. static PyGetSetDef py_getsetters[];
  14732. static PyMethodDef tp_methods[];
  14733. static PyObject* getstate(PyObject* self, PyObject*) {
  14734. auto& opdef = reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst();
  14735. static_cast<void>(opdef);
  14736. std::unordered_map<std::string, py::object> state {
  14737. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  14738. };
  14739. return py::cast(state).release().ptr();
  14740. }
  14741. static PyObject* setstate(PyObject* self, PyObject* args) {
  14742. PyObject* dict = PyTuple_GetItem(args, 0);
  14743. if (!dict) return NULL;
  14744. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14745. auto& opdef = reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst();
  14746. static_cast<void>(opdef);
  14747. {
  14748. auto&& iter = state.find("items");
  14749. if (iter != state.end()) {
  14750. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  14751. }
  14752. }
  14753. Py_RETURN_NONE;
  14754. }
  14755. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14756. // };
  14757. PyOpDefEnd(SetSubtensor)
  14758. int PyOp(SetSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14759. static const char* kwlist[] = {"items", "scope", NULL};
  14760. PyObject *items = NULL, *scope = NULL;
  14761. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  14762. return -1;
  14763. if (items) {
  14764. try {
  14765. // TODO: remove this guard which is used for pybind11 implicit conversion
  14766. py::detail::loader_life_support guard{};
  14767. reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst().items =
  14768. py::cast<decltype(SetSubtensor::items)>(py::handle(items));
  14769. } CATCH_ALL(-1)
  14770. }
  14771. if (scope) {
  14772. try {
  14773. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14774. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14775. } CATCH_ALL(-1)
  14776. }
  14777. return 0;
  14778. }
  14779. PyGetSetDef PyOp(SetSubtensor)::py_getsetters[] = {
  14780. {const_cast<char*>("items"), py_get_generic(SetSubtensor, items), py_set_generic(SetSubtensor, items), const_cast<char*>("items"), NULL},
  14781. {NULL} /* Sentinel */
  14782. };
  14783. PyMethodDef PyOp(SetSubtensor)::tp_methods[] = {
  14784. {const_cast<char*>("__getstate__"), PyOp(SetSubtensor)::getstate, METH_NOARGS, "SetSubtensor getstate"},
  14785. {const_cast<char*>("__setstate__"), PyOp(SetSubtensor)::setstate, METH_VARARGS, "SetSubtensor setstate"},
  14786. {NULL} /* Sentinel */
  14787. };
  14788. void _init_py_SetSubtensor(py::module m) {
  14789. using py_op = PyOp(SetSubtensor);
  14790. auto& py_type = PyOpType(SetSubtensor);
  14791. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14792. py_type.tp_name = "megengine.core._imperative_rt.ops.SetSubtensor";
  14793. py_type.tp_basicsize = sizeof(PyOp(SetSubtensor));
  14794. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14795. py_type.tp_doc = "SetSubtensor";
  14796. py_type.tp_base = &PyOpType(OpDef);
  14797. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14798. py_type.tp_new = py_new_generic<py_op>;
  14799. py_type.tp_init = py_op::py_init;
  14800. py_type.tp_methods = py_op::tp_methods;
  14801. py_type.tp_getset = py_op::py_getsetters;
  14802. mgb_assert(PyType_Ready(&py_type) >= 0);
  14803. PyType_Modified(&py_type);
  14804. m.add_object("SetSubtensor", reinterpret_cast<PyObject*>(&py_type));
  14805. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetSubtensor::typeinfo(), &py_type).second);
  14806. }
  14807. PyOpDefBegin(ShuffleRNG) // {
  14808. static PyGetSetDef py_getsetters[];
  14809. static PyMethodDef tp_methods[];
  14810. static PyObject* getstate(PyObject* self, PyObject*) {
  14811. auto& opdef = reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst();
  14812. static_cast<void>(opdef);
  14813. std::unordered_map<std::string, py::object> state {
  14814. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  14815. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  14816. };
  14817. return py::cast(state).release().ptr();
  14818. }
  14819. static PyObject* setstate(PyObject* self, PyObject* args) {
  14820. PyObject* dict = PyTuple_GetItem(args, 0);
  14821. if (!dict) return NULL;
  14822. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14823. auto& opdef = reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst();
  14824. static_cast<void>(opdef);
  14825. {
  14826. auto&& iter = state.find("seed");
  14827. if (iter != state.end()) {
  14828. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  14829. }
  14830. }
  14831. {
  14832. auto&& iter = state.find("handle");
  14833. if (iter != state.end()) {
  14834. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  14835. }
  14836. }
  14837. Py_RETURN_NONE;
  14838. }
  14839. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14840. // };
  14841. PyOpDefEnd(ShuffleRNG)
  14842. int PyOp(ShuffleRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14843. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  14844. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  14845. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  14846. return -1;
  14847. if (seed) {
  14848. try {
  14849. // TODO: remove this guard which is used for pybind11 implicit conversion
  14850. py::detail::loader_life_support guard{};
  14851. reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst().seed =
  14852. py::cast<decltype(ShuffleRNG::seed)>(py::handle(seed));
  14853. } CATCH_ALL(-1)
  14854. }
  14855. if (handle) {
  14856. try {
  14857. // TODO: remove this guard which is used for pybind11 implicit conversion
  14858. py::detail::loader_life_support guard{};
  14859. reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst().handle =
  14860. py::cast<decltype(ShuffleRNG::handle)>(py::handle(handle));
  14861. } CATCH_ALL(-1)
  14862. }
  14863. if (scope) {
  14864. try {
  14865. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14866. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14867. } CATCH_ALL(-1)
  14868. }
  14869. return 0;
  14870. }
  14871. PyGetSetDef PyOp(ShuffleRNG)::py_getsetters[] = {
  14872. {const_cast<char*>("seed"), py_get_generic(ShuffleRNG, seed), py_set_generic(ShuffleRNG, seed), const_cast<char*>("seed"), NULL},
  14873. {const_cast<char*>("handle"), py_get_generic(ShuffleRNG, handle), py_set_generic(ShuffleRNG, handle), const_cast<char*>("handle"), NULL},
  14874. {NULL} /* Sentinel */
  14875. };
  14876. PyMethodDef PyOp(ShuffleRNG)::tp_methods[] = {
  14877. {const_cast<char*>("__getstate__"), PyOp(ShuffleRNG)::getstate, METH_NOARGS, "ShuffleRNG getstate"},
  14878. {const_cast<char*>("__setstate__"), PyOp(ShuffleRNG)::setstate, METH_VARARGS, "ShuffleRNG setstate"},
  14879. {NULL} /* Sentinel */
  14880. };
  14881. void _init_py_ShuffleRNG(py::module m) {
  14882. using py_op = PyOp(ShuffleRNG);
  14883. auto& py_type = PyOpType(ShuffleRNG);
  14884. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14885. py_type.tp_name = "megengine.core._imperative_rt.ops.ShuffleRNG";
  14886. py_type.tp_basicsize = sizeof(PyOp(ShuffleRNG));
  14887. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14888. py_type.tp_doc = "ShuffleRNG";
  14889. py_type.tp_base = &PyOpType(OpDef);
  14890. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14891. py_type.tp_new = py_new_generic<py_op>;
  14892. py_type.tp_init = py_op::py_init;
  14893. py_type.tp_methods = py_op::tp_methods;
  14894. py_type.tp_getset = py_op::py_getsetters;
  14895. mgb_assert(PyType_Ready(&py_type) >= 0);
  14896. PyType_Modified(&py_type);
  14897. m.add_object("ShuffleRNG", reinterpret_cast<PyObject*>(&py_type));
  14898. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ShuffleRNG::typeinfo(), &py_type).second);
  14899. }
  14900. PyOpDefBegin(SlidingWindowTranspose) // {
  14901. static PyGetSetDef py_getsetters[];
  14902. static PyMethodDef tp_methods[];
  14903. static PyObject* getstate(PyObject* self, PyObject*) {
  14904. auto& opdef = reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst();
  14905. static_cast<void>(opdef);
  14906. std::unordered_map<std::string, py::object> state {
  14907. {"out_h", serialization<decltype(opdef.out_h)>::dump(opdef.out_h)},
  14908. {"out_w", serialization<decltype(opdef.out_w)>::dump(opdef.out_w)},
  14909. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  14910. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  14911. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  14912. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  14913. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  14914. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  14915. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  14916. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)}
  14917. };
  14918. return py::cast(state).release().ptr();
  14919. }
  14920. static PyObject* setstate(PyObject* self, PyObject* args) {
  14921. PyObject* dict = PyTuple_GetItem(args, 0);
  14922. if (!dict) return NULL;
  14923. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14924. auto& opdef = reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst();
  14925. static_cast<void>(opdef);
  14926. {
  14927. auto&& iter = state.find("out_h");
  14928. if (iter != state.end()) {
  14929. opdef.out_h = serialization<decltype(opdef.out_h)>::load(iter->second);
  14930. }
  14931. }
  14932. {
  14933. auto&& iter = state.find("out_w");
  14934. if (iter != state.end()) {
  14935. opdef.out_w = serialization<decltype(opdef.out_w)>::load(iter->second);
  14936. }
  14937. }
  14938. {
  14939. auto&& iter = state.find("pad_h");
  14940. if (iter != state.end()) {
  14941. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  14942. }
  14943. }
  14944. {
  14945. auto&& iter = state.find("pad_w");
  14946. if (iter != state.end()) {
  14947. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  14948. }
  14949. }
  14950. {
  14951. auto&& iter = state.find("stride_h");
  14952. if (iter != state.end()) {
  14953. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  14954. }
  14955. }
  14956. {
  14957. auto&& iter = state.find("stride_w");
  14958. if (iter != state.end()) {
  14959. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  14960. }
  14961. }
  14962. {
  14963. auto&& iter = state.find("dilate_h");
  14964. if (iter != state.end()) {
  14965. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  14966. }
  14967. }
  14968. {
  14969. auto&& iter = state.find("dilate_w");
  14970. if (iter != state.end()) {
  14971. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  14972. }
  14973. }
  14974. {
  14975. auto&& iter = state.find("window_h");
  14976. if (iter != state.end()) {
  14977. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  14978. }
  14979. }
  14980. {
  14981. auto&& iter = state.find("window_w");
  14982. if (iter != state.end()) {
  14983. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  14984. }
  14985. }
  14986. Py_RETURN_NONE;
  14987. }
  14988. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14989. // };
  14990. PyOpDefEnd(SlidingWindowTranspose)
  14991. int PyOp(SlidingWindowTranspose)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14992. static const char* kwlist[] = {"out_h", "out_w", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "window_h", "window_w", "scope", NULL};
  14993. PyObject *out_h = NULL, *out_w = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *window_h = NULL, *window_w = NULL, *scope = NULL;
  14994. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast<char**>(kwlist), &out_h, &out_w, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &window_h, &window_w, &scope))
  14995. return -1;
  14996. if (out_h) {
  14997. try {
  14998. // TODO: remove this guard which is used for pybind11 implicit conversion
  14999. py::detail::loader_life_support guard{};
  15000. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().out_h =
  15001. py::cast<decltype(SlidingWindowTranspose::out_h)>(py::handle(out_h));
  15002. } CATCH_ALL(-1)
  15003. }
  15004. if (out_w) {
  15005. try {
  15006. // TODO: remove this guard which is used for pybind11 implicit conversion
  15007. py::detail::loader_life_support guard{};
  15008. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().out_w =
  15009. py::cast<decltype(SlidingWindowTranspose::out_w)>(py::handle(out_w));
  15010. } CATCH_ALL(-1)
  15011. }
  15012. if (pad_h) {
  15013. try {
  15014. // TODO: remove this guard which is used for pybind11 implicit conversion
  15015. py::detail::loader_life_support guard{};
  15016. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().pad_h =
  15017. py::cast<decltype(SlidingWindowTranspose::pad_h)>(py::handle(pad_h));
  15018. } CATCH_ALL(-1)
  15019. }
  15020. if (pad_w) {
  15021. try {
  15022. // TODO: remove this guard which is used for pybind11 implicit conversion
  15023. py::detail::loader_life_support guard{};
  15024. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().pad_w =
  15025. py::cast<decltype(SlidingWindowTranspose::pad_w)>(py::handle(pad_w));
  15026. } CATCH_ALL(-1)
  15027. }
  15028. if (stride_h) {
  15029. try {
  15030. // TODO: remove this guard which is used for pybind11 implicit conversion
  15031. py::detail::loader_life_support guard{};
  15032. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().stride_h =
  15033. py::cast<decltype(SlidingWindowTranspose::stride_h)>(py::handle(stride_h));
  15034. } CATCH_ALL(-1)
  15035. }
  15036. if (stride_w) {
  15037. try {
  15038. // TODO: remove this guard which is used for pybind11 implicit conversion
  15039. py::detail::loader_life_support guard{};
  15040. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().stride_w =
  15041. py::cast<decltype(SlidingWindowTranspose::stride_w)>(py::handle(stride_w));
  15042. } CATCH_ALL(-1)
  15043. }
  15044. if (dilate_h) {
  15045. try {
  15046. // TODO: remove this guard which is used for pybind11 implicit conversion
  15047. py::detail::loader_life_support guard{};
  15048. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().dilate_h =
  15049. py::cast<decltype(SlidingWindowTranspose::dilate_h)>(py::handle(dilate_h));
  15050. } CATCH_ALL(-1)
  15051. }
  15052. if (dilate_w) {
  15053. try {
  15054. // TODO: remove this guard which is used for pybind11 implicit conversion
  15055. py::detail::loader_life_support guard{};
  15056. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().dilate_w =
  15057. py::cast<decltype(SlidingWindowTranspose::dilate_w)>(py::handle(dilate_w));
  15058. } CATCH_ALL(-1)
  15059. }
  15060. if (window_h) {
  15061. try {
  15062. // TODO: remove this guard which is used for pybind11 implicit conversion
  15063. py::detail::loader_life_support guard{};
  15064. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().window_h =
  15065. py::cast<decltype(SlidingWindowTranspose::window_h)>(py::handle(window_h));
  15066. } CATCH_ALL(-1)
  15067. }
  15068. if (window_w) {
  15069. try {
  15070. // TODO: remove this guard which is used for pybind11 implicit conversion
  15071. py::detail::loader_life_support guard{};
  15072. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().window_w =
  15073. py::cast<decltype(SlidingWindowTranspose::window_w)>(py::handle(window_w));
  15074. } CATCH_ALL(-1)
  15075. }
  15076. if (scope) {
  15077. try {
  15078. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15079. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15080. } CATCH_ALL(-1)
  15081. }
  15082. return 0;
  15083. }
  15084. PyGetSetDef PyOp(SlidingWindowTranspose)::py_getsetters[] = {
  15085. {const_cast<char*>("out_h"), py_get_generic(SlidingWindowTranspose, out_h), py_set_generic(SlidingWindowTranspose, out_h), const_cast<char*>("out_h"), NULL},
  15086. {const_cast<char*>("out_w"), py_get_generic(SlidingWindowTranspose, out_w), py_set_generic(SlidingWindowTranspose, out_w), const_cast<char*>("out_w"), NULL},
  15087. {const_cast<char*>("pad_h"), py_get_generic(SlidingWindowTranspose, pad_h), py_set_generic(SlidingWindowTranspose, pad_h), const_cast<char*>("pad_h"), NULL},
  15088. {const_cast<char*>("pad_w"), py_get_generic(SlidingWindowTranspose, pad_w), py_set_generic(SlidingWindowTranspose, pad_w), const_cast<char*>("pad_w"), NULL},
  15089. {const_cast<char*>("stride_h"), py_get_generic(SlidingWindowTranspose, stride_h), py_set_generic(SlidingWindowTranspose, stride_h), const_cast<char*>("stride_h"), NULL},
  15090. {const_cast<char*>("stride_w"), py_get_generic(SlidingWindowTranspose, stride_w), py_set_generic(SlidingWindowTranspose, stride_w), const_cast<char*>("stride_w"), NULL},
  15091. {const_cast<char*>("dilate_h"), py_get_generic(SlidingWindowTranspose, dilate_h), py_set_generic(SlidingWindowTranspose, dilate_h), const_cast<char*>("dilate_h"), NULL},
  15092. {const_cast<char*>("dilate_w"), py_get_generic(SlidingWindowTranspose, dilate_w), py_set_generic(SlidingWindowTranspose, dilate_w), const_cast<char*>("dilate_w"), NULL},
  15093. {const_cast<char*>("window_h"), py_get_generic(SlidingWindowTranspose, window_h), py_set_generic(SlidingWindowTranspose, window_h), const_cast<char*>("window_h"), NULL},
  15094. {const_cast<char*>("window_w"), py_get_generic(SlidingWindowTranspose, window_w), py_set_generic(SlidingWindowTranspose, window_w), const_cast<char*>("window_w"), NULL},
  15095. {NULL} /* Sentinel */
  15096. };
  15097. PyMethodDef PyOp(SlidingWindowTranspose)::tp_methods[] = {
  15098. {const_cast<char*>("__getstate__"), PyOp(SlidingWindowTranspose)::getstate, METH_NOARGS, "SlidingWindowTranspose getstate"},
  15099. {const_cast<char*>("__setstate__"), PyOp(SlidingWindowTranspose)::setstate, METH_VARARGS, "SlidingWindowTranspose setstate"},
  15100. {NULL} /* Sentinel */
  15101. };
  15102. void _init_py_SlidingWindowTranspose(py::module m) {
  15103. using py_op = PyOp(SlidingWindowTranspose);
  15104. auto& py_type = PyOpType(SlidingWindowTranspose);
  15105. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15106. py_type.tp_name = "megengine.core._imperative_rt.ops.SlidingWindowTranspose";
  15107. py_type.tp_basicsize = sizeof(PyOp(SlidingWindowTranspose));
  15108. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15109. py_type.tp_doc = "SlidingWindowTranspose";
  15110. py_type.tp_base = &PyOpType(OpDef);
  15111. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15112. py_type.tp_new = py_new_generic<py_op>;
  15113. py_type.tp_init = py_op::py_init;
  15114. py_type.tp_methods = py_op::tp_methods;
  15115. py_type.tp_getset = py_op::py_getsetters;
  15116. mgb_assert(PyType_Ready(&py_type) >= 0);
  15117. PyType_Modified(&py_type);
  15118. m.add_object("SlidingWindowTranspose", reinterpret_cast<PyObject*>(&py_type));
  15119. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SlidingWindowTranspose::typeinfo(), &py_type).second);
  15120. }
  15121. PyOpDefBegin(Softmax) // {
  15122. static PyGetSetDef py_getsetters[];
  15123. static PyMethodDef tp_methods[];
  15124. static PyObject* getstate(PyObject* self, PyObject*) {
  15125. auto& opdef = reinterpret_cast<PyOp(Softmax)*>(self)->inst();
  15126. static_cast<void>(opdef);
  15127. std::unordered_map<std::string, py::object> state {
  15128. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  15129. };
  15130. return py::cast(state).release().ptr();
  15131. }
  15132. static PyObject* setstate(PyObject* self, PyObject* args) {
  15133. PyObject* dict = PyTuple_GetItem(args, 0);
  15134. if (!dict) return NULL;
  15135. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15136. auto& opdef = reinterpret_cast<PyOp(Softmax)*>(self)->inst();
  15137. static_cast<void>(opdef);
  15138. {
  15139. auto&& iter = state.find("axis");
  15140. if (iter != state.end()) {
  15141. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  15142. }
  15143. }
  15144. Py_RETURN_NONE;
  15145. }
  15146. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15147. // };
  15148. PyOpDefEnd(Softmax)
  15149. int PyOp(Softmax)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15150. static const char* kwlist[] = {"axis", "scope", NULL};
  15151. PyObject *axis = NULL, *scope = NULL;
  15152. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  15153. return -1;
  15154. if (axis) {
  15155. try {
  15156. // TODO: remove this guard which is used for pybind11 implicit conversion
  15157. py::detail::loader_life_support guard{};
  15158. reinterpret_cast<PyOp(Softmax)*>(self)->inst().axis =
  15159. py::cast<decltype(Softmax::axis)>(py::handle(axis));
  15160. } CATCH_ALL(-1)
  15161. }
  15162. if (scope) {
  15163. try {
  15164. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15165. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15166. } CATCH_ALL(-1)
  15167. }
  15168. return 0;
  15169. }
  15170. PyGetSetDef PyOp(Softmax)::py_getsetters[] = {
  15171. {const_cast<char*>("axis"), py_get_generic(Softmax, axis), py_set_generic(Softmax, axis), const_cast<char*>("axis"), NULL},
  15172. {NULL} /* Sentinel */
  15173. };
  15174. PyMethodDef PyOp(Softmax)::tp_methods[] = {
  15175. {const_cast<char*>("__getstate__"), PyOp(Softmax)::getstate, METH_NOARGS, "Softmax getstate"},
  15176. {const_cast<char*>("__setstate__"), PyOp(Softmax)::setstate, METH_VARARGS, "Softmax setstate"},
  15177. {NULL} /* Sentinel */
  15178. };
  15179. void _init_py_Softmax(py::module m) {
  15180. using py_op = PyOp(Softmax);
  15181. auto& py_type = PyOpType(Softmax);
  15182. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15183. py_type.tp_name = "megengine.core._imperative_rt.ops.Softmax";
  15184. py_type.tp_basicsize = sizeof(PyOp(Softmax));
  15185. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15186. py_type.tp_doc = "Softmax";
  15187. py_type.tp_base = &PyOpType(OpDef);
  15188. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15189. py_type.tp_new = py_new_generic<py_op>;
  15190. py_type.tp_init = py_op::py_init;
  15191. py_type.tp_methods = py_op::tp_methods;
  15192. py_type.tp_getset = py_op::py_getsetters;
  15193. mgb_assert(PyType_Ready(&py_type) >= 0);
  15194. PyType_Modified(&py_type);
  15195. m.add_object("Softmax", reinterpret_cast<PyObject*>(&py_type));
  15196. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Softmax::typeinfo(), &py_type).second);
  15197. }
  15198. PyOpDefBegin(Split) // {
  15199. static PyGetSetDef py_getsetters[];
  15200. static PyMethodDef tp_methods[];
  15201. static PyObject* getstate(PyObject* self, PyObject*) {
  15202. auto& opdef = reinterpret_cast<PyOp(Split)*>(self)->inst();
  15203. static_cast<void>(opdef);
  15204. std::unordered_map<std::string, py::object> state {
  15205. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  15206. {"nsections", serialization<decltype(opdef.nsections)>::dump(opdef.nsections)}
  15207. };
  15208. return py::cast(state).release().ptr();
  15209. }
  15210. static PyObject* setstate(PyObject* self, PyObject* args) {
  15211. PyObject* dict = PyTuple_GetItem(args, 0);
  15212. if (!dict) return NULL;
  15213. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15214. auto& opdef = reinterpret_cast<PyOp(Split)*>(self)->inst();
  15215. static_cast<void>(opdef);
  15216. {
  15217. auto&& iter = state.find("axis");
  15218. if (iter != state.end()) {
  15219. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  15220. }
  15221. }
  15222. {
  15223. auto&& iter = state.find("nsections");
  15224. if (iter != state.end()) {
  15225. opdef.nsections = serialization<decltype(opdef.nsections)>::load(iter->second);
  15226. }
  15227. }
  15228. Py_RETURN_NONE;
  15229. }
  15230. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15231. // };
  15232. PyOpDefEnd(Split)
  15233. int PyOp(Split)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15234. static const char* kwlist[] = {"axis", "nsections", "scope", NULL};
  15235. PyObject *axis = NULL, *nsections = NULL, *scope = NULL;
  15236. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &nsections, &scope))
  15237. return -1;
  15238. if (axis) {
  15239. try {
  15240. // TODO: remove this guard which is used for pybind11 implicit conversion
  15241. py::detail::loader_life_support guard{};
  15242. reinterpret_cast<PyOp(Split)*>(self)->inst().axis =
  15243. py::cast<decltype(Split::axis)>(py::handle(axis));
  15244. } CATCH_ALL(-1)
  15245. }
  15246. if (nsections) {
  15247. try {
  15248. // TODO: remove this guard which is used for pybind11 implicit conversion
  15249. py::detail::loader_life_support guard{};
  15250. reinterpret_cast<PyOp(Split)*>(self)->inst().nsections =
  15251. py::cast<decltype(Split::nsections)>(py::handle(nsections));
  15252. } CATCH_ALL(-1)
  15253. }
  15254. if (scope) {
  15255. try {
  15256. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15257. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15258. } CATCH_ALL(-1)
  15259. }
  15260. return 0;
  15261. }
  15262. PyGetSetDef PyOp(Split)::py_getsetters[] = {
  15263. {const_cast<char*>("axis"), py_get_generic(Split, axis), py_set_generic(Split, axis), const_cast<char*>("axis"), NULL},
  15264. {const_cast<char*>("nsections"), py_get_generic(Split, nsections), py_set_generic(Split, nsections), const_cast<char*>("nsections"), NULL},
  15265. {NULL} /* Sentinel */
  15266. };
  15267. PyMethodDef PyOp(Split)::tp_methods[] = {
  15268. {const_cast<char*>("__getstate__"), PyOp(Split)::getstate, METH_NOARGS, "Split getstate"},
  15269. {const_cast<char*>("__setstate__"), PyOp(Split)::setstate, METH_VARARGS, "Split setstate"},
  15270. {NULL} /* Sentinel */
  15271. };
  15272. void _init_py_Split(py::module m) {
  15273. using py_op = PyOp(Split);
  15274. auto& py_type = PyOpType(Split);
  15275. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15276. py_type.tp_name = "megengine.core._imperative_rt.ops.Split";
  15277. py_type.tp_basicsize = sizeof(PyOp(Split));
  15278. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15279. py_type.tp_doc = "Split";
  15280. py_type.tp_base = &PyOpType(OpDef);
  15281. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15282. py_type.tp_new = py_new_generic<py_op>;
  15283. py_type.tp_init = py_op::py_init;
  15284. py_type.tp_methods = py_op::tp_methods;
  15285. py_type.tp_getset = py_op::py_getsetters;
  15286. mgb_assert(PyType_Ready(&py_type) >= 0);
  15287. PyType_Modified(&py_type);
  15288. m.add_object("Split", reinterpret_cast<PyObject*>(&py_type));
  15289. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Split::typeinfo(), &py_type).second);
  15290. }
  15291. PyOpDefBegin(Subtensor) // {
  15292. static PyGetSetDef py_getsetters[];
  15293. static PyMethodDef tp_methods[];
  15294. static PyObject* getstate(PyObject* self, PyObject*) {
  15295. auto& opdef = reinterpret_cast<PyOp(Subtensor)*>(self)->inst();
  15296. static_cast<void>(opdef);
  15297. std::unordered_map<std::string, py::object> state {
  15298. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  15299. };
  15300. return py::cast(state).release().ptr();
  15301. }
  15302. static PyObject* setstate(PyObject* self, PyObject* args) {
  15303. PyObject* dict = PyTuple_GetItem(args, 0);
  15304. if (!dict) return NULL;
  15305. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15306. auto& opdef = reinterpret_cast<PyOp(Subtensor)*>(self)->inst();
  15307. static_cast<void>(opdef);
  15308. {
  15309. auto&& iter = state.find("items");
  15310. if (iter != state.end()) {
  15311. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  15312. }
  15313. }
  15314. Py_RETURN_NONE;
  15315. }
  15316. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15317. // };
  15318. PyOpDefEnd(Subtensor)
  15319. int PyOp(Subtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15320. static const char* kwlist[] = {"items", "scope", NULL};
  15321. PyObject *items = NULL, *scope = NULL;
  15322. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  15323. return -1;
  15324. if (items) {
  15325. try {
  15326. // TODO: remove this guard which is used for pybind11 implicit conversion
  15327. py::detail::loader_life_support guard{};
  15328. reinterpret_cast<PyOp(Subtensor)*>(self)->inst().items =
  15329. py::cast<decltype(Subtensor::items)>(py::handle(items));
  15330. } CATCH_ALL(-1)
  15331. }
  15332. if (scope) {
  15333. try {
  15334. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15335. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15336. } CATCH_ALL(-1)
  15337. }
  15338. return 0;
  15339. }
  15340. PyGetSetDef PyOp(Subtensor)::py_getsetters[] = {
  15341. {const_cast<char*>("items"), py_get_generic(Subtensor, items), py_set_generic(Subtensor, items), const_cast<char*>("items"), NULL},
  15342. {NULL} /* Sentinel */
  15343. };
  15344. PyMethodDef PyOp(Subtensor)::tp_methods[] = {
  15345. {const_cast<char*>("__getstate__"), PyOp(Subtensor)::getstate, METH_NOARGS, "Subtensor getstate"},
  15346. {const_cast<char*>("__setstate__"), PyOp(Subtensor)::setstate, METH_VARARGS, "Subtensor setstate"},
  15347. {NULL} /* Sentinel */
  15348. };
  15349. void _init_py_Subtensor(py::module m) {
  15350. using py_op = PyOp(Subtensor);
  15351. auto& py_type = PyOpType(Subtensor);
  15352. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15353. py_type.tp_name = "megengine.core._imperative_rt.ops.Subtensor";
  15354. py_type.tp_basicsize = sizeof(PyOp(Subtensor));
  15355. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15356. py_type.tp_doc = "Subtensor";
  15357. py_type.tp_base = &PyOpType(OpDef);
  15358. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15359. py_type.tp_new = py_new_generic<py_op>;
  15360. py_type.tp_init = py_op::py_init;
  15361. py_type.tp_methods = py_op::tp_methods;
  15362. py_type.tp_getset = py_op::py_getsetters;
  15363. mgb_assert(PyType_Ready(&py_type) >= 0);
  15364. PyType_Modified(&py_type);
  15365. m.add_object("Subtensor", reinterpret_cast<PyObject*>(&py_type));
  15366. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Subtensor::typeinfo(), &py_type).second);
  15367. }
  15368. PyOpDefBegin(TQT) // {
  15369. static PyGetSetDef py_getsetters[];
  15370. static PyMethodDef tp_methods[];
  15371. static PyObject* getstate(PyObject* self, PyObject*) {
  15372. auto& opdef = reinterpret_cast<PyOp(TQT)*>(self)->inst();
  15373. static_cast<void>(opdef);
  15374. std::unordered_map<std::string, py::object> state {
  15375. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  15376. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  15377. };
  15378. return py::cast(state).release().ptr();
  15379. }
  15380. static PyObject* setstate(PyObject* self, PyObject* args) {
  15381. PyObject* dict = PyTuple_GetItem(args, 0);
  15382. if (!dict) return NULL;
  15383. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15384. auto& opdef = reinterpret_cast<PyOp(TQT)*>(self)->inst();
  15385. static_cast<void>(opdef);
  15386. {
  15387. auto&& iter = state.find("qmin");
  15388. if (iter != state.end()) {
  15389. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  15390. }
  15391. }
  15392. {
  15393. auto&& iter = state.find("qmax");
  15394. if (iter != state.end()) {
  15395. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  15396. }
  15397. }
  15398. Py_RETURN_NONE;
  15399. }
  15400. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15401. // };
  15402. PyOpDefEnd(TQT)
  15403. int PyOp(TQT)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15404. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  15405. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  15406. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  15407. return -1;
  15408. if (qmin) {
  15409. try {
  15410. // TODO: remove this guard which is used for pybind11 implicit conversion
  15411. py::detail::loader_life_support guard{};
  15412. reinterpret_cast<PyOp(TQT)*>(self)->inst().qmin =
  15413. py::cast<decltype(TQT::qmin)>(py::handle(qmin));
  15414. } CATCH_ALL(-1)
  15415. }
  15416. if (qmax) {
  15417. try {
  15418. // TODO: remove this guard which is used for pybind11 implicit conversion
  15419. py::detail::loader_life_support guard{};
  15420. reinterpret_cast<PyOp(TQT)*>(self)->inst().qmax =
  15421. py::cast<decltype(TQT::qmax)>(py::handle(qmax));
  15422. } CATCH_ALL(-1)
  15423. }
  15424. if (scope) {
  15425. try {
  15426. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15427. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15428. } CATCH_ALL(-1)
  15429. }
  15430. return 0;
  15431. }
  15432. PyGetSetDef PyOp(TQT)::py_getsetters[] = {
  15433. {const_cast<char*>("qmin"), py_get_generic(TQT, qmin), py_set_generic(TQT, qmin), const_cast<char*>("qmin"), NULL},
  15434. {const_cast<char*>("qmax"), py_get_generic(TQT, qmax), py_set_generic(TQT, qmax), const_cast<char*>("qmax"), NULL},
  15435. {NULL} /* Sentinel */
  15436. };
  15437. PyMethodDef PyOp(TQT)::tp_methods[] = {
  15438. {const_cast<char*>("__getstate__"), PyOp(TQT)::getstate, METH_NOARGS, "TQT getstate"},
  15439. {const_cast<char*>("__setstate__"), PyOp(TQT)::setstate, METH_VARARGS, "TQT setstate"},
  15440. {NULL} /* Sentinel */
  15441. };
  15442. void _init_py_TQT(py::module m) {
  15443. using py_op = PyOp(TQT);
  15444. auto& py_type = PyOpType(TQT);
  15445. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15446. py_type.tp_name = "megengine.core._imperative_rt.ops.TQT";
  15447. py_type.tp_basicsize = sizeof(PyOp(TQT));
  15448. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15449. py_type.tp_doc = "TQT";
  15450. py_type.tp_base = &PyOpType(OpDef);
  15451. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15452. py_type.tp_new = py_new_generic<py_op>;
  15453. py_type.tp_init = py_op::py_init;
  15454. py_type.tp_methods = py_op::tp_methods;
  15455. py_type.tp_getset = py_op::py_getsetters;
  15456. mgb_assert(PyType_Ready(&py_type) >= 0);
  15457. PyType_Modified(&py_type);
  15458. m.add_object("TQT", reinterpret_cast<PyObject*>(&py_type));
  15459. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TQT::typeinfo(), &py_type).second);
  15460. }
  15461. PyOpDefBegin(TensorRTRuntime) // {
  15462. static PyGetSetDef py_getsetters[];
  15463. static PyMethodDef tp_methods[];
  15464. static PyObject* getstate(PyObject* self, PyObject*) {
  15465. auto& opdef = reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst();
  15466. static_cast<void>(opdef);
  15467. std::unordered_map<std::string, py::object> state {
  15468. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  15469. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  15470. };
  15471. return py::cast(state).release().ptr();
  15472. }
  15473. static PyObject* setstate(PyObject* self, PyObject* args) {
  15474. PyObject* dict = PyTuple_GetItem(args, 0);
  15475. if (!dict) return NULL;
  15476. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15477. auto& opdef = reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst();
  15478. static_cast<void>(opdef);
  15479. {
  15480. auto&& iter = state.find("buf");
  15481. if (iter != state.end()) {
  15482. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  15483. }
  15484. }
  15485. {
  15486. auto&& iter = state.find("buf_size");
  15487. if (iter != state.end()) {
  15488. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  15489. }
  15490. }
  15491. Py_RETURN_NONE;
  15492. }
  15493. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15494. // };
  15495. PyOpDefEnd(TensorRTRuntime)
  15496. int PyOp(TensorRTRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15497. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  15498. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  15499. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  15500. return -1;
  15501. if (buf) {
  15502. try {
  15503. // TODO: remove this guard which is used for pybind11 implicit conversion
  15504. py::detail::loader_life_support guard{};
  15505. reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst().buf =
  15506. py::cast<decltype(TensorRTRuntime::buf)>(py::handle(buf));
  15507. } CATCH_ALL(-1)
  15508. }
  15509. if (buf_size) {
  15510. try {
  15511. // TODO: remove this guard which is used for pybind11 implicit conversion
  15512. py::detail::loader_life_support guard{};
  15513. reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst().buf_size =
  15514. py::cast<decltype(TensorRTRuntime::buf_size)>(py::handle(buf_size));
  15515. } CATCH_ALL(-1)
  15516. }
  15517. if (scope) {
  15518. try {
  15519. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15520. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15521. } CATCH_ALL(-1)
  15522. }
  15523. return 0;
  15524. }
  15525. PyGetSetDef PyOp(TensorRTRuntime)::py_getsetters[] = {
  15526. {const_cast<char*>("buf"), py_get_generic(TensorRTRuntime, buf), py_set_generic(TensorRTRuntime, buf), const_cast<char*>("buf"), NULL},
  15527. {const_cast<char*>("buf_size"), py_get_generic(TensorRTRuntime, buf_size), py_set_generic(TensorRTRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  15528. {NULL} /* Sentinel */
  15529. };
  15530. PyMethodDef PyOp(TensorRTRuntime)::tp_methods[] = {
  15531. {const_cast<char*>("__getstate__"), PyOp(TensorRTRuntime)::getstate, METH_NOARGS, "TensorRTRuntime getstate"},
  15532. {const_cast<char*>("__setstate__"), PyOp(TensorRTRuntime)::setstate, METH_VARARGS, "TensorRTRuntime setstate"},
  15533. {NULL} /* Sentinel */
  15534. };
  15535. void _init_py_TensorRTRuntime(py::module m) {
  15536. using py_op = PyOp(TensorRTRuntime);
  15537. auto& py_type = PyOpType(TensorRTRuntime);
  15538. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15539. py_type.tp_name = "megengine.core._imperative_rt.ops.TensorRTRuntime";
  15540. py_type.tp_basicsize = sizeof(PyOp(TensorRTRuntime));
  15541. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15542. py_type.tp_doc = "TensorRTRuntime";
  15543. py_type.tp_base = &PyOpType(OpDef);
  15544. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15545. py_type.tp_new = py_new_generic<py_op>;
  15546. py_type.tp_init = py_op::py_init;
  15547. py_type.tp_methods = py_op::tp_methods;
  15548. py_type.tp_getset = py_op::py_getsetters;
  15549. mgb_assert(PyType_Ready(&py_type) >= 0);
  15550. PyType_Modified(&py_type);
  15551. m.add_object("TensorRTRuntime", reinterpret_cast<PyObject*>(&py_type));
  15552. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TensorRTRuntime::typeinfo(), &py_type).second);
  15553. }
  15554. template<> struct EnumTrait<TopK::Mode> {
  15555. static constexpr const char *name = "TopK.Mode";
  15556. static constexpr std::underlying_type_t<TopK::Mode> max = 3 - 1;
  15557. };
  15558. template<> PyTypeObject* EnumWrapper<TopK::Mode>::type = nullptr;
  15559. template<> const char*
  15560. EnumWrapper<TopK::Mode>::members[] = {"KTH_ONLY", "VALUE_IDX_NOSORT", "VALUE_IDX_SORTED"};
  15561. template<> std::unordered_map<std::string, TopK::Mode>
  15562. EnumWrapper<TopK::Mode>::mem2value = {{normalize_enum("KTH_ONLY"), TopK::Mode::KTH_ONLY}, {normalize_enum("VALUE_IDX_NOSORT"), TopK::Mode::VALUE_IDX_NOSORT}, {normalize_enum("VALUE_IDX_SORTED"), TopK::Mode::VALUE_IDX_SORTED}};
  15563. template<> PyObject* EnumWrapper<TopK::Mode>::pyobj_insts[3] = {nullptr};
  15564. void _init_py_TopK_Mode(PyTypeObject& py_type) {
  15565. auto& e_type = EnumWrapper<TopK::Mode>::type;
  15566. static PyMethodDef tp_methods[] = {
  15567. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<TopK::Mode>::py_dump, METH_NOARGS, NULL},
  15568. {NULL} /* Sentinel */
  15569. };
  15570. static PyType_Slot slots[] = {
  15571. {Py_tp_repr, (void*)EnumWrapper<TopK::Mode>::py_repr},
  15572. {Py_tp_richcompare, (void*)EnumWrapper<TopK::Mode>::tp_richcompare},
  15573. {Py_tp_methods, tp_methods},
  15574. {0, NULL}
  15575. };
  15576. static PyType_Spec spec = {
  15577. // name
  15578. "megengine.core._imperative_rt.ops.TopK.Mode",
  15579. // basicsize
  15580. sizeof(EnumWrapper<TopK::Mode>),
  15581. // itemsize
  15582. 0,
  15583. // flags
  15584. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  15585. // slots
  15586. slots
  15587. };
  15588. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  15589. mgb_assert(
  15590. e_type->tp_setattro(
  15591. reinterpret_cast<PyObject*>(e_type),
  15592. py::cast("__name__").release().ptr(),
  15593. py::cast("Mode").release().ptr()) >= 0);
  15594. mgb_assert(
  15595. e_type->tp_setattro(
  15596. reinterpret_cast<PyObject*>(e_type),
  15597. py::cast("__module__").release().ptr(),
  15598. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  15599. mgb_assert(
  15600. e_type->tp_setattro(
  15601. reinterpret_cast<PyObject*>(e_type),
  15602. py::cast("__qualname__").release().ptr(),
  15603. py::cast("TopK.Mode").release().ptr()) >= 0);
  15604. {
  15605. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15606. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::KTH_ONLY;
  15607. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "KTH_ONLY", inst) >= 0);
  15608. EnumWrapper<TopK::Mode>::pyobj_insts[0] = inst;
  15609. }{
  15610. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15611. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::VALUE_IDX_NOSORT;
  15612. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_NOSORT", inst) >= 0);
  15613. EnumWrapper<TopK::Mode>::pyobj_insts[1] = inst;
  15614. }{
  15615. PyObject* inst = e_type->tp_alloc(e_type, 0);
  15616. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::VALUE_IDX_SORTED;
  15617. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_SORTED", inst) >= 0);
  15618. EnumWrapper<TopK::Mode>::pyobj_insts[2] = inst;
  15619. }
  15620. Py_INCREF(e_type);
  15621. mgb_assert(PyDict_SetItemString(
  15622. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15623. }
  15624. PyOpDefBegin(TopK) // {
  15625. static PyGetSetDef py_getsetters[];
  15626. static PyMethodDef tp_methods[];
  15627. static PyObject* getstate(PyObject* self, PyObject*) {
  15628. auto& opdef = reinterpret_cast<PyOp(TopK)*>(self)->inst();
  15629. static_cast<void>(opdef);
  15630. std::unordered_map<std::string, py::object> state {
  15631. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  15632. };
  15633. return py::cast(state).release().ptr();
  15634. }
  15635. static PyObject* setstate(PyObject* self, PyObject* args) {
  15636. PyObject* dict = PyTuple_GetItem(args, 0);
  15637. if (!dict) return NULL;
  15638. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15639. auto& opdef = reinterpret_cast<PyOp(TopK)*>(self)->inst();
  15640. static_cast<void>(opdef);
  15641. {
  15642. auto&& iter = state.find("mode");
  15643. if (iter != state.end()) {
  15644. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  15645. }
  15646. }
  15647. Py_RETURN_NONE;
  15648. }
  15649. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15650. // };
  15651. PyOpDefEnd(TopK)
  15652. int PyOp(TopK)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15653. static const char* kwlist[] = {"mode", "scope", NULL};
  15654. PyObject *mode = NULL, *scope = NULL;
  15655. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  15656. return -1;
  15657. if (mode) {
  15658. try {
  15659. // TODO: remove this guard which is used for pybind11 implicit conversion
  15660. py::detail::loader_life_support guard{};
  15661. reinterpret_cast<PyOp(TopK)*>(self)->inst().mode =
  15662. py::cast<decltype(TopK::mode)>(py::handle(mode));
  15663. } CATCH_ALL(-1)
  15664. }
  15665. if (scope) {
  15666. try {
  15667. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15668. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15669. } CATCH_ALL(-1)
  15670. }
  15671. return 0;
  15672. }
  15673. PyGetSetDef PyOp(TopK)::py_getsetters[] = {
  15674. {const_cast<char*>("mode"), py_get_generic(TopK, mode), py_set_generic(TopK, mode), const_cast<char*>("mode"), NULL},
  15675. {NULL} /* Sentinel */
  15676. };
  15677. PyMethodDef PyOp(TopK)::tp_methods[] = {
  15678. {const_cast<char*>("__getstate__"), PyOp(TopK)::getstate, METH_NOARGS, "TopK getstate"},
  15679. {const_cast<char*>("__setstate__"), PyOp(TopK)::setstate, METH_VARARGS, "TopK setstate"},
  15680. {NULL} /* Sentinel */
  15681. };
  15682. void _init_py_TopK(py::module m) {
  15683. using py_op = PyOp(TopK);
  15684. auto& py_type = PyOpType(TopK);
  15685. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15686. py_type.tp_name = "megengine.core._imperative_rt.ops.TopK";
  15687. py_type.tp_basicsize = sizeof(PyOp(TopK));
  15688. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15689. py_type.tp_doc = "TopK";
  15690. py_type.tp_base = &PyOpType(OpDef);
  15691. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15692. py_type.tp_new = py_new_generic<py_op>;
  15693. py_type.tp_init = py_op::py_init;
  15694. py_type.tp_methods = py_op::tp_methods;
  15695. py_type.tp_getset = py_op::py_getsetters;
  15696. mgb_assert(PyType_Ready(&py_type) >= 0);
  15697. _init_py_TopK_Mode(py_type);
  15698. PyType_Modified(&py_type);
  15699. m.add_object("TopK", reinterpret_cast<PyObject*>(&py_type));
  15700. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TopK::typeinfo(), &py_type).second);
  15701. }
  15702. PyOpDefBegin(TypeCvt) // {
  15703. static PyGetSetDef py_getsetters[];
  15704. static PyMethodDef tp_methods[];
  15705. static PyObject* getstate(PyObject* self, PyObject*) {
  15706. auto& opdef = reinterpret_cast<PyOp(TypeCvt)*>(self)->inst();
  15707. static_cast<void>(opdef);
  15708. std::unordered_map<std::string, py::object> state {
  15709. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  15710. };
  15711. return py::cast(state).release().ptr();
  15712. }
  15713. static PyObject* setstate(PyObject* self, PyObject* args) {
  15714. PyObject* dict = PyTuple_GetItem(args, 0);
  15715. if (!dict) return NULL;
  15716. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15717. auto& opdef = reinterpret_cast<PyOp(TypeCvt)*>(self)->inst();
  15718. static_cast<void>(opdef);
  15719. {
  15720. auto&& iter = state.find("dtype");
  15721. if (iter != state.end()) {
  15722. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  15723. }
  15724. }
  15725. Py_RETURN_NONE;
  15726. }
  15727. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15728. // };
  15729. PyOpDefEnd(TypeCvt)
  15730. int PyOp(TypeCvt)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15731. static const char* kwlist[] = {"dtype", "scope", NULL};
  15732. PyObject *dtype = NULL, *scope = NULL;
  15733. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &dtype, &scope))
  15734. return -1;
  15735. if (dtype) {
  15736. try {
  15737. // TODO: remove this guard which is used for pybind11 implicit conversion
  15738. py::detail::loader_life_support guard{};
  15739. reinterpret_cast<PyOp(TypeCvt)*>(self)->inst().dtype =
  15740. py::cast<decltype(TypeCvt::dtype)>(py::handle(dtype));
  15741. } CATCH_ALL(-1)
  15742. }
  15743. if (scope) {
  15744. try {
  15745. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15746. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15747. } CATCH_ALL(-1)
  15748. }
  15749. return 0;
  15750. }
  15751. PyGetSetDef PyOp(TypeCvt)::py_getsetters[] = {
  15752. {const_cast<char*>("dtype"), py_get_generic(TypeCvt, dtype), py_set_generic(TypeCvt, dtype), const_cast<char*>("dtype"), NULL},
  15753. {NULL} /* Sentinel */
  15754. };
  15755. PyMethodDef PyOp(TypeCvt)::tp_methods[] = {
  15756. {const_cast<char*>("__getstate__"), PyOp(TypeCvt)::getstate, METH_NOARGS, "TypeCvt getstate"},
  15757. {const_cast<char*>("__setstate__"), PyOp(TypeCvt)::setstate, METH_VARARGS, "TypeCvt setstate"},
  15758. {NULL} /* Sentinel */
  15759. };
  15760. void _init_py_TypeCvt(py::module m) {
  15761. using py_op = PyOp(TypeCvt);
  15762. auto& py_type = PyOpType(TypeCvt);
  15763. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15764. py_type.tp_name = "megengine.core._imperative_rt.ops.TypeCvt";
  15765. py_type.tp_basicsize = sizeof(PyOp(TypeCvt));
  15766. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15767. py_type.tp_doc = "TypeCvt";
  15768. py_type.tp_base = &PyOpType(OpDef);
  15769. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15770. py_type.tp_new = py_new_generic<py_op>;
  15771. py_type.tp_init = py_op::py_init;
  15772. py_type.tp_methods = py_op::tp_methods;
  15773. py_type.tp_getset = py_op::py_getsetters;
  15774. mgb_assert(PyType_Ready(&py_type) >= 0);
  15775. PyType_Modified(&py_type);
  15776. m.add_object("TypeCvt", reinterpret_cast<PyObject*>(&py_type));
  15777. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TypeCvt::typeinfo(), &py_type).second);
  15778. }
  15779. PyOpDefBegin(UniformRNG) // {
  15780. static PyGetSetDef py_getsetters[];
  15781. static PyMethodDef tp_methods[];
  15782. static PyObject* getstate(PyObject* self, PyObject*) {
  15783. auto& opdef = reinterpret_cast<PyOp(UniformRNG)*>(self)->inst();
  15784. static_cast<void>(opdef);
  15785. std::unordered_map<std::string, py::object> state {
  15786. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  15787. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  15788. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  15789. };
  15790. return py::cast(state).release().ptr();
  15791. }
  15792. static PyObject* setstate(PyObject* self, PyObject* args) {
  15793. PyObject* dict = PyTuple_GetItem(args, 0);
  15794. if (!dict) return NULL;
  15795. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15796. auto& opdef = reinterpret_cast<PyOp(UniformRNG)*>(self)->inst();
  15797. static_cast<void>(opdef);
  15798. {
  15799. auto&& iter = state.find("seed");
  15800. if (iter != state.end()) {
  15801. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  15802. }
  15803. }
  15804. {
  15805. auto&& iter = state.find("dtype");
  15806. if (iter != state.end()) {
  15807. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  15808. }
  15809. }
  15810. {
  15811. auto&& iter = state.find("handle");
  15812. if (iter != state.end()) {
  15813. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  15814. }
  15815. }
  15816. Py_RETURN_NONE;
  15817. }
  15818. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15819. // };
  15820. PyOpDefEnd(UniformRNG)
  15821. int PyOp(UniformRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15822. static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL};
  15823. PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  15824. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &seed, &dtype, &handle, &scope))
  15825. return -1;
  15826. if (seed) {
  15827. try {
  15828. // TODO: remove this guard which is used for pybind11 implicit conversion
  15829. py::detail::loader_life_support guard{};
  15830. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().seed =
  15831. py::cast<decltype(UniformRNG::seed)>(py::handle(seed));
  15832. } CATCH_ALL(-1)
  15833. }
  15834. if (dtype) {
  15835. try {
  15836. // TODO: remove this guard which is used for pybind11 implicit conversion
  15837. py::detail::loader_life_support guard{};
  15838. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().dtype =
  15839. py::cast<decltype(UniformRNG::dtype)>(py::handle(dtype));
  15840. } CATCH_ALL(-1)
  15841. }
  15842. if (handle) {
  15843. try {
  15844. // TODO: remove this guard which is used for pybind11 implicit conversion
  15845. py::detail::loader_life_support guard{};
  15846. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().handle =
  15847. py::cast<decltype(UniformRNG::handle)>(py::handle(handle));
  15848. } CATCH_ALL(-1)
  15849. }
  15850. if (scope) {
  15851. try {
  15852. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15853. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15854. } CATCH_ALL(-1)
  15855. }
  15856. return 0;
  15857. }
  15858. PyGetSetDef PyOp(UniformRNG)::py_getsetters[] = {
  15859. {const_cast<char*>("seed"), py_get_generic(UniformRNG, seed), py_set_generic(UniformRNG, seed), const_cast<char*>("seed"), NULL},
  15860. {const_cast<char*>("dtype"), py_get_generic(UniformRNG, dtype), py_set_generic(UniformRNG, dtype), const_cast<char*>("dtype"), NULL},
  15861. {const_cast<char*>("handle"), py_get_generic(UniformRNG, handle), py_set_generic(UniformRNG, handle), const_cast<char*>("handle"), NULL},
  15862. {NULL} /* Sentinel */
  15863. };
  15864. PyMethodDef PyOp(UniformRNG)::tp_methods[] = {
  15865. {const_cast<char*>("__getstate__"), PyOp(UniformRNG)::getstate, METH_NOARGS, "UniformRNG getstate"},
  15866. {const_cast<char*>("__setstate__"), PyOp(UniformRNG)::setstate, METH_VARARGS, "UniformRNG setstate"},
  15867. {NULL} /* Sentinel */
  15868. };
  15869. void _init_py_UniformRNG(py::module m) {
  15870. using py_op = PyOp(UniformRNG);
  15871. auto& py_type = PyOpType(UniformRNG);
  15872. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15873. py_type.tp_name = "megengine.core._imperative_rt.ops.UniformRNG";
  15874. py_type.tp_basicsize = sizeof(PyOp(UniformRNG));
  15875. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15876. py_type.tp_doc = "UniformRNG";
  15877. py_type.tp_base = &PyOpType(OpDef);
  15878. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15879. py_type.tp_new = py_new_generic<py_op>;
  15880. py_type.tp_init = py_op::py_init;
  15881. py_type.tp_methods = py_op::tp_methods;
  15882. py_type.tp_getset = py_op::py_getsetters;
  15883. mgb_assert(PyType_Ready(&py_type) >= 0);
  15884. PyType_Modified(&py_type);
  15885. m.add_object("UniformRNG", reinterpret_cast<PyObject*>(&py_type));
  15886. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(UniformRNG::typeinfo(), &py_type).second);
  15887. }
  15888. void _init_py_WarpAffine_InterpolationMode(PyTypeObject& py_type) {
  15889. auto& e_type = EnumWrapper<WarpAffine::InterpolationMode>::type;
  15890. Py_INCREF(e_type);
  15891. mgb_assert(PyDict_SetItemString(
  15892. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15893. }
  15894. void _init_py_WarpAffine_BorderMode(PyTypeObject& py_type) {
  15895. auto& e_type = EnumWrapper<WarpAffine::BorderMode>::type;
  15896. Py_INCREF(e_type);
  15897. mgb_assert(PyDict_SetItemString(
  15898. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15899. }
  15900. void _init_py_WarpAffine_Format(PyTypeObject& py_type) {
  15901. auto& e_type = EnumWrapper<WarpAffine::Format>::type;
  15902. Py_INCREF(e_type);
  15903. mgb_assert(PyDict_SetItemString(
  15904. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  15905. }
  15906. PyOpDefBegin(WarpAffine) // {
  15907. static PyGetSetDef py_getsetters[];
  15908. static PyMethodDef tp_methods[];
  15909. static PyObject* getstate(PyObject* self, PyObject*) {
  15910. auto& opdef = reinterpret_cast<PyOp(WarpAffine)*>(self)->inst();
  15911. static_cast<void>(opdef);
  15912. std::unordered_map<std::string, py::object> state {
  15913. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  15914. {"border_mode", serialization<decltype(opdef.border_mode)>::dump(opdef.border_mode)},
  15915. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)},
  15916. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  15917. };
  15918. return py::cast(state).release().ptr();
  15919. }
  15920. static PyObject* setstate(PyObject* self, PyObject* args) {
  15921. PyObject* dict = PyTuple_GetItem(args, 0);
  15922. if (!dict) return NULL;
  15923. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15924. auto& opdef = reinterpret_cast<PyOp(WarpAffine)*>(self)->inst();
  15925. static_cast<void>(opdef);
  15926. {
  15927. auto&& iter = state.find("imode");
  15928. if (iter != state.end()) {
  15929. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  15930. }
  15931. }
  15932. {
  15933. auto&& iter = state.find("border_mode");
  15934. if (iter != state.end()) {
  15935. opdef.border_mode = serialization<decltype(opdef.border_mode)>::load(iter->second);
  15936. }
  15937. }
  15938. {
  15939. auto&& iter = state.find("border_val");
  15940. if (iter != state.end()) {
  15941. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  15942. }
  15943. }
  15944. {
  15945. auto&& iter = state.find("format");
  15946. if (iter != state.end()) {
  15947. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  15948. }
  15949. }
  15950. Py_RETURN_NONE;
  15951. }
  15952. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15953. // };
  15954. PyOpDefEnd(WarpAffine)
  15955. int PyOp(WarpAffine)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15956. static const char* kwlist[] = {"imode", "border_mode", "border_val", "format", "scope", NULL};
  15957. PyObject *imode = NULL, *border_mode = NULL, *border_val = NULL, *format = NULL, *scope = NULL;
  15958. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &border_mode, &border_val, &format, &scope))
  15959. return -1;
  15960. if (imode) {
  15961. try {
  15962. // TODO: remove this guard which is used for pybind11 implicit conversion
  15963. py::detail::loader_life_support guard{};
  15964. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().imode =
  15965. py::cast<decltype(WarpAffine::imode)>(py::handle(imode));
  15966. } CATCH_ALL(-1)
  15967. }
  15968. if (border_mode) {
  15969. try {
  15970. // TODO: remove this guard which is used for pybind11 implicit conversion
  15971. py::detail::loader_life_support guard{};
  15972. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().border_mode =
  15973. py::cast<decltype(WarpAffine::border_mode)>(py::handle(border_mode));
  15974. } CATCH_ALL(-1)
  15975. }
  15976. if (border_val) {
  15977. try {
  15978. // TODO: remove this guard which is used for pybind11 implicit conversion
  15979. py::detail::loader_life_support guard{};
  15980. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().border_val =
  15981. py::cast<decltype(WarpAffine::border_val)>(py::handle(border_val));
  15982. } CATCH_ALL(-1)
  15983. }
  15984. if (format) {
  15985. try {
  15986. // TODO: remove this guard which is used for pybind11 implicit conversion
  15987. py::detail::loader_life_support guard{};
  15988. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().format =
  15989. py::cast<decltype(WarpAffine::format)>(py::handle(format));
  15990. } CATCH_ALL(-1)
  15991. }
  15992. if (scope) {
  15993. try {
  15994. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15995. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15996. } CATCH_ALL(-1)
  15997. }
  15998. return 0;
  15999. }
  16000. PyGetSetDef PyOp(WarpAffine)::py_getsetters[] = {
  16001. {const_cast<char*>("imode"), py_get_generic(WarpAffine, imode), py_set_generic(WarpAffine, imode), const_cast<char*>("imode"), NULL},
  16002. {const_cast<char*>("border_mode"), py_get_generic(WarpAffine, border_mode), py_set_generic(WarpAffine, border_mode), const_cast<char*>("border_mode"), NULL},
  16003. {const_cast<char*>("border_val"), py_get_generic(WarpAffine, border_val), py_set_generic(WarpAffine, border_val), const_cast<char*>("border_val"), NULL},
  16004. {const_cast<char*>("format"), py_get_generic(WarpAffine, format), py_set_generic(WarpAffine, format), const_cast<char*>("format"), NULL},
  16005. {NULL} /* Sentinel */
  16006. };
  16007. PyMethodDef PyOp(WarpAffine)::tp_methods[] = {
  16008. {const_cast<char*>("__getstate__"), PyOp(WarpAffine)::getstate, METH_NOARGS, "WarpAffine getstate"},
  16009. {const_cast<char*>("__setstate__"), PyOp(WarpAffine)::setstate, METH_VARARGS, "WarpAffine setstate"},
  16010. {NULL} /* Sentinel */
  16011. };
  16012. void _init_py_WarpAffine(py::module m) {
  16013. using py_op = PyOp(WarpAffine);
  16014. auto& py_type = PyOpType(WarpAffine);
  16015. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16016. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpAffine";
  16017. py_type.tp_basicsize = sizeof(PyOp(WarpAffine));
  16018. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16019. py_type.tp_doc = "WarpAffine";
  16020. py_type.tp_base = &PyOpType(OpDef);
  16021. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16022. py_type.tp_new = py_new_generic<py_op>;
  16023. py_type.tp_init = py_op::py_init;
  16024. py_type.tp_methods = py_op::tp_methods;
  16025. py_type.tp_getset = py_op::py_getsetters;
  16026. mgb_assert(PyType_Ready(&py_type) >= 0);
  16027. _init_py_WarpAffine_InterpolationMode(py_type);
  16028. _init_py_WarpAffine_BorderMode(py_type);
  16029. _init_py_WarpAffine_Format(py_type);
  16030. PyType_Modified(&py_type);
  16031. m.add_object("WarpAffine", reinterpret_cast<PyObject*>(&py_type));
  16032. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpAffine::typeinfo(), &py_type).second);
  16033. }
  16034. void _init_py_WarpPerspective_InterpolationMode(PyTypeObject& py_type) {
  16035. auto& e_type = EnumWrapper<WarpPerspective::InterpolationMode>::type;
  16036. Py_INCREF(e_type);
  16037. mgb_assert(PyDict_SetItemString(
  16038. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16039. }
  16040. void _init_py_WarpPerspective_BorderMode(PyTypeObject& py_type) {
  16041. auto& e_type = EnumWrapper<WarpPerspective::BorderMode>::type;
  16042. Py_INCREF(e_type);
  16043. mgb_assert(PyDict_SetItemString(
  16044. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16045. }
  16046. void _init_py_WarpPerspective_Format(PyTypeObject& py_type) {
  16047. auto& e_type = EnumWrapper<WarpPerspective::Format>::type;
  16048. Py_INCREF(e_type);
  16049. mgb_assert(PyDict_SetItemString(
  16050. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16051. }
  16052. PyOpDefBegin(WarpPerspective) // {
  16053. static PyGetSetDef py_getsetters[];
  16054. static PyMethodDef tp_methods[];
  16055. static PyObject* getstate(PyObject* self, PyObject*) {
  16056. auto& opdef = reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst();
  16057. static_cast<void>(opdef);
  16058. std::unordered_map<std::string, py::object> state {
  16059. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  16060. {"bmode", serialization<decltype(opdef.bmode)>::dump(opdef.bmode)},
  16061. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  16062. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)}
  16063. };
  16064. return py::cast(state).release().ptr();
  16065. }
  16066. static PyObject* setstate(PyObject* self, PyObject* args) {
  16067. PyObject* dict = PyTuple_GetItem(args, 0);
  16068. if (!dict) return NULL;
  16069. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16070. auto& opdef = reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst();
  16071. static_cast<void>(opdef);
  16072. {
  16073. auto&& iter = state.find("imode");
  16074. if (iter != state.end()) {
  16075. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  16076. }
  16077. }
  16078. {
  16079. auto&& iter = state.find("bmode");
  16080. if (iter != state.end()) {
  16081. opdef.bmode = serialization<decltype(opdef.bmode)>::load(iter->second);
  16082. }
  16083. }
  16084. {
  16085. auto&& iter = state.find("format");
  16086. if (iter != state.end()) {
  16087. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  16088. }
  16089. }
  16090. {
  16091. auto&& iter = state.find("border_val");
  16092. if (iter != state.end()) {
  16093. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  16094. }
  16095. }
  16096. Py_RETURN_NONE;
  16097. }
  16098. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16099. // };
  16100. PyOpDefEnd(WarpPerspective)
  16101. int PyOp(WarpPerspective)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16102. static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL};
  16103. PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL;
  16104. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &bmode, &format, &border_val, &scope))
  16105. return -1;
  16106. if (imode) {
  16107. try {
  16108. // TODO: remove this guard which is used for pybind11 implicit conversion
  16109. py::detail::loader_life_support guard{};
  16110. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().imode =
  16111. py::cast<decltype(WarpPerspective::imode)>(py::handle(imode));
  16112. } CATCH_ALL(-1)
  16113. }
  16114. if (bmode) {
  16115. try {
  16116. // TODO: remove this guard which is used for pybind11 implicit conversion
  16117. py::detail::loader_life_support guard{};
  16118. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().bmode =
  16119. py::cast<decltype(WarpPerspective::bmode)>(py::handle(bmode));
  16120. } CATCH_ALL(-1)
  16121. }
  16122. if (format) {
  16123. try {
  16124. // TODO: remove this guard which is used for pybind11 implicit conversion
  16125. py::detail::loader_life_support guard{};
  16126. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().format =
  16127. py::cast<decltype(WarpPerspective::format)>(py::handle(format));
  16128. } CATCH_ALL(-1)
  16129. }
  16130. if (border_val) {
  16131. try {
  16132. // TODO: remove this guard which is used for pybind11 implicit conversion
  16133. py::detail::loader_life_support guard{};
  16134. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().border_val =
  16135. py::cast<decltype(WarpPerspective::border_val)>(py::handle(border_val));
  16136. } CATCH_ALL(-1)
  16137. }
  16138. if (scope) {
  16139. try {
  16140. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16141. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16142. } CATCH_ALL(-1)
  16143. }
  16144. return 0;
  16145. }
  16146. PyGetSetDef PyOp(WarpPerspective)::py_getsetters[] = {
  16147. {const_cast<char*>("imode"), py_get_generic(WarpPerspective, imode), py_set_generic(WarpPerspective, imode), const_cast<char*>("imode"), NULL},
  16148. {const_cast<char*>("bmode"), py_get_generic(WarpPerspective, bmode), py_set_generic(WarpPerspective, bmode), const_cast<char*>("bmode"), NULL},
  16149. {const_cast<char*>("format"), py_get_generic(WarpPerspective, format), py_set_generic(WarpPerspective, format), const_cast<char*>("format"), NULL},
  16150. {const_cast<char*>("border_val"), py_get_generic(WarpPerspective, border_val), py_set_generic(WarpPerspective, border_val), const_cast<char*>("border_val"), NULL},
  16151. {NULL} /* Sentinel */
  16152. };
  16153. PyMethodDef PyOp(WarpPerspective)::tp_methods[] = {
  16154. {const_cast<char*>("__getstate__"), PyOp(WarpPerspective)::getstate, METH_NOARGS, "WarpPerspective getstate"},
  16155. {const_cast<char*>("__setstate__"), PyOp(WarpPerspective)::setstate, METH_VARARGS, "WarpPerspective setstate"},
  16156. {NULL} /* Sentinel */
  16157. };
  16158. void _init_py_WarpPerspective(py::module m) {
  16159. using py_op = PyOp(WarpPerspective);
  16160. auto& py_type = PyOpType(WarpPerspective);
  16161. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16162. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspective";
  16163. py_type.tp_basicsize = sizeof(PyOp(WarpPerspective));
  16164. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16165. py_type.tp_doc = "WarpPerspective";
  16166. py_type.tp_base = &PyOpType(OpDef);
  16167. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16168. py_type.tp_new = py_new_generic<py_op>;
  16169. py_type.tp_init = py_op::py_init;
  16170. py_type.tp_methods = py_op::tp_methods;
  16171. py_type.tp_getset = py_op::py_getsetters;
  16172. mgb_assert(PyType_Ready(&py_type) >= 0);
  16173. _init_py_WarpPerspective_InterpolationMode(py_type);
  16174. _init_py_WarpPerspective_BorderMode(py_type);
  16175. _init_py_WarpPerspective_Format(py_type);
  16176. PyType_Modified(&py_type);
  16177. m.add_object("WarpPerspective", reinterpret_cast<PyObject*>(&py_type));
  16178. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspective::typeinfo(), &py_type).second);
  16179. }
  16180. #define INIT_ALL_OP(m) \
  16181. _init_py_AdaptivePooling(m); \
  16182. _init_py_AddAxis(m); \
  16183. _init_py_Argmax(m); \
  16184. _init_py_Argmin(m); \
  16185. _init_py_Argsort(m); \
  16186. _init_py_AssertEqual(m); \
  16187. _init_py_AtlasRuntime(m); \
  16188. _init_py_Barrier(m); \
  16189. _init_py_BatchConvBias(m); \
  16190. _init_py_BatchNorm(m); \
  16191. _init_py_BatchNormBackward(m); \
  16192. _init_py_BatchedIncrMeshIndexing(m); \
  16193. _init_py_BatchedMatrixMul(m); \
  16194. _init_py_BatchedMeshIndexing(m); \
  16195. _init_py_BatchedSetMeshIndexing(m); \
  16196. _init_py_BetaRNG(m); \
  16197. _init_py_Borrow(m); \
  16198. _init_py_Broadcast(m); \
  16199. _init_py_CambriconRuntime(m); \
  16200. _init_py_CheckNonFinite(m); \
  16201. _init_py_CollectiveComm(m); \
  16202. _init_py_Concat(m); \
  16203. _init_py_CondTake(m); \
  16204. _init_py_ConvBias(m); \
  16205. _init_py_Convolution(m); \
  16206. _init_py_Convolution3D(m); \
  16207. _init_py_Convolution3DBackwardData(m); \
  16208. _init_py_ConvolutionBackwardData(m); \
  16209. _init_py_Copy(m); \
  16210. _init_py_Correlation(m); \
  16211. _init_py_Cumprod(m); \
  16212. _init_py_Cumsum(m); \
  16213. _init_py_CvtColor(m); \
  16214. _init_py_DeformableConv(m); \
  16215. _init_py_DeformablePSROIPooling(m); \
  16216. _init_py_Diag(m); \
  16217. _init_py_Dimshuffle(m); \
  16218. _init_py_Dot(m); \
  16219. _init_py_Dropout(m); \
  16220. _init_py_Elemwise(m); \
  16221. _init_py_ElemwiseMultiType(m); \
  16222. _init_py_ExternOpr(m); \
  16223. _init_py_Eye(m); \
  16224. _init_py_FakeQuant(m); \
  16225. _init_py_FastpathCopy(m); \
  16226. _init_py_GammaRNG(m); \
  16227. _init_py_GaussianRNG(m); \
  16228. _init_py_GetVarShape(m); \
  16229. _init_py_GroupLocal(m); \
  16230. _init_py_Identity(m); \
  16231. _init_py_Images2Neibs(m); \
  16232. _init_py_IncrMeshIndexing(m); \
  16233. _init_py_IncrSubtensor(m); \
  16234. _init_py_IndexingIncrMultiAxisVec(m); \
  16235. _init_py_IndexingMultiAxisVec(m); \
  16236. _init_py_IndexingOneHot(m); \
  16237. _init_py_IndexingSetMultiAxisVec(m); \
  16238. _init_py_IndexingSetOneHot(m); \
  16239. _init_py_InplaceAdd(m); \
  16240. _init_py_LAMBUpdate(m); \
  16241. _init_py_LRN(m); \
  16242. _init_py_LSQ(m); \
  16243. _init_py_LSTM(m); \
  16244. _init_py_LSTMCell(m); \
  16245. _init_py_LayerNorm(m); \
  16246. _init_py_Linspace(m); \
  16247. _init_py_MagicMindRuntime(m); \
  16248. _init_py_MatrixInverse(m); \
  16249. _init_py_MatrixMul(m); \
  16250. _init_py_MeshIndexing(m); \
  16251. _init_py_NMSKeep(m); \
  16252. _init_py_NvOf(m); \
  16253. _init_py_Padding(m); \
  16254. _init_py_ParamPackConcat(m); \
  16255. _init_py_ParamPackSplit(m); \
  16256. _init_py_PermutationRNG(m); \
  16257. _init_py_PixelShuffle(m); \
  16258. _init_py_PixelShuffleBackward(m); \
  16259. _init_py_PoissonRNG(m); \
  16260. _init_py_Pooling(m); \
  16261. _init_py_RNN(m); \
  16262. _init_py_RNNCell(m); \
  16263. _init_py_ROIAlign(m); \
  16264. _init_py_ROIPooling(m); \
  16265. _init_py_Reduce(m); \
  16266. _init_py_Remap(m); \
  16267. _init_py_RemoteRecv(m); \
  16268. _init_py_RemoteSend(m); \
  16269. _init_py_RemoveAxis(m); \
  16270. _init_py_Reshape(m); \
  16271. _init_py_Resize(m); \
  16272. _init_py_SVD(m); \
  16273. _init_py_SetMeshIndexing(m); \
  16274. _init_py_SetSubtensor(m); \
  16275. _init_py_ShuffleRNG(m); \
  16276. _init_py_SlidingWindowTranspose(m); \
  16277. _init_py_Softmax(m); \
  16278. _init_py_Split(m); \
  16279. _init_py_Subtensor(m); \
  16280. _init_py_TQT(m); \
  16281. _init_py_TensorRTRuntime(m); \
  16282. _init_py_TopK(m); \
  16283. _init_py_TypeCvt(m); \
  16284. _init_py_UniformRNG(m); \
  16285. _init_py_WarpAffine(m); \
  16286. _init_py_WarpPerspective(m);
  16287. // clang-format on