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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455
  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(Cumsum) // {
  5845. static PyGetSetDef py_getsetters[];
  5846. static PyMethodDef tp_methods[];
  5847. static PyObject* getstate(PyObject* self, PyObject*) {
  5848. auto& opdef = reinterpret_cast<PyOp(Cumsum)*>(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(Cumsum)*>(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(Cumsum)
  5886. int PyOp(Cumsum)::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(Cumsum)*>(self)->inst().axis =
  5896. py::cast<decltype(Cumsum::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(Cumsum)*>(self)->inst().exclusive =
  5904. py::cast<decltype(Cumsum::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(Cumsum)*>(self)->inst().reverse =
  5912. py::cast<decltype(Cumsum::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(Cumsum)::py_getsetters[] = {
  5924. {const_cast<char*>("axis"), py_get_generic(Cumsum, axis), py_set_generic(Cumsum, axis), const_cast<char*>("axis"), NULL},
  5925. {const_cast<char*>("exclusive"), py_get_generic(Cumsum, exclusive), py_set_generic(Cumsum, exclusive), const_cast<char*>("exclusive"), NULL},
  5926. {const_cast<char*>("reverse"), py_get_generic(Cumsum, reverse), py_set_generic(Cumsum, reverse), const_cast<char*>("reverse"), NULL},
  5927. {NULL} /* Sentinel */
  5928. };
  5929. PyMethodDef PyOp(Cumsum)::tp_methods[] = {
  5930. {const_cast<char*>("__getstate__"), PyOp(Cumsum)::getstate, METH_NOARGS, "Cumsum getstate"},
  5931. {const_cast<char*>("__setstate__"), PyOp(Cumsum)::setstate, METH_VARARGS, "Cumsum setstate"},
  5932. {NULL} /* Sentinel */
  5933. };
  5934. void _init_py_Cumsum(py::module m) {
  5935. using py_op = PyOp(Cumsum);
  5936. auto& py_type = PyOpType(Cumsum);
  5937. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  5938. py_type.tp_name = "megengine.core._imperative_rt.ops.Cumsum";
  5939. py_type.tp_basicsize = sizeof(PyOp(Cumsum));
  5940. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  5941. py_type.tp_doc = "Cumsum";
  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("Cumsum", reinterpret_cast<PyObject*>(&py_type));
  5951. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Cumsum::typeinfo(), &py_type).second);
  5952. }
  5953. template<> struct EnumTrait<CvtColor::Mode> {
  5954. static constexpr const char *name = "CvtColor.Mode";
  5955. static constexpr std::underlying_type_t<CvtColor::Mode> max = 32 - 1;
  5956. };
  5957. template<> PyTypeObject* EnumWrapper<CvtColor::Mode>::type = nullptr;
  5958. template<> const char*
  5959. 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"};
  5960. template<> std::unordered_map<std::string, CvtColor::Mode>
  5961. 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}};
  5962. template<> PyObject* EnumWrapper<CvtColor::Mode>::pyobj_insts[32] = {nullptr};
  5963. void _init_py_CvtColor_Mode(PyTypeObject& py_type) {
  5964. auto& e_type = EnumWrapper<CvtColor::Mode>::type;
  5965. static PyMethodDef tp_methods[] = {
  5966. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<CvtColor::Mode>::py_dump, METH_NOARGS, NULL},
  5967. {NULL} /* Sentinel */
  5968. };
  5969. static PyType_Slot slots[] = {
  5970. {Py_tp_repr, (void*)EnumWrapper<CvtColor::Mode>::py_repr},
  5971. {Py_tp_richcompare, (void*)EnumWrapper<CvtColor::Mode>::tp_richcompare},
  5972. {Py_tp_methods, tp_methods},
  5973. {0, NULL}
  5974. };
  5975. static PyType_Spec spec = {
  5976. // name
  5977. "megengine.core._imperative_rt.ops.CvtColor.Mode",
  5978. // basicsize
  5979. sizeof(EnumWrapper<CvtColor::Mode>),
  5980. // itemsize
  5981. 0,
  5982. // flags
  5983. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  5984. // slots
  5985. slots
  5986. };
  5987. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  5988. mgb_assert(
  5989. e_type->tp_setattro(
  5990. reinterpret_cast<PyObject*>(e_type),
  5991. py::cast("__name__").release().ptr(),
  5992. py::cast("Mode").release().ptr()) >= 0);
  5993. mgb_assert(
  5994. e_type->tp_setattro(
  5995. reinterpret_cast<PyObject*>(e_type),
  5996. py::cast("__module__").release().ptr(),
  5997. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  5998. mgb_assert(
  5999. e_type->tp_setattro(
  6000. reinterpret_cast<PyObject*>(e_type),
  6001. py::cast("__qualname__").release().ptr(),
  6002. py::cast("CvtColor.Mode").release().ptr()) >= 0);
  6003. {
  6004. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6005. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2GRAY;
  6006. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2GRAY", inst) >= 0);
  6007. EnumWrapper<CvtColor::Mode>::pyobj_insts[0] = inst;
  6008. }{
  6009. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6010. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2YUV;
  6011. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2YUV", inst) >= 0);
  6012. EnumWrapper<CvtColor::Mode>::pyobj_insts[1] = inst;
  6013. }{
  6014. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6015. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB;
  6016. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB", inst) >= 0);
  6017. EnumWrapper<CvtColor::Mode>::pyobj_insts[2] = inst;
  6018. }{
  6019. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6020. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::GRAY2RGB;
  6021. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GRAY2RGB", inst) >= 0);
  6022. EnumWrapper<CvtColor::Mode>::pyobj_insts[3] = inst;
  6023. }{
  6024. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6025. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2RGB;
  6026. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2RGB", inst) >= 0);
  6027. EnumWrapper<CvtColor::Mode>::pyobj_insts[4] = inst;
  6028. }{
  6029. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6030. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2BGR;
  6031. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2BGR", inst) >= 0);
  6032. EnumWrapper<CvtColor::Mode>::pyobj_insts[5] = inst;
  6033. }{
  6034. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6035. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGBA2GRAY;
  6036. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2GRAY", inst) >= 0);
  6037. EnumWrapper<CvtColor::Mode>::pyobj_insts[6] = inst;
  6038. }{
  6039. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6040. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::RGB2BGR;
  6041. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2BGR", inst) >= 0);
  6042. EnumWrapper<CvtColor::Mode>::pyobj_insts[7] = inst;
  6043. }{
  6044. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6045. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BGR2GRAY;
  6046. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2GRAY", inst) >= 0);
  6047. EnumWrapper<CvtColor::Mode>::pyobj_insts[8] = inst;
  6048. }{
  6049. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6050. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BGR2RGB;
  6051. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2RGB", inst) >= 0);
  6052. EnumWrapper<CvtColor::Mode>::pyobj_insts[9] = inst;
  6053. }{
  6054. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6055. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV21;
  6056. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV21", inst) >= 0);
  6057. EnumWrapper<CvtColor::Mode>::pyobj_insts[10] = inst;
  6058. }{
  6059. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6060. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_NV21;
  6061. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV21", inst) >= 0);
  6062. EnumWrapper<CvtColor::Mode>::pyobj_insts[11] = inst;
  6063. }{
  6064. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6065. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_NV21;
  6066. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV21", inst) >= 0);
  6067. EnumWrapper<CvtColor::Mode>::pyobj_insts[12] = inst;
  6068. }{
  6069. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6070. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV12;
  6071. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV12", inst) >= 0);
  6072. EnumWrapper<CvtColor::Mode>::pyobj_insts[13] = inst;
  6073. }{
  6074. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6075. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_NV12;
  6076. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV12", inst) >= 0);
  6077. EnumWrapper<CvtColor::Mode>::pyobj_insts[14] = inst;
  6078. }{
  6079. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6080. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_NV12;
  6081. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV12", inst) >= 0);
  6082. EnumWrapper<CvtColor::Mode>::pyobj_insts[15] = inst;
  6083. }{
  6084. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6085. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_YV12;
  6086. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YV12", inst) >= 0);
  6087. EnumWrapper<CvtColor::Mode>::pyobj_insts[16] = inst;
  6088. }{
  6089. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6090. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_YV12;
  6091. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YV12", inst) >= 0);
  6092. EnumWrapper<CvtColor::Mode>::pyobj_insts[17] = inst;
  6093. }{
  6094. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6095. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_YV12;
  6096. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YV12", inst) >= 0);
  6097. EnumWrapper<CvtColor::Mode>::pyobj_insts[18] = inst;
  6098. }{
  6099. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6100. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2GRAY_YU12;
  6101. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YU12", inst) >= 0);
  6102. EnumWrapper<CvtColor::Mode>::pyobj_insts[19] = inst;
  6103. }{
  6104. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6105. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2RGB_YU12;
  6106. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YU12", inst) >= 0);
  6107. EnumWrapper<CvtColor::Mode>::pyobj_insts[20] = inst;
  6108. }{
  6109. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6110. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YUV2BGR_YU12;
  6111. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YU12", inst) >= 0);
  6112. EnumWrapper<CvtColor::Mode>::pyobj_insts[21] = inst;
  6113. }{
  6114. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6115. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YCrCb2RGB;
  6116. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2RGB", inst) >= 0);
  6117. EnumWrapper<CvtColor::Mode>::pyobj_insts[22] = inst;
  6118. }{
  6119. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6120. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::YCrCb2BGR;
  6121. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2BGR", inst) >= 0);
  6122. EnumWrapper<CvtColor::Mode>::pyobj_insts[23] = inst;
  6123. }{
  6124. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6125. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV21;
  6126. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV21", inst) >= 0);
  6127. EnumWrapper<CvtColor::Mode>::pyobj_insts[24] = inst;
  6128. }{
  6129. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6130. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV21;
  6131. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV21", inst) >= 0);
  6132. EnumWrapper<CvtColor::Mode>::pyobj_insts[25] = inst;
  6133. }{
  6134. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6135. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV12;
  6136. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV12", inst) >= 0);
  6137. EnumWrapper<CvtColor::Mode>::pyobj_insts[26] = inst;
  6138. }{
  6139. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6140. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV12;
  6141. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV12", inst) >= 0);
  6142. EnumWrapper<CvtColor::Mode>::pyobj_insts[27] = inst;
  6143. }{
  6144. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6145. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YV12;
  6146. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YV12", inst) >= 0);
  6147. EnumWrapper<CvtColor::Mode>::pyobj_insts[28] = inst;
  6148. }{
  6149. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6150. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YV12;
  6151. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YV12", inst) >= 0);
  6152. EnumWrapper<CvtColor::Mode>::pyobj_insts[29] = inst;
  6153. }{
  6154. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6155. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YU12;
  6156. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YU12", inst) >= 0);
  6157. EnumWrapper<CvtColor::Mode>::pyobj_insts[30] = inst;
  6158. }{
  6159. PyObject* inst = e_type->tp_alloc(e_type, 0);
  6160. reinterpret_cast<EnumWrapper<CvtColor::Mode>*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YU12;
  6161. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YU12", inst) >= 0);
  6162. EnumWrapper<CvtColor::Mode>::pyobj_insts[31] = inst;
  6163. }
  6164. Py_INCREF(e_type);
  6165. mgb_assert(PyDict_SetItemString(
  6166. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6167. }
  6168. PyOpDefBegin(CvtColor) // {
  6169. static PyGetSetDef py_getsetters[];
  6170. static PyMethodDef tp_methods[];
  6171. static PyObject* getstate(PyObject* self, PyObject*) {
  6172. auto& opdef = reinterpret_cast<PyOp(CvtColor)*>(self)->inst();
  6173. static_cast<void>(opdef);
  6174. std::unordered_map<std::string, py::object> state {
  6175. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  6176. };
  6177. return py::cast(state).release().ptr();
  6178. }
  6179. static PyObject* setstate(PyObject* self, PyObject* args) {
  6180. PyObject* dict = PyTuple_GetItem(args, 0);
  6181. if (!dict) return NULL;
  6182. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6183. auto& opdef = reinterpret_cast<PyOp(CvtColor)*>(self)->inst();
  6184. static_cast<void>(opdef);
  6185. {
  6186. auto&& iter = state.find("mode");
  6187. if (iter != state.end()) {
  6188. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  6189. }
  6190. }
  6191. Py_RETURN_NONE;
  6192. }
  6193. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6194. // };
  6195. PyOpDefEnd(CvtColor)
  6196. int PyOp(CvtColor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6197. static const char* kwlist[] = {"mode", "scope", NULL};
  6198. PyObject *mode = NULL, *scope = NULL;
  6199. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  6200. return -1;
  6201. if (mode) {
  6202. try {
  6203. // TODO: remove this guard which is used for pybind11 implicit conversion
  6204. py::detail::loader_life_support guard{};
  6205. reinterpret_cast<PyOp(CvtColor)*>(self)->inst().mode =
  6206. py::cast<decltype(CvtColor::mode)>(py::handle(mode));
  6207. } CATCH_ALL(-1)
  6208. }
  6209. if (scope) {
  6210. try {
  6211. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6212. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6213. } CATCH_ALL(-1)
  6214. }
  6215. return 0;
  6216. }
  6217. PyGetSetDef PyOp(CvtColor)::py_getsetters[] = {
  6218. {const_cast<char*>("mode"), py_get_generic(CvtColor, mode), py_set_generic(CvtColor, mode), const_cast<char*>("mode"), NULL},
  6219. {NULL} /* Sentinel */
  6220. };
  6221. PyMethodDef PyOp(CvtColor)::tp_methods[] = {
  6222. {const_cast<char*>("__getstate__"), PyOp(CvtColor)::getstate, METH_NOARGS, "CvtColor getstate"},
  6223. {const_cast<char*>("__setstate__"), PyOp(CvtColor)::setstate, METH_VARARGS, "CvtColor setstate"},
  6224. {NULL} /* Sentinel */
  6225. };
  6226. void _init_py_CvtColor(py::module m) {
  6227. using py_op = PyOp(CvtColor);
  6228. auto& py_type = PyOpType(CvtColor);
  6229. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6230. py_type.tp_name = "megengine.core._imperative_rt.ops.CvtColor";
  6231. py_type.tp_basicsize = sizeof(PyOp(CvtColor));
  6232. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6233. py_type.tp_doc = "CvtColor";
  6234. py_type.tp_base = &PyOpType(OpDef);
  6235. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6236. py_type.tp_new = py_new_generic<py_op>;
  6237. py_type.tp_init = py_op::py_init;
  6238. py_type.tp_methods = py_op::tp_methods;
  6239. py_type.tp_getset = py_op::py_getsetters;
  6240. mgb_assert(PyType_Ready(&py_type) >= 0);
  6241. _init_py_CvtColor_Mode(py_type);
  6242. PyType_Modified(&py_type);
  6243. m.add_object("CvtColor", reinterpret_cast<PyObject*>(&py_type));
  6244. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CvtColor::typeinfo(), &py_type).second);
  6245. }
  6246. void _init_py_DeformableConv_Mode(PyTypeObject& py_type) {
  6247. auto& e_type = EnumWrapper<DeformableConv::Mode>::type;
  6248. Py_INCREF(e_type);
  6249. mgb_assert(PyDict_SetItemString(
  6250. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6251. }
  6252. void _init_py_DeformableConv_Sparse(PyTypeObject& py_type) {
  6253. auto& e_type = EnumWrapper<DeformableConv::Sparse>::type;
  6254. Py_INCREF(e_type);
  6255. mgb_assert(PyDict_SetItemString(
  6256. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6257. }
  6258. void _init_py_DeformableConv_Format(PyTypeObject& py_type) {
  6259. auto& e_type = EnumWrapper<DeformableConv::Format>::type;
  6260. Py_INCREF(e_type);
  6261. mgb_assert(PyDict_SetItemString(
  6262. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6263. }
  6264. void _init_py_DeformableConv_ComputeMode(PyTypeObject& py_type) {
  6265. auto& e_type = EnumWrapper<DeformableConv::ComputeMode>::type;
  6266. Py_INCREF(e_type);
  6267. mgb_assert(PyDict_SetItemString(
  6268. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6269. }
  6270. void _init_py_DeformableConv_Strategy(PyTypeObject& py_type) {
  6271. auto& e_type = BitCombinedEnumWrapper<DeformableConv::Strategy>::type;
  6272. Py_INCREF(e_type);
  6273. mgb_assert(PyDict_SetItemString(
  6274. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  6275. }
  6276. PyOpDefBegin(DeformableConv) // {
  6277. static PyGetSetDef py_getsetters[];
  6278. static PyMethodDef tp_methods[];
  6279. static PyObject* getstate(PyObject* self, PyObject*) {
  6280. auto& opdef = reinterpret_cast<PyOp(DeformableConv)*>(self)->inst();
  6281. static_cast<void>(opdef);
  6282. std::unordered_map<std::string, py::object> state {
  6283. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  6284. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  6285. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  6286. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  6287. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  6288. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  6289. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  6290. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  6291. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  6292. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  6293. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  6294. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  6295. };
  6296. return py::cast(state).release().ptr();
  6297. }
  6298. static PyObject* setstate(PyObject* self, PyObject* args) {
  6299. PyObject* dict = PyTuple_GetItem(args, 0);
  6300. if (!dict) return NULL;
  6301. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6302. auto& opdef = reinterpret_cast<PyOp(DeformableConv)*>(self)->inst();
  6303. static_cast<void>(opdef);
  6304. {
  6305. auto&& iter = state.find("mode");
  6306. if (iter != state.end()) {
  6307. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  6308. }
  6309. }
  6310. {
  6311. auto&& iter = state.find("pad_h");
  6312. if (iter != state.end()) {
  6313. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  6314. }
  6315. }
  6316. {
  6317. auto&& iter = state.find("pad_w");
  6318. if (iter != state.end()) {
  6319. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  6320. }
  6321. }
  6322. {
  6323. auto&& iter = state.find("stride_h");
  6324. if (iter != state.end()) {
  6325. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  6326. }
  6327. }
  6328. {
  6329. auto&& iter = state.find("stride_w");
  6330. if (iter != state.end()) {
  6331. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  6332. }
  6333. }
  6334. {
  6335. auto&& iter = state.find("dilate_h");
  6336. if (iter != state.end()) {
  6337. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  6338. }
  6339. }
  6340. {
  6341. auto&& iter = state.find("dilate_w");
  6342. if (iter != state.end()) {
  6343. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  6344. }
  6345. }
  6346. {
  6347. auto&& iter = state.find("sparse");
  6348. if (iter != state.end()) {
  6349. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  6350. }
  6351. }
  6352. {
  6353. auto&& iter = state.find("format");
  6354. if (iter != state.end()) {
  6355. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  6356. }
  6357. }
  6358. {
  6359. auto&& iter = state.find("compute_mode");
  6360. if (iter != state.end()) {
  6361. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  6362. }
  6363. }
  6364. {
  6365. auto&& iter = state.find("strategy");
  6366. if (iter != state.end()) {
  6367. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  6368. }
  6369. }
  6370. {
  6371. auto&& iter = state.find("workspace_limit");
  6372. if (iter != state.end()) {
  6373. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  6374. }
  6375. }
  6376. Py_RETURN_NONE;
  6377. }
  6378. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6379. // };
  6380. PyOpDefEnd(DeformableConv)
  6381. int PyOp(DeformableConv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6382. 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};
  6383. 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;
  6384. 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))
  6385. return -1;
  6386. if (mode) {
  6387. try {
  6388. // TODO: remove this guard which is used for pybind11 implicit conversion
  6389. py::detail::loader_life_support guard{};
  6390. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().mode =
  6391. py::cast<decltype(DeformableConv::mode)>(py::handle(mode));
  6392. } CATCH_ALL(-1)
  6393. }
  6394. if (pad_h) {
  6395. try {
  6396. // TODO: remove this guard which is used for pybind11 implicit conversion
  6397. py::detail::loader_life_support guard{};
  6398. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().pad_h =
  6399. py::cast<decltype(DeformableConv::pad_h)>(py::handle(pad_h));
  6400. } CATCH_ALL(-1)
  6401. }
  6402. if (pad_w) {
  6403. try {
  6404. // TODO: remove this guard which is used for pybind11 implicit conversion
  6405. py::detail::loader_life_support guard{};
  6406. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().pad_w =
  6407. py::cast<decltype(DeformableConv::pad_w)>(py::handle(pad_w));
  6408. } CATCH_ALL(-1)
  6409. }
  6410. if (stride_h) {
  6411. try {
  6412. // TODO: remove this guard which is used for pybind11 implicit conversion
  6413. py::detail::loader_life_support guard{};
  6414. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().stride_h =
  6415. py::cast<decltype(DeformableConv::stride_h)>(py::handle(stride_h));
  6416. } CATCH_ALL(-1)
  6417. }
  6418. if (stride_w) {
  6419. try {
  6420. // TODO: remove this guard which is used for pybind11 implicit conversion
  6421. py::detail::loader_life_support guard{};
  6422. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().stride_w =
  6423. py::cast<decltype(DeformableConv::stride_w)>(py::handle(stride_w));
  6424. } CATCH_ALL(-1)
  6425. }
  6426. if (dilate_h) {
  6427. try {
  6428. // TODO: remove this guard which is used for pybind11 implicit conversion
  6429. py::detail::loader_life_support guard{};
  6430. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().dilate_h =
  6431. py::cast<decltype(DeformableConv::dilate_h)>(py::handle(dilate_h));
  6432. } CATCH_ALL(-1)
  6433. }
  6434. if (dilate_w) {
  6435. try {
  6436. // TODO: remove this guard which is used for pybind11 implicit conversion
  6437. py::detail::loader_life_support guard{};
  6438. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().dilate_w =
  6439. py::cast<decltype(DeformableConv::dilate_w)>(py::handle(dilate_w));
  6440. } CATCH_ALL(-1)
  6441. }
  6442. if (sparse) {
  6443. try {
  6444. // TODO: remove this guard which is used for pybind11 implicit conversion
  6445. py::detail::loader_life_support guard{};
  6446. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().sparse =
  6447. py::cast<decltype(DeformableConv::sparse)>(py::handle(sparse));
  6448. } CATCH_ALL(-1)
  6449. }
  6450. if (format) {
  6451. try {
  6452. // TODO: remove this guard which is used for pybind11 implicit conversion
  6453. py::detail::loader_life_support guard{};
  6454. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().format =
  6455. py::cast<decltype(DeformableConv::format)>(py::handle(format));
  6456. } CATCH_ALL(-1)
  6457. }
  6458. if (compute_mode) {
  6459. try {
  6460. // TODO: remove this guard which is used for pybind11 implicit conversion
  6461. py::detail::loader_life_support guard{};
  6462. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().compute_mode =
  6463. py::cast<decltype(DeformableConv::compute_mode)>(py::handle(compute_mode));
  6464. } CATCH_ALL(-1)
  6465. }
  6466. if (strategy) {
  6467. try {
  6468. // TODO: remove this guard which is used for pybind11 implicit conversion
  6469. py::detail::loader_life_support guard{};
  6470. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().strategy =
  6471. py::cast<decltype(DeformableConv::strategy)>(py::handle(strategy));
  6472. } CATCH_ALL(-1)
  6473. }
  6474. if (workspace_limit) {
  6475. try {
  6476. // TODO: remove this guard which is used for pybind11 implicit conversion
  6477. py::detail::loader_life_support guard{};
  6478. reinterpret_cast<PyOp(DeformableConv)*>(self)->inst().workspace_limit =
  6479. py::cast<decltype(DeformableConv::workspace_limit)>(py::handle(workspace_limit));
  6480. } CATCH_ALL(-1)
  6481. }
  6482. if (scope) {
  6483. try {
  6484. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6485. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6486. } CATCH_ALL(-1)
  6487. }
  6488. return 0;
  6489. }
  6490. PyGetSetDef PyOp(DeformableConv)::py_getsetters[] = {
  6491. {const_cast<char*>("mode"), py_get_generic(DeformableConv, mode), py_set_generic(DeformableConv, mode), const_cast<char*>("mode"), NULL},
  6492. {const_cast<char*>("pad_h"), py_get_generic(DeformableConv, pad_h), py_set_generic(DeformableConv, pad_h), const_cast<char*>("pad_h"), NULL},
  6493. {const_cast<char*>("pad_w"), py_get_generic(DeformableConv, pad_w), py_set_generic(DeformableConv, pad_w), const_cast<char*>("pad_w"), NULL},
  6494. {const_cast<char*>("stride_h"), py_get_generic(DeformableConv, stride_h), py_set_generic(DeformableConv, stride_h), const_cast<char*>("stride_h"), NULL},
  6495. {const_cast<char*>("stride_w"), py_get_generic(DeformableConv, stride_w), py_set_generic(DeformableConv, stride_w), const_cast<char*>("stride_w"), NULL},
  6496. {const_cast<char*>("dilate_h"), py_get_generic(DeformableConv, dilate_h), py_set_generic(DeformableConv, dilate_h), const_cast<char*>("dilate_h"), NULL},
  6497. {const_cast<char*>("dilate_w"), py_get_generic(DeformableConv, dilate_w), py_set_generic(DeformableConv, dilate_w), const_cast<char*>("dilate_w"), NULL},
  6498. {const_cast<char*>("sparse"), py_get_generic(DeformableConv, sparse), py_set_generic(DeformableConv, sparse), const_cast<char*>("sparse"), NULL},
  6499. {const_cast<char*>("format"), py_get_generic(DeformableConv, format), py_set_generic(DeformableConv, format), const_cast<char*>("format"), NULL},
  6500. {const_cast<char*>("compute_mode"), py_get_generic(DeformableConv, compute_mode), py_set_generic(DeformableConv, compute_mode), const_cast<char*>("compute_mode"), NULL},
  6501. {const_cast<char*>("strategy"), py_get_generic(DeformableConv, strategy), py_set_generic(DeformableConv, strategy), const_cast<char*>("strategy"), NULL},
  6502. {const_cast<char*>("workspace_limit"), py_get_generic(DeformableConv, workspace_limit), py_set_generic(DeformableConv, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  6503. {NULL} /* Sentinel */
  6504. };
  6505. PyMethodDef PyOp(DeformableConv)::tp_methods[] = {
  6506. {const_cast<char*>("__getstate__"), PyOp(DeformableConv)::getstate, METH_NOARGS, "DeformableConv getstate"},
  6507. {const_cast<char*>("__setstate__"), PyOp(DeformableConv)::setstate, METH_VARARGS, "DeformableConv setstate"},
  6508. {NULL} /* Sentinel */
  6509. };
  6510. void _init_py_DeformableConv(py::module m) {
  6511. using py_op = PyOp(DeformableConv);
  6512. auto& py_type = PyOpType(DeformableConv);
  6513. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6514. py_type.tp_name = "megengine.core._imperative_rt.ops.DeformableConv";
  6515. py_type.tp_basicsize = sizeof(PyOp(DeformableConv));
  6516. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6517. py_type.tp_doc = "DeformableConv";
  6518. py_type.tp_base = &PyOpType(OpDef);
  6519. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6520. py_type.tp_new = py_new_generic<py_op>;
  6521. py_type.tp_init = py_op::py_init;
  6522. py_type.tp_methods = py_op::tp_methods;
  6523. py_type.tp_getset = py_op::py_getsetters;
  6524. mgb_assert(PyType_Ready(&py_type) >= 0);
  6525. _init_py_DeformableConv_Mode(py_type);
  6526. _init_py_DeformableConv_Sparse(py_type);
  6527. _init_py_DeformableConv_Format(py_type);
  6528. _init_py_DeformableConv_ComputeMode(py_type);
  6529. _init_py_DeformableConv_Strategy(py_type);
  6530. PyType_Modified(&py_type);
  6531. m.add_object("DeformableConv", reinterpret_cast<PyObject*>(&py_type));
  6532. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformableConv::typeinfo(), &py_type).second);
  6533. }
  6534. PyOpDefBegin(DeformablePSROIPooling) // {
  6535. static PyGetSetDef py_getsetters[];
  6536. static PyMethodDef tp_methods[];
  6537. static PyObject* getstate(PyObject* self, PyObject*) {
  6538. auto& opdef = reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst();
  6539. static_cast<void>(opdef);
  6540. std::unordered_map<std::string, py::object> state {
  6541. {"no_trans", serialization<decltype(opdef.no_trans)>::dump(opdef.no_trans)},
  6542. {"spatial_scale", serialization<decltype(opdef.spatial_scale)>::dump(opdef.spatial_scale)},
  6543. {"trans_std", serialization<decltype(opdef.trans_std)>::dump(opdef.trans_std)},
  6544. {"pooled_h", serialization<decltype(opdef.pooled_h)>::dump(opdef.pooled_h)},
  6545. {"pooled_w", serialization<decltype(opdef.pooled_w)>::dump(opdef.pooled_w)},
  6546. {"part_size", serialization<decltype(opdef.part_size)>::dump(opdef.part_size)},
  6547. {"sample_per_part", serialization<decltype(opdef.sample_per_part)>::dump(opdef.sample_per_part)}
  6548. };
  6549. return py::cast(state).release().ptr();
  6550. }
  6551. static PyObject* setstate(PyObject* self, PyObject* args) {
  6552. PyObject* dict = PyTuple_GetItem(args, 0);
  6553. if (!dict) return NULL;
  6554. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6555. auto& opdef = reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst();
  6556. static_cast<void>(opdef);
  6557. {
  6558. auto&& iter = state.find("no_trans");
  6559. if (iter != state.end()) {
  6560. opdef.no_trans = serialization<decltype(opdef.no_trans)>::load(iter->second);
  6561. }
  6562. }
  6563. {
  6564. auto&& iter = state.find("spatial_scale");
  6565. if (iter != state.end()) {
  6566. opdef.spatial_scale = serialization<decltype(opdef.spatial_scale)>::load(iter->second);
  6567. }
  6568. }
  6569. {
  6570. auto&& iter = state.find("trans_std");
  6571. if (iter != state.end()) {
  6572. opdef.trans_std = serialization<decltype(opdef.trans_std)>::load(iter->second);
  6573. }
  6574. }
  6575. {
  6576. auto&& iter = state.find("pooled_h");
  6577. if (iter != state.end()) {
  6578. opdef.pooled_h = serialization<decltype(opdef.pooled_h)>::load(iter->second);
  6579. }
  6580. }
  6581. {
  6582. auto&& iter = state.find("pooled_w");
  6583. if (iter != state.end()) {
  6584. opdef.pooled_w = serialization<decltype(opdef.pooled_w)>::load(iter->second);
  6585. }
  6586. }
  6587. {
  6588. auto&& iter = state.find("part_size");
  6589. if (iter != state.end()) {
  6590. opdef.part_size = serialization<decltype(opdef.part_size)>::load(iter->second);
  6591. }
  6592. }
  6593. {
  6594. auto&& iter = state.find("sample_per_part");
  6595. if (iter != state.end()) {
  6596. opdef.sample_per_part = serialization<decltype(opdef.sample_per_part)>::load(iter->second);
  6597. }
  6598. }
  6599. Py_RETURN_NONE;
  6600. }
  6601. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6602. // };
  6603. PyOpDefEnd(DeformablePSROIPooling)
  6604. int PyOp(DeformablePSROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6605. static const char* kwlist[] = {"no_trans", "spatial_scale", "trans_std", "pooled_h", "pooled_w", "part_size", "sample_per_part", "scope", NULL};
  6606. 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;
  6607. 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))
  6608. return -1;
  6609. if (no_trans) {
  6610. try {
  6611. // TODO: remove this guard which is used for pybind11 implicit conversion
  6612. py::detail::loader_life_support guard{};
  6613. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().no_trans =
  6614. py::cast<decltype(DeformablePSROIPooling::no_trans)>(py::handle(no_trans));
  6615. } CATCH_ALL(-1)
  6616. }
  6617. if (spatial_scale) {
  6618. try {
  6619. // TODO: remove this guard which is used for pybind11 implicit conversion
  6620. py::detail::loader_life_support guard{};
  6621. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().spatial_scale =
  6622. py::cast<decltype(DeformablePSROIPooling::spatial_scale)>(py::handle(spatial_scale));
  6623. } CATCH_ALL(-1)
  6624. }
  6625. if (trans_std) {
  6626. try {
  6627. // TODO: remove this guard which is used for pybind11 implicit conversion
  6628. py::detail::loader_life_support guard{};
  6629. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().trans_std =
  6630. py::cast<decltype(DeformablePSROIPooling::trans_std)>(py::handle(trans_std));
  6631. } CATCH_ALL(-1)
  6632. }
  6633. if (pooled_h) {
  6634. try {
  6635. // TODO: remove this guard which is used for pybind11 implicit conversion
  6636. py::detail::loader_life_support guard{};
  6637. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().pooled_h =
  6638. py::cast<decltype(DeformablePSROIPooling::pooled_h)>(py::handle(pooled_h));
  6639. } CATCH_ALL(-1)
  6640. }
  6641. if (pooled_w) {
  6642. try {
  6643. // TODO: remove this guard which is used for pybind11 implicit conversion
  6644. py::detail::loader_life_support guard{};
  6645. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().pooled_w =
  6646. py::cast<decltype(DeformablePSROIPooling::pooled_w)>(py::handle(pooled_w));
  6647. } CATCH_ALL(-1)
  6648. }
  6649. if (part_size) {
  6650. try {
  6651. // TODO: remove this guard which is used for pybind11 implicit conversion
  6652. py::detail::loader_life_support guard{};
  6653. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().part_size =
  6654. py::cast<decltype(DeformablePSROIPooling::part_size)>(py::handle(part_size));
  6655. } CATCH_ALL(-1)
  6656. }
  6657. if (sample_per_part) {
  6658. try {
  6659. // TODO: remove this guard which is used for pybind11 implicit conversion
  6660. py::detail::loader_life_support guard{};
  6661. reinterpret_cast<PyOp(DeformablePSROIPooling)*>(self)->inst().sample_per_part =
  6662. py::cast<decltype(DeformablePSROIPooling::sample_per_part)>(py::handle(sample_per_part));
  6663. } CATCH_ALL(-1)
  6664. }
  6665. if (scope) {
  6666. try {
  6667. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6668. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6669. } CATCH_ALL(-1)
  6670. }
  6671. return 0;
  6672. }
  6673. PyGetSetDef PyOp(DeformablePSROIPooling)::py_getsetters[] = {
  6674. {const_cast<char*>("no_trans"), py_get_generic(DeformablePSROIPooling, no_trans), py_set_generic(DeformablePSROIPooling, no_trans), const_cast<char*>("no_trans"), NULL},
  6675. {const_cast<char*>("spatial_scale"), py_get_generic(DeformablePSROIPooling, spatial_scale), py_set_generic(DeformablePSROIPooling, spatial_scale), const_cast<char*>("spatial_scale"), NULL},
  6676. {const_cast<char*>("trans_std"), py_get_generic(DeformablePSROIPooling, trans_std), py_set_generic(DeformablePSROIPooling, trans_std), const_cast<char*>("trans_std"), NULL},
  6677. {const_cast<char*>("pooled_h"), py_get_generic(DeformablePSROIPooling, pooled_h), py_set_generic(DeformablePSROIPooling, pooled_h), const_cast<char*>("pooled_h"), NULL},
  6678. {const_cast<char*>("pooled_w"), py_get_generic(DeformablePSROIPooling, pooled_w), py_set_generic(DeformablePSROIPooling, pooled_w), const_cast<char*>("pooled_w"), NULL},
  6679. {const_cast<char*>("part_size"), py_get_generic(DeformablePSROIPooling, part_size), py_set_generic(DeformablePSROIPooling, part_size), const_cast<char*>("part_size"), NULL},
  6680. {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},
  6681. {NULL} /* Sentinel */
  6682. };
  6683. PyMethodDef PyOp(DeformablePSROIPooling)::tp_methods[] = {
  6684. {const_cast<char*>("__getstate__"), PyOp(DeformablePSROIPooling)::getstate, METH_NOARGS, "DeformablePSROIPooling getstate"},
  6685. {const_cast<char*>("__setstate__"), PyOp(DeformablePSROIPooling)::setstate, METH_VARARGS, "DeformablePSROIPooling setstate"},
  6686. {NULL} /* Sentinel */
  6687. };
  6688. void _init_py_DeformablePSROIPooling(py::module m) {
  6689. using py_op = PyOp(DeformablePSROIPooling);
  6690. auto& py_type = PyOpType(DeformablePSROIPooling);
  6691. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6692. py_type.tp_name = "megengine.core._imperative_rt.ops.DeformablePSROIPooling";
  6693. py_type.tp_basicsize = sizeof(PyOp(DeformablePSROIPooling));
  6694. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6695. py_type.tp_doc = "DeformablePSROIPooling";
  6696. py_type.tp_base = &PyOpType(OpDef);
  6697. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6698. py_type.tp_new = py_new_generic<py_op>;
  6699. py_type.tp_init = py_op::py_init;
  6700. py_type.tp_methods = py_op::tp_methods;
  6701. py_type.tp_getset = py_op::py_getsetters;
  6702. mgb_assert(PyType_Ready(&py_type) >= 0);
  6703. PyType_Modified(&py_type);
  6704. m.add_object("DeformablePSROIPooling", reinterpret_cast<PyObject*>(&py_type));
  6705. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformablePSROIPooling::typeinfo(), &py_type).second);
  6706. }
  6707. PyOpDefBegin(Diag) // {
  6708. static PyGetSetDef py_getsetters[];
  6709. static PyMethodDef tp_methods[];
  6710. static PyObject* getstate(PyObject* self, PyObject*) {
  6711. auto& opdef = reinterpret_cast<PyOp(Diag)*>(self)->inst();
  6712. static_cast<void>(opdef);
  6713. std::unordered_map<std::string, py::object> state {
  6714. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)}
  6715. };
  6716. return py::cast(state).release().ptr();
  6717. }
  6718. static PyObject* setstate(PyObject* self, PyObject* args) {
  6719. PyObject* dict = PyTuple_GetItem(args, 0);
  6720. if (!dict) return NULL;
  6721. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6722. auto& opdef = reinterpret_cast<PyOp(Diag)*>(self)->inst();
  6723. static_cast<void>(opdef);
  6724. {
  6725. auto&& iter = state.find("k");
  6726. if (iter != state.end()) {
  6727. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  6728. }
  6729. }
  6730. Py_RETURN_NONE;
  6731. }
  6732. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6733. // };
  6734. PyOpDefEnd(Diag)
  6735. int PyOp(Diag)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6736. static const char* kwlist[] = {"k", "scope", NULL};
  6737. PyObject *k = NULL, *scope = NULL;
  6738. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &k, &scope))
  6739. return -1;
  6740. if (k) {
  6741. try {
  6742. // TODO: remove this guard which is used for pybind11 implicit conversion
  6743. py::detail::loader_life_support guard{};
  6744. reinterpret_cast<PyOp(Diag)*>(self)->inst().k =
  6745. py::cast<decltype(Diag::k)>(py::handle(k));
  6746. } CATCH_ALL(-1)
  6747. }
  6748. if (scope) {
  6749. try {
  6750. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6751. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6752. } CATCH_ALL(-1)
  6753. }
  6754. return 0;
  6755. }
  6756. PyGetSetDef PyOp(Diag)::py_getsetters[] = {
  6757. {const_cast<char*>("k"), py_get_generic(Diag, k), py_set_generic(Diag, k), const_cast<char*>("k"), NULL},
  6758. {NULL} /* Sentinel */
  6759. };
  6760. PyMethodDef PyOp(Diag)::tp_methods[] = {
  6761. {const_cast<char*>("__getstate__"), PyOp(Diag)::getstate, METH_NOARGS, "Diag getstate"},
  6762. {const_cast<char*>("__setstate__"), PyOp(Diag)::setstate, METH_VARARGS, "Diag setstate"},
  6763. {NULL} /* Sentinel */
  6764. };
  6765. void _init_py_Diag(py::module m) {
  6766. using py_op = PyOp(Diag);
  6767. auto& py_type = PyOpType(Diag);
  6768. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6769. py_type.tp_name = "megengine.core._imperative_rt.ops.Diag";
  6770. py_type.tp_basicsize = sizeof(PyOp(Diag));
  6771. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6772. py_type.tp_doc = "Diag";
  6773. py_type.tp_base = &PyOpType(OpDef);
  6774. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6775. py_type.tp_new = py_new_generic<py_op>;
  6776. py_type.tp_init = py_op::py_init;
  6777. py_type.tp_methods = py_op::tp_methods;
  6778. py_type.tp_getset = py_op::py_getsetters;
  6779. mgb_assert(PyType_Ready(&py_type) >= 0);
  6780. PyType_Modified(&py_type);
  6781. m.add_object("Diag", reinterpret_cast<PyObject*>(&py_type));
  6782. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Diag::typeinfo(), &py_type).second);
  6783. }
  6784. PyOpDefBegin(Dimshuffle) // {
  6785. static PyGetSetDef py_getsetters[];
  6786. static PyMethodDef tp_methods[];
  6787. static PyObject* getstate(PyObject* self, PyObject*) {
  6788. auto& opdef = reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst();
  6789. static_cast<void>(opdef);
  6790. std::unordered_map<std::string, py::object> state {
  6791. {"pattern", serialization<decltype(opdef.pattern)>::dump(opdef.pattern)}
  6792. };
  6793. return py::cast(state).release().ptr();
  6794. }
  6795. static PyObject* setstate(PyObject* self, PyObject* args) {
  6796. PyObject* dict = PyTuple_GetItem(args, 0);
  6797. if (!dict) return NULL;
  6798. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6799. auto& opdef = reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst();
  6800. static_cast<void>(opdef);
  6801. {
  6802. auto&& iter = state.find("pattern");
  6803. if (iter != state.end()) {
  6804. opdef.pattern = serialization<decltype(opdef.pattern)>::load(iter->second);
  6805. }
  6806. }
  6807. Py_RETURN_NONE;
  6808. }
  6809. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6810. // };
  6811. PyOpDefEnd(Dimshuffle)
  6812. int PyOp(Dimshuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6813. static const char* kwlist[] = {"pattern", "scope", NULL};
  6814. PyObject *pattern = NULL, *scope = NULL;
  6815. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &pattern, &scope))
  6816. return -1;
  6817. if (pattern) {
  6818. try {
  6819. // TODO: remove this guard which is used for pybind11 implicit conversion
  6820. py::detail::loader_life_support guard{};
  6821. reinterpret_cast<PyOp(Dimshuffle)*>(self)->inst().pattern =
  6822. py::cast<decltype(Dimshuffle::pattern)>(py::handle(pattern));
  6823. } CATCH_ALL(-1)
  6824. }
  6825. if (scope) {
  6826. try {
  6827. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6828. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6829. } CATCH_ALL(-1)
  6830. }
  6831. return 0;
  6832. }
  6833. PyGetSetDef PyOp(Dimshuffle)::py_getsetters[] = {
  6834. {const_cast<char*>("pattern"), py_get_generic(Dimshuffle, pattern), py_set_generic(Dimshuffle, pattern), const_cast<char*>("pattern"), NULL},
  6835. {NULL} /* Sentinel */
  6836. };
  6837. PyMethodDef PyOp(Dimshuffle)::tp_methods[] = {
  6838. {const_cast<char*>("__getstate__"), PyOp(Dimshuffle)::getstate, METH_NOARGS, "Dimshuffle getstate"},
  6839. {const_cast<char*>("__setstate__"), PyOp(Dimshuffle)::setstate, METH_VARARGS, "Dimshuffle setstate"},
  6840. {NULL} /* Sentinel */
  6841. };
  6842. void _init_py_Dimshuffle(py::module m) {
  6843. using py_op = PyOp(Dimshuffle);
  6844. auto& py_type = PyOpType(Dimshuffle);
  6845. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6846. py_type.tp_name = "megengine.core._imperative_rt.ops.Dimshuffle";
  6847. py_type.tp_basicsize = sizeof(PyOp(Dimshuffle));
  6848. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6849. py_type.tp_doc = "Dimshuffle";
  6850. py_type.tp_base = &PyOpType(OpDef);
  6851. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6852. py_type.tp_new = py_new_generic<py_op>;
  6853. py_type.tp_init = py_op::py_init;
  6854. py_type.tp_methods = py_op::tp_methods;
  6855. py_type.tp_getset = py_op::py_getsetters;
  6856. mgb_assert(PyType_Ready(&py_type) >= 0);
  6857. PyType_Modified(&py_type);
  6858. m.add_object("Dimshuffle", reinterpret_cast<PyObject*>(&py_type));
  6859. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dimshuffle::typeinfo(), &py_type).second);
  6860. }
  6861. PyOpDefBegin(Dot) // {
  6862. static PyGetSetDef py_getsetters[];
  6863. static PyMethodDef tp_methods[];
  6864. static PyObject* getstate(PyObject* self, PyObject*) {
  6865. auto& opdef = reinterpret_cast<PyOp(Dot)*>(self)->inst();
  6866. static_cast<void>(opdef);
  6867. std::unordered_map<std::string, py::object> state {
  6868. };
  6869. return py::cast(state).release().ptr();
  6870. }
  6871. static PyObject* setstate(PyObject* self, PyObject* args) {
  6872. PyObject* dict = PyTuple_GetItem(args, 0);
  6873. if (!dict) return NULL;
  6874. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6875. auto& opdef = reinterpret_cast<PyOp(Dot)*>(self)->inst();
  6876. static_cast<void>(opdef);
  6877. Py_RETURN_NONE;
  6878. }
  6879. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6880. // };
  6881. PyOpDefEnd(Dot)
  6882. int PyOp(Dot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6883. return 0;
  6884. }
  6885. PyGetSetDef PyOp(Dot)::py_getsetters[] = {
  6886. {NULL} /* Sentinel */
  6887. };
  6888. PyMethodDef PyOp(Dot)::tp_methods[] = {
  6889. {const_cast<char*>("__getstate__"), PyOp(Dot)::getstate, METH_NOARGS, "Dot getstate"},
  6890. {const_cast<char*>("__setstate__"), PyOp(Dot)::setstate, METH_VARARGS, "Dot setstate"},
  6891. {NULL} /* Sentinel */
  6892. };
  6893. void _init_py_Dot(py::module m) {
  6894. using py_op = PyOp(Dot);
  6895. auto& py_type = PyOpType(Dot);
  6896. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  6897. py_type.tp_name = "megengine.core._imperative_rt.ops.Dot";
  6898. py_type.tp_basicsize = sizeof(PyOp(Dot));
  6899. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  6900. py_type.tp_doc = "Dot";
  6901. py_type.tp_base = &PyOpType(OpDef);
  6902. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  6903. py_type.tp_new = py_new_generic<py_op>;
  6904. py_type.tp_init = py_op::py_init;
  6905. py_type.tp_methods = py_op::tp_methods;
  6906. py_type.tp_getset = py_op::py_getsetters;
  6907. mgb_assert(PyType_Ready(&py_type) >= 0);
  6908. PyType_Modified(&py_type);
  6909. m.add_object("Dot", reinterpret_cast<PyObject*>(&py_type));
  6910. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dot::typeinfo(), &py_type).second);
  6911. }
  6912. PyOpDefBegin(Dropout) // {
  6913. static PyGetSetDef py_getsetters[];
  6914. static PyMethodDef tp_methods[];
  6915. static PyObject* getstate(PyObject* self, PyObject*) {
  6916. auto& opdef = reinterpret_cast<PyOp(Dropout)*>(self)->inst();
  6917. static_cast<void>(opdef);
  6918. std::unordered_map<std::string, py::object> state {
  6919. {"drop_prob", serialization<decltype(opdef.drop_prob)>::dump(opdef.drop_prob)},
  6920. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  6921. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  6922. };
  6923. return py::cast(state).release().ptr();
  6924. }
  6925. static PyObject* setstate(PyObject* self, PyObject* args) {
  6926. PyObject* dict = PyTuple_GetItem(args, 0);
  6927. if (!dict) return NULL;
  6928. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  6929. auto& opdef = reinterpret_cast<PyOp(Dropout)*>(self)->inst();
  6930. static_cast<void>(opdef);
  6931. {
  6932. auto&& iter = state.find("drop_prob");
  6933. if (iter != state.end()) {
  6934. opdef.drop_prob = serialization<decltype(opdef.drop_prob)>::load(iter->second);
  6935. }
  6936. }
  6937. {
  6938. auto&& iter = state.find("seed");
  6939. if (iter != state.end()) {
  6940. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  6941. }
  6942. }
  6943. {
  6944. auto&& iter = state.find("handle");
  6945. if (iter != state.end()) {
  6946. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  6947. }
  6948. }
  6949. Py_RETURN_NONE;
  6950. }
  6951. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  6952. // };
  6953. PyOpDefEnd(Dropout)
  6954. int PyOp(Dropout)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  6955. static const char* kwlist[] = {"drop_prob", "seed", "handle", "scope", NULL};
  6956. PyObject *drop_prob = NULL, *seed = NULL, *handle = NULL, *scope = NULL;
  6957. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &drop_prob, &seed, &handle, &scope))
  6958. return -1;
  6959. if (drop_prob) {
  6960. try {
  6961. // TODO: remove this guard which is used for pybind11 implicit conversion
  6962. py::detail::loader_life_support guard{};
  6963. reinterpret_cast<PyOp(Dropout)*>(self)->inst().drop_prob =
  6964. py::cast<decltype(Dropout::drop_prob)>(py::handle(drop_prob));
  6965. } CATCH_ALL(-1)
  6966. }
  6967. if (seed) {
  6968. try {
  6969. // TODO: remove this guard which is used for pybind11 implicit conversion
  6970. py::detail::loader_life_support guard{};
  6971. reinterpret_cast<PyOp(Dropout)*>(self)->inst().seed =
  6972. py::cast<decltype(Dropout::seed)>(py::handle(seed));
  6973. } CATCH_ALL(-1)
  6974. }
  6975. if (handle) {
  6976. try {
  6977. // TODO: remove this guard which is used for pybind11 implicit conversion
  6978. py::detail::loader_life_support guard{};
  6979. reinterpret_cast<PyOp(Dropout)*>(self)->inst().handle =
  6980. py::cast<decltype(Dropout::handle)>(py::handle(handle));
  6981. } CATCH_ALL(-1)
  6982. }
  6983. if (scope) {
  6984. try {
  6985. reinterpret_cast<PyOp(OpDef)*>(self)->op
  6986. ->set_scope(py::cast<std::string>(py::handle(scope)));
  6987. } CATCH_ALL(-1)
  6988. }
  6989. return 0;
  6990. }
  6991. PyGetSetDef PyOp(Dropout)::py_getsetters[] = {
  6992. {const_cast<char*>("drop_prob"), py_get_generic(Dropout, drop_prob), py_set_generic(Dropout, drop_prob), const_cast<char*>("drop_prob"), NULL},
  6993. {const_cast<char*>("seed"), py_get_generic(Dropout, seed), py_set_generic(Dropout, seed), const_cast<char*>("seed"), NULL},
  6994. {const_cast<char*>("handle"), py_get_generic(Dropout, handle), py_set_generic(Dropout, handle), const_cast<char*>("handle"), NULL},
  6995. {NULL} /* Sentinel */
  6996. };
  6997. PyMethodDef PyOp(Dropout)::tp_methods[] = {
  6998. {const_cast<char*>("__getstate__"), PyOp(Dropout)::getstate, METH_NOARGS, "Dropout getstate"},
  6999. {const_cast<char*>("__setstate__"), PyOp(Dropout)::setstate, METH_VARARGS, "Dropout setstate"},
  7000. {NULL} /* Sentinel */
  7001. };
  7002. void _init_py_Dropout(py::module m) {
  7003. using py_op = PyOp(Dropout);
  7004. auto& py_type = PyOpType(Dropout);
  7005. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7006. py_type.tp_name = "megengine.core._imperative_rt.ops.Dropout";
  7007. py_type.tp_basicsize = sizeof(PyOp(Dropout));
  7008. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7009. py_type.tp_doc = "Dropout";
  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("Dropout", reinterpret_cast<PyObject*>(&py_type));
  7019. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dropout::typeinfo(), &py_type).second);
  7020. }
  7021. template<> struct EnumTrait<Elemwise::Mode> {
  7022. static constexpr const char *name = "Elemwise.Mode";
  7023. static constexpr std::underlying_type_t<Elemwise::Mode> max = 64 - 1;
  7024. };
  7025. template<> PyTypeObject* EnumWrapper<Elemwise::Mode>::type = nullptr;
  7026. template<> const char*
  7027. 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", "NEQ", "ISNAN", "ISINF"};
  7028. template<> std::unordered_map<std::string, Elemwise::Mode>
  7029. 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("NEQ"), Elemwise::Mode::NEQ}, {normalize_enum("ISNAN"), Elemwise::Mode::ISNAN}, {normalize_enum("ISINF"), Elemwise::Mode::ISINF}};
  7030. template<> PyObject* EnumWrapper<Elemwise::Mode>::pyobj_insts[64] = {nullptr};
  7031. void _init_py_Elemwise_Mode(PyTypeObject& py_type) {
  7032. auto& e_type = EnumWrapper<Elemwise::Mode>::type;
  7033. static PyMethodDef tp_methods[] = {
  7034. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Elemwise::Mode>::py_dump, METH_NOARGS, NULL},
  7035. {NULL} /* Sentinel */
  7036. };
  7037. static PyType_Slot slots[] = {
  7038. {Py_tp_repr, (void*)EnumWrapper<Elemwise::Mode>::py_repr},
  7039. {Py_tp_richcompare, (void*)EnumWrapper<Elemwise::Mode>::tp_richcompare},
  7040. {Py_tp_methods, tp_methods},
  7041. {0, NULL}
  7042. };
  7043. static PyType_Spec spec = {
  7044. // name
  7045. "megengine.core._imperative_rt.ops.Elemwise.Mode",
  7046. // basicsize
  7047. sizeof(EnumWrapper<Elemwise::Mode>),
  7048. // itemsize
  7049. 0,
  7050. // flags
  7051. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  7052. // slots
  7053. slots
  7054. };
  7055. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  7056. mgb_assert(
  7057. e_type->tp_setattro(
  7058. reinterpret_cast<PyObject*>(e_type),
  7059. py::cast("__name__").release().ptr(),
  7060. py::cast("Mode").release().ptr()) >= 0);
  7061. mgb_assert(
  7062. e_type->tp_setattro(
  7063. reinterpret_cast<PyObject*>(e_type),
  7064. py::cast("__module__").release().ptr(),
  7065. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  7066. mgb_assert(
  7067. e_type->tp_setattro(
  7068. reinterpret_cast<PyObject*>(e_type),
  7069. py::cast("__qualname__").release().ptr(),
  7070. py::cast("Elemwise.Mode").release().ptr()) >= 0);
  7071. {
  7072. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7073. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RELU;
  7074. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  7075. EnumWrapper<Elemwise::Mode>::pyobj_insts[0] = inst;
  7076. }{
  7077. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7078. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ABS;
  7079. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS", inst) >= 0);
  7080. EnumWrapper<Elemwise::Mode>::pyobj_insts[1] = inst;
  7081. }{
  7082. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7083. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ACOS;
  7084. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ACOS", inst) >= 0);
  7085. EnumWrapper<Elemwise::Mode>::pyobj_insts[2] = inst;
  7086. }{
  7087. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7088. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ASIN;
  7089. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASIN", inst) >= 0);
  7090. EnumWrapper<Elemwise::Mode>::pyobj_insts[3] = inst;
  7091. }{
  7092. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7093. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::CEIL;
  7094. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CEIL", inst) >= 0);
  7095. EnumWrapper<Elemwise::Mode>::pyobj_insts[4] = inst;
  7096. }{
  7097. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7098. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COS;
  7099. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COS", inst) >= 0);
  7100. EnumWrapper<Elemwise::Mode>::pyobj_insts[5] = inst;
  7101. }{
  7102. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7103. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EXP;
  7104. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXP", inst) >= 0);
  7105. EnumWrapper<Elemwise::Mode>::pyobj_insts[6] = inst;
  7106. }{
  7107. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7108. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EXPM1;
  7109. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXPM1", inst) >= 0);
  7110. EnumWrapper<Elemwise::Mode>::pyobj_insts[7] = inst;
  7111. }{
  7112. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7113. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FLOOR;
  7114. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR", inst) >= 0);
  7115. EnumWrapper<Elemwise::Mode>::pyobj_insts[8] = inst;
  7116. }{
  7117. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7118. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG;
  7119. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG", inst) >= 0);
  7120. EnumWrapper<Elemwise::Mode>::pyobj_insts[9] = inst;
  7121. }{
  7122. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7123. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG1P;
  7124. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG1P", inst) >= 0);
  7125. EnumWrapper<Elemwise::Mode>::pyobj_insts[10] = inst;
  7126. }{
  7127. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7128. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NEGATE;
  7129. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEGATE", inst) >= 0);
  7130. EnumWrapper<Elemwise::Mode>::pyobj_insts[11] = inst;
  7131. }{
  7132. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7133. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIGMOID;
  7134. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID", inst) >= 0);
  7135. EnumWrapper<Elemwise::Mode>::pyobj_insts[12] = inst;
  7136. }{
  7137. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7138. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIN;
  7139. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIN", inst) >= 0);
  7140. EnumWrapper<Elemwise::Mode>::pyobj_insts[13] = inst;
  7141. }{
  7142. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7143. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TANH;
  7144. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0);
  7145. EnumWrapper<Elemwise::Mode>::pyobj_insts[14] = inst;
  7146. }{
  7147. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7148. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ABS_GRAD;
  7149. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS_GRAD", inst) >= 0);
  7150. EnumWrapper<Elemwise::Mode>::pyobj_insts[15] = inst;
  7151. }{
  7152. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7153. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ADD;
  7154. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ADD", inst) >= 0);
  7155. EnumWrapper<Elemwise::Mode>::pyobj_insts[16] = inst;
  7156. }{
  7157. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7158. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FLOOR_DIV;
  7159. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR_DIV", inst) >= 0);
  7160. EnumWrapper<Elemwise::Mode>::pyobj_insts[17] = inst;
  7161. }{
  7162. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7163. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MAX;
  7164. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  7165. EnumWrapper<Elemwise::Mode>::pyobj_insts[18] = inst;
  7166. }{
  7167. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7168. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MIN;
  7169. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0);
  7170. EnumWrapper<Elemwise::Mode>::pyobj_insts[19] = inst;
  7171. }{
  7172. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7173. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MOD;
  7174. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MOD", inst) >= 0);
  7175. EnumWrapper<Elemwise::Mode>::pyobj_insts[20] = inst;
  7176. }{
  7177. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7178. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::MUL;
  7179. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL", inst) >= 0);
  7180. EnumWrapper<Elemwise::Mode>::pyobj_insts[21] = inst;
  7181. }{
  7182. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7183. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::POW;
  7184. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "POW", inst) >= 0);
  7185. EnumWrapper<Elemwise::Mode>::pyobj_insts[22] = inst;
  7186. }{
  7187. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7188. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SIGMOID_GRAD;
  7189. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID_GRAD", inst) >= 0);
  7190. EnumWrapper<Elemwise::Mode>::pyobj_insts[23] = inst;
  7191. }{
  7192. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7193. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SUB;
  7194. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUB", inst) >= 0);
  7195. EnumWrapper<Elemwise::Mode>::pyobj_insts[24] = inst;
  7196. }{
  7197. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7198. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SWITCH_GT0;
  7199. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SWITCH_GT0", inst) >= 0);
  7200. EnumWrapper<Elemwise::Mode>::pyobj_insts[25] = inst;
  7201. }{
  7202. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7203. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TANH_GRAD;
  7204. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH_GRAD", inst) >= 0);
  7205. EnumWrapper<Elemwise::Mode>::pyobj_insts[26] = inst;
  7206. }{
  7207. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7208. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::TRUE_DIV;
  7209. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRUE_DIV", inst) >= 0);
  7210. EnumWrapper<Elemwise::Mode>::pyobj_insts[27] = inst;
  7211. }{
  7212. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7213. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LOG_SUM_EXP;
  7214. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG_SUM_EXP", inst) >= 0);
  7215. EnumWrapper<Elemwise::Mode>::pyobj_insts[28] = inst;
  7216. }{
  7217. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7218. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LT;
  7219. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LT", inst) >= 0);
  7220. EnumWrapper<Elemwise::Mode>::pyobj_insts[29] = inst;
  7221. }{
  7222. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7223. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::LEQ;
  7224. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LEQ", inst) >= 0);
  7225. EnumWrapper<Elemwise::Mode>::pyobj_insts[30] = inst;
  7226. }{
  7227. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7228. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::EQ;
  7229. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EQ", inst) >= 0);
  7230. EnumWrapper<Elemwise::Mode>::pyobj_insts[31] = inst;
  7231. }{
  7232. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7233. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SHL;
  7234. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHL", inst) >= 0);
  7235. EnumWrapper<Elemwise::Mode>::pyobj_insts[32] = inst;
  7236. }{
  7237. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7238. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SHR;
  7239. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHR", inst) >= 0);
  7240. EnumWrapper<Elemwise::Mode>::pyobj_insts[33] = inst;
  7241. }{
  7242. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7243. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COND_LEQ_MOV;
  7244. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LEQ_MOV", inst) >= 0);
  7245. EnumWrapper<Elemwise::Mode>::pyobj_insts[34] = inst;
  7246. }{
  7247. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7248. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD3;
  7249. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3", inst) >= 0);
  7250. EnumWrapper<Elemwise::Mode>::pyobj_insts[35] = inst;
  7251. }{
  7252. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7253. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD4;
  7254. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD4", inst) >= 0);
  7255. EnumWrapper<Elemwise::Mode>::pyobj_insts[36] = inst;
  7256. }{
  7257. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7258. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_RELU;
  7259. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RELU", inst) >= 0);
  7260. EnumWrapper<Elemwise::Mode>::pyobj_insts[37] = inst;
  7261. }{
  7262. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7263. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_SIGMOID;
  7264. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_SIGMOID", inst) >= 0);
  7265. EnumWrapper<Elemwise::Mode>::pyobj_insts[38] = inst;
  7266. }{
  7267. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7268. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_TANH;
  7269. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_TANH", inst) >= 0);
  7270. EnumWrapper<Elemwise::Mode>::pyobj_insts[39] = inst;
  7271. }{
  7272. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7273. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FAST_TANH;
  7274. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH", inst) >= 0);
  7275. EnumWrapper<Elemwise::Mode>::pyobj_insts[40] = inst;
  7276. }{
  7277. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7278. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FAST_TANH_GRAD;
  7279. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH_GRAD", inst) >= 0);
  7280. EnumWrapper<Elemwise::Mode>::pyobj_insts[41] = inst;
  7281. }{
  7282. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7283. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ROUND;
  7284. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND", inst) >= 0);
  7285. EnumWrapper<Elemwise::Mode>::pyobj_insts[42] = inst;
  7286. }{
  7287. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7288. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::RMULH;
  7289. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RMULH", inst) >= 0);
  7290. EnumWrapper<Elemwise::Mode>::pyobj_insts[43] = inst;
  7291. }{
  7292. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7293. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ATAN2;
  7294. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ATAN2", inst) >= 0);
  7295. EnumWrapper<Elemwise::Mode>::pyobj_insts[44] = inst;
  7296. }{
  7297. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7298. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERF;
  7299. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERF", inst) >= 0);
  7300. EnumWrapper<Elemwise::Mode>::pyobj_insts[45] = inst;
  7301. }{
  7302. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7303. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFINV;
  7304. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFINV", inst) >= 0);
  7305. EnumWrapper<Elemwise::Mode>::pyobj_insts[46] = inst;
  7306. }{
  7307. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7308. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFC;
  7309. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFC", inst) >= 0);
  7310. EnumWrapper<Elemwise::Mode>::pyobj_insts[47] = inst;
  7311. }{
  7312. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7313. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ERFCINV;
  7314. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFCINV", inst) >= 0);
  7315. EnumWrapper<Elemwise::Mode>::pyobj_insts[48] = inst;
  7316. }{
  7317. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7318. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::H_SWISH;
  7319. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH", inst) >= 0);
  7320. EnumWrapper<Elemwise::Mode>::pyobj_insts[49] = inst;
  7321. }{
  7322. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7323. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::H_SWISH_GRAD;
  7324. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH_GRAD", inst) >= 0);
  7325. EnumWrapper<Elemwise::Mode>::pyobj_insts[50] = inst;
  7326. }{
  7327. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7328. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::FUSE_ADD_H_SWISH;
  7329. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_H_SWISH", inst) >= 0);
  7330. EnumWrapper<Elemwise::Mode>::pyobj_insts[51] = inst;
  7331. }{
  7332. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7333. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NOT;
  7334. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NOT", inst) >= 0);
  7335. EnumWrapper<Elemwise::Mode>::pyobj_insts[52] = inst;
  7336. }{
  7337. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7338. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::AND;
  7339. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AND", inst) >= 0);
  7340. EnumWrapper<Elemwise::Mode>::pyobj_insts[53] = inst;
  7341. }{
  7342. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7343. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::OR;
  7344. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "OR", inst) >= 0);
  7345. EnumWrapper<Elemwise::Mode>::pyobj_insts[54] = inst;
  7346. }{
  7347. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7348. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::XOR;
  7349. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "XOR", inst) >= 0);
  7350. EnumWrapper<Elemwise::Mode>::pyobj_insts[55] = inst;
  7351. }{
  7352. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7353. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SILU;
  7354. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU", inst) >= 0);
  7355. EnumWrapper<Elemwise::Mode>::pyobj_insts[56] = inst;
  7356. }{
  7357. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7358. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::SILU_GRAD;
  7359. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU_GRAD", inst) >= 0);
  7360. EnumWrapper<Elemwise::Mode>::pyobj_insts[57] = inst;
  7361. }{
  7362. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7363. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::GELU;
  7364. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU", inst) >= 0);
  7365. EnumWrapper<Elemwise::Mode>::pyobj_insts[58] = inst;
  7366. }{
  7367. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7368. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::GELU_GRAD;
  7369. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU_GRAD", inst) >= 0);
  7370. EnumWrapper<Elemwise::Mode>::pyobj_insts[59] = inst;
  7371. }{
  7372. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7373. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::COND_LT_MOV;
  7374. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LT_MOV", inst) >= 0);
  7375. EnumWrapper<Elemwise::Mode>::pyobj_insts[60] = inst;
  7376. }{
  7377. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7378. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::NEQ;
  7379. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEQ", inst) >= 0);
  7380. EnumWrapper<Elemwise::Mode>::pyobj_insts[61] = inst;
  7381. }{
  7382. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7383. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ISNAN;
  7384. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISNAN", inst) >= 0);
  7385. EnumWrapper<Elemwise::Mode>::pyobj_insts[62] = inst;
  7386. }{
  7387. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7388. reinterpret_cast<EnumWrapper<Elemwise::Mode>*>(inst)->value = Elemwise::Mode::ISINF;
  7389. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISINF", inst) >= 0);
  7390. EnumWrapper<Elemwise::Mode>::pyobj_insts[63] = inst;
  7391. }
  7392. Py_INCREF(e_type);
  7393. mgb_assert(PyDict_SetItemString(
  7394. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  7395. }
  7396. PyOpDefBegin(Elemwise) // {
  7397. static PyGetSetDef py_getsetters[];
  7398. static PyMethodDef tp_methods[];
  7399. static PyObject* getstate(PyObject* self, PyObject*) {
  7400. auto& opdef = reinterpret_cast<PyOp(Elemwise)*>(self)->inst();
  7401. static_cast<void>(opdef);
  7402. std::unordered_map<std::string, py::object> state {
  7403. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  7404. };
  7405. return py::cast(state).release().ptr();
  7406. }
  7407. static PyObject* setstate(PyObject* self, PyObject* args) {
  7408. PyObject* dict = PyTuple_GetItem(args, 0);
  7409. if (!dict) return NULL;
  7410. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7411. auto& opdef = reinterpret_cast<PyOp(Elemwise)*>(self)->inst();
  7412. static_cast<void>(opdef);
  7413. {
  7414. auto&& iter = state.find("mode");
  7415. if (iter != state.end()) {
  7416. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  7417. }
  7418. }
  7419. Py_RETURN_NONE;
  7420. }
  7421. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7422. // };
  7423. PyOpDefEnd(Elemwise)
  7424. int PyOp(Elemwise)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7425. static const char* kwlist[] = {"mode", "scope", NULL};
  7426. PyObject *mode = NULL, *scope = NULL;
  7427. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  7428. return -1;
  7429. if (mode) {
  7430. try {
  7431. // TODO: remove this guard which is used for pybind11 implicit conversion
  7432. py::detail::loader_life_support guard{};
  7433. reinterpret_cast<PyOp(Elemwise)*>(self)->inst().mode =
  7434. py::cast<decltype(Elemwise::mode)>(py::handle(mode));
  7435. } CATCH_ALL(-1)
  7436. }
  7437. if (scope) {
  7438. try {
  7439. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7440. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7441. } CATCH_ALL(-1)
  7442. }
  7443. return 0;
  7444. }
  7445. PyGetSetDef PyOp(Elemwise)::py_getsetters[] = {
  7446. {const_cast<char*>("mode"), py_get_generic(Elemwise, mode), py_set_generic(Elemwise, mode), const_cast<char*>("mode"), NULL},
  7447. {NULL} /* Sentinel */
  7448. };
  7449. PyMethodDef PyOp(Elemwise)::tp_methods[] = {
  7450. {const_cast<char*>("__getstate__"), PyOp(Elemwise)::getstate, METH_NOARGS, "Elemwise getstate"},
  7451. {const_cast<char*>("__setstate__"), PyOp(Elemwise)::setstate, METH_VARARGS, "Elemwise setstate"},
  7452. {NULL} /* Sentinel */
  7453. };
  7454. void _init_py_Elemwise(py::module m) {
  7455. using py_op = PyOp(Elemwise);
  7456. auto& py_type = PyOpType(Elemwise);
  7457. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7458. py_type.tp_name = "megengine.core._imperative_rt.ops.Elemwise";
  7459. py_type.tp_basicsize = sizeof(PyOp(Elemwise));
  7460. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7461. py_type.tp_doc = "Elemwise";
  7462. py_type.tp_base = &PyOpType(OpDef);
  7463. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7464. py_type.tp_new = py_new_generic<py_op>;
  7465. py_type.tp_init = py_op::py_init;
  7466. py_type.tp_methods = py_op::tp_methods;
  7467. py_type.tp_getset = py_op::py_getsetters;
  7468. mgb_assert(PyType_Ready(&py_type) >= 0);
  7469. _init_py_Elemwise_Mode(py_type);
  7470. PyType_Modified(&py_type);
  7471. m.add_object("Elemwise", reinterpret_cast<PyObject*>(&py_type));
  7472. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Elemwise::typeinfo(), &py_type).second);
  7473. }
  7474. template<> struct EnumTrait<ElemwiseMultiType::Mode> {
  7475. static constexpr const char *name = "ElemwiseMultiType.Mode";
  7476. static constexpr std::underlying_type_t<ElemwiseMultiType::Mode> max = 64 - 1;
  7477. };
  7478. template<> PyTypeObject* EnumWrapper<ElemwiseMultiType::Mode>::type = nullptr;
  7479. template<> const char*
  7480. 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"};
  7481. template<> std::unordered_map<std::string, ElemwiseMultiType::Mode>
  7482. 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}};
  7483. template<> PyObject* EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[64] = {nullptr};
  7484. void _init_py_ElemwiseMultiType_Mode(PyTypeObject& py_type) {
  7485. auto& e_type = EnumWrapper<ElemwiseMultiType::Mode>::type;
  7486. static PyMethodDef tp_methods[] = {
  7487. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ElemwiseMultiType::Mode>::py_dump, METH_NOARGS, NULL},
  7488. {NULL} /* Sentinel */
  7489. };
  7490. static PyType_Slot slots[] = {
  7491. {Py_tp_repr, (void*)EnumWrapper<ElemwiseMultiType::Mode>::py_repr},
  7492. {Py_tp_richcompare, (void*)EnumWrapper<ElemwiseMultiType::Mode>::tp_richcompare},
  7493. {Py_tp_methods, tp_methods},
  7494. {0, NULL}
  7495. };
  7496. static PyType_Spec spec = {
  7497. // name
  7498. "megengine.core._imperative_rt.ops.ElemwiseMultiType.Mode",
  7499. // basicsize
  7500. sizeof(EnumWrapper<ElemwiseMultiType::Mode>),
  7501. // itemsize
  7502. 0,
  7503. // flags
  7504. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  7505. // slots
  7506. slots
  7507. };
  7508. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  7509. mgb_assert(
  7510. e_type->tp_setattro(
  7511. reinterpret_cast<PyObject*>(e_type),
  7512. py::cast("__name__").release().ptr(),
  7513. py::cast("Mode").release().ptr()) >= 0);
  7514. mgb_assert(
  7515. e_type->tp_setattro(
  7516. reinterpret_cast<PyObject*>(e_type),
  7517. py::cast("__module__").release().ptr(),
  7518. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  7519. mgb_assert(
  7520. e_type->tp_setattro(
  7521. reinterpret_cast<PyObject*>(e_type),
  7522. py::cast("__qualname__").release().ptr(),
  7523. py::cast("ElemwiseMultiType.Mode").release().ptr()) >= 0);
  7524. {
  7525. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7526. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32;
  7527. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16x32x32x32", inst) >= 0);
  7528. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[0] = inst;
  7529. }{
  7530. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7531. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8;
  7532. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_IXxF32xF32xI8", inst) >= 0);
  7533. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[1] = inst;
  7534. }{
  7535. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7536. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8;
  7537. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI8", inst) >= 0);
  7538. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[2] = inst;
  7539. }{
  7540. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7541. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8;
  7542. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", inst) >= 0);
  7543. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[3] = inst;
  7544. }{
  7545. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7546. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8;
  7547. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", inst) >= 0);
  7548. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[4] = inst;
  7549. }{
  7550. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7551. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16;
  7552. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI16", inst) >= 0);
  7553. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[5] = inst;
  7554. }{
  7555. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7556. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QADD;
  7557. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QADD", inst) >= 0);
  7558. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[6] = inst;
  7559. }{
  7560. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7561. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_RELU;
  7562. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_RELU", inst) >= 0);
  7563. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[7] = inst;
  7564. }{
  7565. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7566. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMUL;
  7567. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMUL", inst) >= 0);
  7568. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[8] = inst;
  7569. }{
  7570. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7571. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMIN;
  7572. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMIN", inst) >= 0);
  7573. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[9] = inst;
  7574. }{
  7575. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7576. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMAX;
  7577. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMAX", inst) >= 0);
  7578. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[10] = inst;
  7579. }{
  7580. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7581. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSUB;
  7582. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSUB", inst) >= 0);
  7583. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[11] = inst;
  7584. }{
  7585. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7586. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTRUE_DIV;
  7587. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTRUE_DIV", inst) >= 0);
  7588. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[12] = inst;
  7589. }{
  7590. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7591. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID;
  7592. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_SIGMOID", inst) >= 0);
  7593. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[13] = inst;
  7594. }{
  7595. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7596. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_TANH;
  7597. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_TANH", inst) >= 0);
  7598. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[14] = inst;
  7599. }{
  7600. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7601. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QRELU;
  7602. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QRELU", inst) >= 0);
  7603. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[15] = inst;
  7604. }{
  7605. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7606. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QABS;
  7607. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS", inst) >= 0);
  7608. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[16] = inst;
  7609. }{
  7610. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7611. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID;
  7612. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID", inst) >= 0);
  7613. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[17] = inst;
  7614. }{
  7615. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7616. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEXP;
  7617. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXP", inst) >= 0);
  7618. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[18] = inst;
  7619. }{
  7620. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7621. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTANH;
  7622. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH", inst) >= 0);
  7623. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[19] = inst;
  7624. }{
  7625. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7626. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_MUL_ADD3;
  7627. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_MUL_ADD3", inst) >= 0);
  7628. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[20] = inst;
  7629. }{
  7630. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7631. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH;
  7632. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH", inst) >= 0);
  7633. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[21] = inst;
  7634. }{
  7635. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7636. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QNEGATE;
  7637. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QNEGATE", inst) >= 0);
  7638. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[22] = inst;
  7639. }{
  7640. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7641. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QACOS;
  7642. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QACOS", inst) >= 0);
  7643. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[23] = inst;
  7644. }{
  7645. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7646. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QASIN;
  7647. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QASIN", inst) >= 0);
  7648. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[24] = inst;
  7649. }{
  7650. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7651. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCEIL;
  7652. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCEIL", inst) >= 0);
  7653. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[25] = inst;
  7654. }{
  7655. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7656. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOS;
  7657. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOS", inst) >= 0);
  7658. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[26] = inst;
  7659. }{
  7660. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7661. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEXPM1;
  7662. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXPM1", inst) >= 0);
  7663. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[27] = inst;
  7664. }{
  7665. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7666. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR;
  7667. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR", inst) >= 0);
  7668. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[28] = inst;
  7669. }{
  7670. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7671. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG;
  7672. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG", inst) >= 0);
  7673. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[29] = inst;
  7674. }{
  7675. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7676. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG1P;
  7677. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG1P", inst) >= 0);
  7678. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[30] = inst;
  7679. }{
  7680. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7681. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIN;
  7682. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIN", inst) >= 0);
  7683. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[31] = inst;
  7684. }{
  7685. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7686. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QROUND;
  7687. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QROUND", inst) >= 0);
  7688. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[32] = inst;
  7689. }{
  7690. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7691. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERF;
  7692. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERF", inst) >= 0);
  7693. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[33] = inst;
  7694. }{
  7695. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7696. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFINV;
  7697. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFINV", inst) >= 0);
  7698. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[34] = inst;
  7699. }{
  7700. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7701. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFC;
  7702. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFC", inst) >= 0);
  7703. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[35] = inst;
  7704. }{
  7705. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7706. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QERFCINV;
  7707. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFCINV", inst) >= 0);
  7708. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[36] = inst;
  7709. }{
  7710. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7711. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QABS_GRAD;
  7712. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS_GRAD", inst) >= 0);
  7713. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[37] = inst;
  7714. }{
  7715. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7716. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR_DIV;
  7717. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR_DIV", inst) >= 0);
  7718. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[38] = inst;
  7719. }{
  7720. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7721. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QMOD;
  7722. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMOD", inst) >= 0);
  7723. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[39] = inst;
  7724. }{
  7725. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7726. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID_GRAD;
  7727. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID_GRAD", inst) >= 0);
  7728. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[40] = inst;
  7729. }{
  7730. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7731. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QSWITCH_GT0;
  7732. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSWITCH_GT0", inst) >= 0);
  7733. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[41] = inst;
  7734. }{
  7735. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7736. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QTANH_GRAD;
  7737. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH_GRAD", inst) >= 0);
  7738. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[42] = inst;
  7739. }{
  7740. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7741. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLT;
  7742. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLT", inst) >= 0);
  7743. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[43] = inst;
  7744. }{
  7745. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7746. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLEQ;
  7747. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLEQ", inst) >= 0);
  7748. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[44] = inst;
  7749. }{
  7750. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7751. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QEQ;
  7752. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEQ", inst) >= 0);
  7753. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[45] = inst;
  7754. }{
  7755. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7756. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QPOW;
  7757. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QPOW", inst) >= 0);
  7758. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[46] = inst;
  7759. }{
  7760. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7761. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QLOG_SUM_EXP;
  7762. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG_SUM_EXP", inst) >= 0);
  7763. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[47] = inst;
  7764. }{
  7765. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7766. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH_GRAD;
  7767. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH_GRAD", inst) >= 0);
  7768. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[48] = inst;
  7769. }{
  7770. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7771. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QATAN2;
  7772. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QATAN2", inst) >= 0);
  7773. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[49] = inst;
  7774. }{
  7775. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7776. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LEQ_MOV;
  7777. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LEQ_MOV", inst) >= 0);
  7778. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[50] = inst;
  7779. }{
  7780. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7781. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH;
  7782. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH", inst) >= 0);
  7783. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[51] = inst;
  7784. }{
  7785. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7786. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH;
  7787. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_H_SWISH", inst) >= 0);
  7788. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[52] = inst;
  7789. }{
  7790. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7791. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH_GRAD;
  7792. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH_GRAD", inst) >= 0);
  7793. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[53] = inst;
  7794. }{
  7795. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7796. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32;
  7797. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16xF32xF32xF32", inst) >= 0);
  7798. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[54] = inst;
  7799. }{
  7800. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7801. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::MUL_INT16xF32xF32;
  7802. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL_INT16xF32xF32", inst) >= 0);
  7803. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[55] = inst;
  7804. }{
  7805. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7806. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32;
  7807. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_UINT8xF32xF32xF32", inst) >= 0);
  7808. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[56] = inst;
  7809. }{
  7810. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7811. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LT_MOV;
  7812. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LT_MOV", inst) >= 0);
  7813. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[57] = inst;
  7814. }{
  7815. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7816. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::EQ;
  7817. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EQ", inst) >= 0);
  7818. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[58] = inst;
  7819. }{
  7820. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7821. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::NEQ;
  7822. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEQ", inst) >= 0);
  7823. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[59] = inst;
  7824. }{
  7825. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7826. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::LT;
  7827. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LT", inst) >= 0);
  7828. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[60] = inst;
  7829. }{
  7830. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7831. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::LEQ;
  7832. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LEQ", inst) >= 0);
  7833. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[61] = inst;
  7834. }{
  7835. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7836. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ISNAN;
  7837. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISNAN", inst) >= 0);
  7838. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[62] = inst;
  7839. }{
  7840. PyObject* inst = e_type->tp_alloc(e_type, 0);
  7841. reinterpret_cast<EnumWrapper<ElemwiseMultiType::Mode>*>(inst)->value = ElemwiseMultiType::Mode::ISINF;
  7842. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISINF", inst) >= 0);
  7843. EnumWrapper<ElemwiseMultiType::Mode>::pyobj_insts[63] = inst;
  7844. }
  7845. Py_INCREF(e_type);
  7846. mgb_assert(PyDict_SetItemString(
  7847. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  7848. }
  7849. PyOpDefBegin(ElemwiseMultiType) // {
  7850. static PyGetSetDef py_getsetters[];
  7851. static PyMethodDef tp_methods[];
  7852. static PyObject* getstate(PyObject* self, PyObject*) {
  7853. auto& opdef = reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst();
  7854. static_cast<void>(opdef);
  7855. std::unordered_map<std::string, py::object> state {
  7856. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  7857. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  7858. };
  7859. return py::cast(state).release().ptr();
  7860. }
  7861. static PyObject* setstate(PyObject* self, PyObject* args) {
  7862. PyObject* dict = PyTuple_GetItem(args, 0);
  7863. if (!dict) return NULL;
  7864. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7865. auto& opdef = reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst();
  7866. static_cast<void>(opdef);
  7867. {
  7868. auto&& iter = state.find("mode");
  7869. if (iter != state.end()) {
  7870. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  7871. }
  7872. }
  7873. {
  7874. auto&& iter = state.find("dtype");
  7875. if (iter != state.end()) {
  7876. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  7877. }
  7878. }
  7879. Py_RETURN_NONE;
  7880. }
  7881. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7882. // };
  7883. PyOpDefEnd(ElemwiseMultiType)
  7884. int PyOp(ElemwiseMultiType)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  7885. static const char* kwlist[] = {"mode", "dtype", "scope", NULL};
  7886. PyObject *mode = NULL, *dtype = NULL, *scope = NULL;
  7887. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &mode, &dtype, &scope))
  7888. return -1;
  7889. if (mode) {
  7890. try {
  7891. // TODO: remove this guard which is used for pybind11 implicit conversion
  7892. py::detail::loader_life_support guard{};
  7893. reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst().mode =
  7894. py::cast<decltype(ElemwiseMultiType::mode)>(py::handle(mode));
  7895. } CATCH_ALL(-1)
  7896. }
  7897. if (dtype) {
  7898. try {
  7899. // TODO: remove this guard which is used for pybind11 implicit conversion
  7900. py::detail::loader_life_support guard{};
  7901. reinterpret_cast<PyOp(ElemwiseMultiType)*>(self)->inst().dtype =
  7902. py::cast<decltype(ElemwiseMultiType::dtype)>(py::handle(dtype));
  7903. } CATCH_ALL(-1)
  7904. }
  7905. if (scope) {
  7906. try {
  7907. reinterpret_cast<PyOp(OpDef)*>(self)->op
  7908. ->set_scope(py::cast<std::string>(py::handle(scope)));
  7909. } CATCH_ALL(-1)
  7910. }
  7911. return 0;
  7912. }
  7913. PyGetSetDef PyOp(ElemwiseMultiType)::py_getsetters[] = {
  7914. {const_cast<char*>("mode"), py_get_generic(ElemwiseMultiType, mode), py_set_generic(ElemwiseMultiType, mode), const_cast<char*>("mode"), NULL},
  7915. {const_cast<char*>("dtype"), py_get_generic(ElemwiseMultiType, dtype), py_set_generic(ElemwiseMultiType, dtype), const_cast<char*>("dtype"), NULL},
  7916. {NULL} /* Sentinel */
  7917. };
  7918. PyMethodDef PyOp(ElemwiseMultiType)::tp_methods[] = {
  7919. {const_cast<char*>("__getstate__"), PyOp(ElemwiseMultiType)::getstate, METH_NOARGS, "ElemwiseMultiType getstate"},
  7920. {const_cast<char*>("__setstate__"), PyOp(ElemwiseMultiType)::setstate, METH_VARARGS, "ElemwiseMultiType setstate"},
  7921. {NULL} /* Sentinel */
  7922. };
  7923. void _init_py_ElemwiseMultiType(py::module m) {
  7924. using py_op = PyOp(ElemwiseMultiType);
  7925. auto& py_type = PyOpType(ElemwiseMultiType);
  7926. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  7927. py_type.tp_name = "megengine.core._imperative_rt.ops.ElemwiseMultiType";
  7928. py_type.tp_basicsize = sizeof(PyOp(ElemwiseMultiType));
  7929. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  7930. py_type.tp_doc = "ElemwiseMultiType";
  7931. py_type.tp_base = &PyOpType(OpDef);
  7932. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  7933. py_type.tp_new = py_new_generic<py_op>;
  7934. py_type.tp_init = py_op::py_init;
  7935. py_type.tp_methods = py_op::tp_methods;
  7936. py_type.tp_getset = py_op::py_getsetters;
  7937. mgb_assert(PyType_Ready(&py_type) >= 0);
  7938. _init_py_ElemwiseMultiType_Mode(py_type);
  7939. PyType_Modified(&py_type);
  7940. m.add_object("ElemwiseMultiType", reinterpret_cast<PyObject*>(&py_type));
  7941. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ElemwiseMultiType::typeinfo(), &py_type).second);
  7942. }
  7943. PyOpDefBegin(ExternOpr) // {
  7944. static PyGetSetDef py_getsetters[];
  7945. static PyMethodDef tp_methods[];
  7946. static PyObject* getstate(PyObject* self, PyObject*) {
  7947. auto& opdef = reinterpret_cast<PyOp(ExternOpr)*>(self)->inst();
  7948. static_cast<void>(opdef);
  7949. std::unordered_map<std::string, py::object> state {
  7950. {"output_shapes", serialization<decltype(opdef.output_shapes)>::dump(opdef.output_shapes)},
  7951. {"name", serialization<decltype(opdef.name)>::dump(opdef.name)},
  7952. {"data", serialization<decltype(opdef.data)>::dump(opdef.data)},
  7953. {"data_len", serialization<decltype(opdef.data_len)>::dump(opdef.data_len)},
  7954. {"output_dtypes", serialization<decltype(opdef.output_dtypes)>::dump(opdef.output_dtypes)}
  7955. };
  7956. return py::cast(state).release().ptr();
  7957. }
  7958. static PyObject* setstate(PyObject* self, PyObject* args) {
  7959. PyObject* dict = PyTuple_GetItem(args, 0);
  7960. if (!dict) return NULL;
  7961. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  7962. auto& opdef = reinterpret_cast<PyOp(ExternOpr)*>(self)->inst();
  7963. static_cast<void>(opdef);
  7964. {
  7965. auto&& iter = state.find("output_shapes");
  7966. if (iter != state.end()) {
  7967. opdef.output_shapes = serialization<decltype(opdef.output_shapes)>::load(iter->second);
  7968. }
  7969. }
  7970. {
  7971. auto&& iter = state.find("name");
  7972. if (iter != state.end()) {
  7973. opdef.name = serialization<decltype(opdef.name)>::load(iter->second);
  7974. }
  7975. }
  7976. {
  7977. auto&& iter = state.find("data");
  7978. if (iter != state.end()) {
  7979. opdef.data = serialization<decltype(opdef.data)>::load(iter->second);
  7980. }
  7981. }
  7982. {
  7983. auto&& iter = state.find("data_len");
  7984. if (iter != state.end()) {
  7985. opdef.data_len = serialization<decltype(opdef.data_len)>::load(iter->second);
  7986. }
  7987. }
  7988. {
  7989. auto&& iter = state.find("output_dtypes");
  7990. if (iter != state.end()) {
  7991. opdef.output_dtypes = serialization<decltype(opdef.output_dtypes)>::load(iter->second);
  7992. }
  7993. }
  7994. Py_RETURN_NONE;
  7995. }
  7996. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  7997. // };
  7998. PyOpDefEnd(ExternOpr)
  7999. int PyOp(ExternOpr)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8000. static const char* kwlist[] = {"output_shapes", "name", "data", "data_len", "output_dtypes", "scope", NULL};
  8001. PyObject *output_shapes = NULL, *name = NULL, *data = NULL, *data_len = NULL, *output_dtypes = NULL, *scope = NULL;
  8002. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &output_shapes, &name, &data, &data_len, &output_dtypes, &scope))
  8003. return -1;
  8004. if (output_shapes) {
  8005. try {
  8006. // TODO: remove this guard which is used for pybind11 implicit conversion
  8007. py::detail::loader_life_support guard{};
  8008. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().output_shapes =
  8009. py::cast<decltype(ExternOpr::output_shapes)>(py::handle(output_shapes));
  8010. } CATCH_ALL(-1)
  8011. }
  8012. if (name) {
  8013. try {
  8014. // TODO: remove this guard which is used for pybind11 implicit conversion
  8015. py::detail::loader_life_support guard{};
  8016. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().name =
  8017. py::cast<decltype(ExternOpr::name)>(py::handle(name));
  8018. } CATCH_ALL(-1)
  8019. }
  8020. if (data) {
  8021. try {
  8022. // TODO: remove this guard which is used for pybind11 implicit conversion
  8023. py::detail::loader_life_support guard{};
  8024. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().data =
  8025. py::cast<decltype(ExternOpr::data)>(py::handle(data));
  8026. } CATCH_ALL(-1)
  8027. }
  8028. if (data_len) {
  8029. try {
  8030. // TODO: remove this guard which is used for pybind11 implicit conversion
  8031. py::detail::loader_life_support guard{};
  8032. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().data_len =
  8033. py::cast<decltype(ExternOpr::data_len)>(py::handle(data_len));
  8034. } CATCH_ALL(-1)
  8035. }
  8036. if (output_dtypes) {
  8037. try {
  8038. // TODO: remove this guard which is used for pybind11 implicit conversion
  8039. py::detail::loader_life_support guard{};
  8040. reinterpret_cast<PyOp(ExternOpr)*>(self)->inst().output_dtypes =
  8041. py::cast<decltype(ExternOpr::output_dtypes)>(py::handle(output_dtypes));
  8042. } CATCH_ALL(-1)
  8043. }
  8044. if (scope) {
  8045. try {
  8046. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8047. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8048. } CATCH_ALL(-1)
  8049. }
  8050. return 0;
  8051. }
  8052. PyGetSetDef PyOp(ExternOpr)::py_getsetters[] = {
  8053. {const_cast<char*>("output_shapes"), py_get_generic(ExternOpr, output_shapes), py_set_generic(ExternOpr, output_shapes), const_cast<char*>("output_shapes"), NULL},
  8054. {const_cast<char*>("name"), py_get_generic(ExternOpr, name), py_set_generic(ExternOpr, name), const_cast<char*>("name"), NULL},
  8055. {const_cast<char*>("data"), py_get_generic(ExternOpr, data), py_set_generic(ExternOpr, data), const_cast<char*>("data"), NULL},
  8056. {const_cast<char*>("data_len"), py_get_generic(ExternOpr, data_len), py_set_generic(ExternOpr, data_len), const_cast<char*>("data_len"), NULL},
  8057. {const_cast<char*>("output_dtypes"), py_get_generic(ExternOpr, output_dtypes), py_set_generic(ExternOpr, output_dtypes), const_cast<char*>("output_dtypes"), NULL},
  8058. {NULL} /* Sentinel */
  8059. };
  8060. PyMethodDef PyOp(ExternOpr)::tp_methods[] = {
  8061. {const_cast<char*>("__getstate__"), PyOp(ExternOpr)::getstate, METH_NOARGS, "ExternOpr getstate"},
  8062. {const_cast<char*>("__setstate__"), PyOp(ExternOpr)::setstate, METH_VARARGS, "ExternOpr setstate"},
  8063. {NULL} /* Sentinel */
  8064. };
  8065. void _init_py_ExternOpr(py::module m) {
  8066. using py_op = PyOp(ExternOpr);
  8067. auto& py_type = PyOpType(ExternOpr);
  8068. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8069. py_type.tp_name = "megengine.core._imperative_rt.ops.ExternOpr";
  8070. py_type.tp_basicsize = sizeof(PyOp(ExternOpr));
  8071. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8072. py_type.tp_doc = "ExternOpr";
  8073. py_type.tp_base = &PyOpType(OpDef);
  8074. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8075. py_type.tp_new = py_new_generic<py_op>;
  8076. py_type.tp_init = py_op::py_init;
  8077. py_type.tp_methods = py_op::tp_methods;
  8078. py_type.tp_getset = py_op::py_getsetters;
  8079. mgb_assert(PyType_Ready(&py_type) >= 0);
  8080. PyType_Modified(&py_type);
  8081. m.add_object("ExternOpr", reinterpret_cast<PyObject*>(&py_type));
  8082. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ExternOpr::typeinfo(), &py_type).second);
  8083. }
  8084. PyOpDefBegin(Eye) // {
  8085. static PyGetSetDef py_getsetters[];
  8086. static PyMethodDef tp_methods[];
  8087. static PyObject* getstate(PyObject* self, PyObject*) {
  8088. auto& opdef = reinterpret_cast<PyOp(Eye)*>(self)->inst();
  8089. static_cast<void>(opdef);
  8090. std::unordered_map<std::string, py::object> state {
  8091. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)},
  8092. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  8093. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  8094. };
  8095. return py::cast(state).release().ptr();
  8096. }
  8097. static PyObject* setstate(PyObject* self, PyObject* args) {
  8098. PyObject* dict = PyTuple_GetItem(args, 0);
  8099. if (!dict) return NULL;
  8100. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8101. auto& opdef = reinterpret_cast<PyOp(Eye)*>(self)->inst();
  8102. static_cast<void>(opdef);
  8103. {
  8104. auto&& iter = state.find("k");
  8105. if (iter != state.end()) {
  8106. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  8107. }
  8108. }
  8109. {
  8110. auto&& iter = state.find("dtype");
  8111. if (iter != state.end()) {
  8112. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  8113. }
  8114. }
  8115. {
  8116. auto&& iter = state.find("comp_node");
  8117. if (iter != state.end()) {
  8118. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  8119. }
  8120. }
  8121. Py_RETURN_NONE;
  8122. }
  8123. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8124. // };
  8125. PyOpDefEnd(Eye)
  8126. int PyOp(Eye)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8127. static const char* kwlist[] = {"k", "dtype", "comp_node", "scope", NULL};
  8128. PyObject *k = NULL, *dtype = NULL, *comp_node = NULL, *scope = NULL;
  8129. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &k, &dtype, &comp_node, &scope))
  8130. return -1;
  8131. if (k) {
  8132. try {
  8133. // TODO: remove this guard which is used for pybind11 implicit conversion
  8134. py::detail::loader_life_support guard{};
  8135. reinterpret_cast<PyOp(Eye)*>(self)->inst().k =
  8136. py::cast<decltype(Eye::k)>(py::handle(k));
  8137. } CATCH_ALL(-1)
  8138. }
  8139. if (dtype) {
  8140. try {
  8141. // TODO: remove this guard which is used for pybind11 implicit conversion
  8142. py::detail::loader_life_support guard{};
  8143. reinterpret_cast<PyOp(Eye)*>(self)->inst().dtype =
  8144. py::cast<decltype(Eye::dtype)>(py::handle(dtype));
  8145. } CATCH_ALL(-1)
  8146. }
  8147. if (comp_node) {
  8148. try {
  8149. // TODO: remove this guard which is used for pybind11 implicit conversion
  8150. py::detail::loader_life_support guard{};
  8151. reinterpret_cast<PyOp(Eye)*>(self)->inst().comp_node =
  8152. py::cast<decltype(Eye::comp_node)>(py::handle(comp_node));
  8153. } CATCH_ALL(-1)
  8154. }
  8155. if (scope) {
  8156. try {
  8157. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8158. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8159. } CATCH_ALL(-1)
  8160. }
  8161. return 0;
  8162. }
  8163. PyGetSetDef PyOp(Eye)::py_getsetters[] = {
  8164. {const_cast<char*>("k"), py_get_generic(Eye, k), py_set_generic(Eye, k), const_cast<char*>("k"), NULL},
  8165. {const_cast<char*>("dtype"), py_get_generic(Eye, dtype), py_set_generic(Eye, dtype), const_cast<char*>("dtype"), NULL},
  8166. {const_cast<char*>("comp_node"), py_get_generic(Eye, comp_node), py_set_generic(Eye, comp_node), const_cast<char*>("comp_node"), NULL},
  8167. {NULL} /* Sentinel */
  8168. };
  8169. PyMethodDef PyOp(Eye)::tp_methods[] = {
  8170. {const_cast<char*>("__getstate__"), PyOp(Eye)::getstate, METH_NOARGS, "Eye getstate"},
  8171. {const_cast<char*>("__setstate__"), PyOp(Eye)::setstate, METH_VARARGS, "Eye setstate"},
  8172. {NULL} /* Sentinel */
  8173. };
  8174. void _init_py_Eye(py::module m) {
  8175. using py_op = PyOp(Eye);
  8176. auto& py_type = PyOpType(Eye);
  8177. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8178. py_type.tp_name = "megengine.core._imperative_rt.ops.Eye";
  8179. py_type.tp_basicsize = sizeof(PyOp(Eye));
  8180. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8181. py_type.tp_doc = "Eye";
  8182. py_type.tp_base = &PyOpType(OpDef);
  8183. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8184. py_type.tp_new = py_new_generic<py_op>;
  8185. py_type.tp_init = py_op::py_init;
  8186. py_type.tp_methods = py_op::tp_methods;
  8187. py_type.tp_getset = py_op::py_getsetters;
  8188. mgb_assert(PyType_Ready(&py_type) >= 0);
  8189. PyType_Modified(&py_type);
  8190. m.add_object("Eye", reinterpret_cast<PyObject*>(&py_type));
  8191. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Eye::typeinfo(), &py_type).second);
  8192. }
  8193. PyOpDefBegin(FakeQuant) // {
  8194. static PyGetSetDef py_getsetters[];
  8195. static PyMethodDef tp_methods[];
  8196. static PyObject* getstate(PyObject* self, PyObject*) {
  8197. auto& opdef = reinterpret_cast<PyOp(FakeQuant)*>(self)->inst();
  8198. static_cast<void>(opdef);
  8199. std::unordered_map<std::string, py::object> state {
  8200. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  8201. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  8202. };
  8203. return py::cast(state).release().ptr();
  8204. }
  8205. static PyObject* setstate(PyObject* self, PyObject* args) {
  8206. PyObject* dict = PyTuple_GetItem(args, 0);
  8207. if (!dict) return NULL;
  8208. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8209. auto& opdef = reinterpret_cast<PyOp(FakeQuant)*>(self)->inst();
  8210. static_cast<void>(opdef);
  8211. {
  8212. auto&& iter = state.find("qmin");
  8213. if (iter != state.end()) {
  8214. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  8215. }
  8216. }
  8217. {
  8218. auto&& iter = state.find("qmax");
  8219. if (iter != state.end()) {
  8220. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  8221. }
  8222. }
  8223. Py_RETURN_NONE;
  8224. }
  8225. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8226. // };
  8227. PyOpDefEnd(FakeQuant)
  8228. int PyOp(FakeQuant)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8229. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  8230. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  8231. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  8232. return -1;
  8233. if (qmin) {
  8234. try {
  8235. // TODO: remove this guard which is used for pybind11 implicit conversion
  8236. py::detail::loader_life_support guard{};
  8237. reinterpret_cast<PyOp(FakeQuant)*>(self)->inst().qmin =
  8238. py::cast<decltype(FakeQuant::qmin)>(py::handle(qmin));
  8239. } CATCH_ALL(-1)
  8240. }
  8241. if (qmax) {
  8242. try {
  8243. // TODO: remove this guard which is used for pybind11 implicit conversion
  8244. py::detail::loader_life_support guard{};
  8245. reinterpret_cast<PyOp(FakeQuant)*>(self)->inst().qmax =
  8246. py::cast<decltype(FakeQuant::qmax)>(py::handle(qmax));
  8247. } CATCH_ALL(-1)
  8248. }
  8249. if (scope) {
  8250. try {
  8251. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8252. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8253. } CATCH_ALL(-1)
  8254. }
  8255. return 0;
  8256. }
  8257. PyGetSetDef PyOp(FakeQuant)::py_getsetters[] = {
  8258. {const_cast<char*>("qmin"), py_get_generic(FakeQuant, qmin), py_set_generic(FakeQuant, qmin), const_cast<char*>("qmin"), NULL},
  8259. {const_cast<char*>("qmax"), py_get_generic(FakeQuant, qmax), py_set_generic(FakeQuant, qmax), const_cast<char*>("qmax"), NULL},
  8260. {NULL} /* Sentinel */
  8261. };
  8262. PyMethodDef PyOp(FakeQuant)::tp_methods[] = {
  8263. {const_cast<char*>("__getstate__"), PyOp(FakeQuant)::getstate, METH_NOARGS, "FakeQuant getstate"},
  8264. {const_cast<char*>("__setstate__"), PyOp(FakeQuant)::setstate, METH_VARARGS, "FakeQuant setstate"},
  8265. {NULL} /* Sentinel */
  8266. };
  8267. void _init_py_FakeQuant(py::module m) {
  8268. using py_op = PyOp(FakeQuant);
  8269. auto& py_type = PyOpType(FakeQuant);
  8270. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8271. py_type.tp_name = "megengine.core._imperative_rt.ops.FakeQuant";
  8272. py_type.tp_basicsize = sizeof(PyOp(FakeQuant));
  8273. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8274. py_type.tp_doc = "FakeQuant";
  8275. py_type.tp_base = &PyOpType(OpDef);
  8276. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8277. py_type.tp_new = py_new_generic<py_op>;
  8278. py_type.tp_init = py_op::py_init;
  8279. py_type.tp_methods = py_op::tp_methods;
  8280. py_type.tp_getset = py_op::py_getsetters;
  8281. mgb_assert(PyType_Ready(&py_type) >= 0);
  8282. PyType_Modified(&py_type);
  8283. m.add_object("FakeQuant", reinterpret_cast<PyObject*>(&py_type));
  8284. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FakeQuant::typeinfo(), &py_type).second);
  8285. }
  8286. PyOpDefBegin(FastpathCopy) // {
  8287. static PyGetSetDef py_getsetters[];
  8288. static PyMethodDef tp_methods[];
  8289. static PyObject* getstate(PyObject* self, PyObject*) {
  8290. auto& opdef = reinterpret_cast<PyOp(FastpathCopy)*>(self)->inst();
  8291. static_cast<void>(opdef);
  8292. std::unordered_map<std::string, py::object> state {
  8293. };
  8294. return py::cast(state).release().ptr();
  8295. }
  8296. static PyObject* setstate(PyObject* self, PyObject* args) {
  8297. PyObject* dict = PyTuple_GetItem(args, 0);
  8298. if (!dict) return NULL;
  8299. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8300. auto& opdef = reinterpret_cast<PyOp(FastpathCopy)*>(self)->inst();
  8301. static_cast<void>(opdef);
  8302. Py_RETURN_NONE;
  8303. }
  8304. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8305. // };
  8306. PyOpDefEnd(FastpathCopy)
  8307. int PyOp(FastpathCopy)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8308. return 0;
  8309. }
  8310. PyGetSetDef PyOp(FastpathCopy)::py_getsetters[] = {
  8311. {NULL} /* Sentinel */
  8312. };
  8313. PyMethodDef PyOp(FastpathCopy)::tp_methods[] = {
  8314. {const_cast<char*>("__getstate__"), PyOp(FastpathCopy)::getstate, METH_NOARGS, "FastpathCopy getstate"},
  8315. {const_cast<char*>("__setstate__"), PyOp(FastpathCopy)::setstate, METH_VARARGS, "FastpathCopy setstate"},
  8316. {NULL} /* Sentinel */
  8317. };
  8318. void _init_py_FastpathCopy(py::module m) {
  8319. using py_op = PyOp(FastpathCopy);
  8320. auto& py_type = PyOpType(FastpathCopy);
  8321. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8322. py_type.tp_name = "megengine.core._imperative_rt.ops.FastpathCopy";
  8323. py_type.tp_basicsize = sizeof(PyOp(FastpathCopy));
  8324. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8325. py_type.tp_doc = "FastpathCopy";
  8326. py_type.tp_base = &PyOpType(OpDef);
  8327. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8328. py_type.tp_new = py_new_generic<py_op>;
  8329. py_type.tp_init = py_op::py_init;
  8330. py_type.tp_methods = py_op::tp_methods;
  8331. py_type.tp_getset = py_op::py_getsetters;
  8332. mgb_assert(PyType_Ready(&py_type) >= 0);
  8333. PyType_Modified(&py_type);
  8334. m.add_object("FastpathCopy", reinterpret_cast<PyObject*>(&py_type));
  8335. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FastpathCopy::typeinfo(), &py_type).second);
  8336. }
  8337. PyOpDefBegin(GammaRNG) // {
  8338. static PyGetSetDef py_getsetters[];
  8339. static PyMethodDef tp_methods[];
  8340. static PyObject* getstate(PyObject* self, PyObject*) {
  8341. auto& opdef = reinterpret_cast<PyOp(GammaRNG)*>(self)->inst();
  8342. static_cast<void>(opdef);
  8343. std::unordered_map<std::string, py::object> state {
  8344. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  8345. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  8346. };
  8347. return py::cast(state).release().ptr();
  8348. }
  8349. static PyObject* setstate(PyObject* self, PyObject* args) {
  8350. PyObject* dict = PyTuple_GetItem(args, 0);
  8351. if (!dict) return NULL;
  8352. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8353. auto& opdef = reinterpret_cast<PyOp(GammaRNG)*>(self)->inst();
  8354. static_cast<void>(opdef);
  8355. {
  8356. auto&& iter = state.find("seed");
  8357. if (iter != state.end()) {
  8358. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  8359. }
  8360. }
  8361. {
  8362. auto&& iter = state.find("handle");
  8363. if (iter != state.end()) {
  8364. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  8365. }
  8366. }
  8367. Py_RETURN_NONE;
  8368. }
  8369. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8370. // };
  8371. PyOpDefEnd(GammaRNG)
  8372. int PyOp(GammaRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8373. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  8374. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  8375. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  8376. return -1;
  8377. if (seed) {
  8378. try {
  8379. // TODO: remove this guard which is used for pybind11 implicit conversion
  8380. py::detail::loader_life_support guard{};
  8381. reinterpret_cast<PyOp(GammaRNG)*>(self)->inst().seed =
  8382. py::cast<decltype(GammaRNG::seed)>(py::handle(seed));
  8383. } CATCH_ALL(-1)
  8384. }
  8385. if (handle) {
  8386. try {
  8387. // TODO: remove this guard which is used for pybind11 implicit conversion
  8388. py::detail::loader_life_support guard{};
  8389. reinterpret_cast<PyOp(GammaRNG)*>(self)->inst().handle =
  8390. py::cast<decltype(GammaRNG::handle)>(py::handle(handle));
  8391. } CATCH_ALL(-1)
  8392. }
  8393. if (scope) {
  8394. try {
  8395. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8396. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8397. } CATCH_ALL(-1)
  8398. }
  8399. return 0;
  8400. }
  8401. PyGetSetDef PyOp(GammaRNG)::py_getsetters[] = {
  8402. {const_cast<char*>("seed"), py_get_generic(GammaRNG, seed), py_set_generic(GammaRNG, seed), const_cast<char*>("seed"), NULL},
  8403. {const_cast<char*>("handle"), py_get_generic(GammaRNG, handle), py_set_generic(GammaRNG, handle), const_cast<char*>("handle"), NULL},
  8404. {NULL} /* Sentinel */
  8405. };
  8406. PyMethodDef PyOp(GammaRNG)::tp_methods[] = {
  8407. {const_cast<char*>("__getstate__"), PyOp(GammaRNG)::getstate, METH_NOARGS, "GammaRNG getstate"},
  8408. {const_cast<char*>("__setstate__"), PyOp(GammaRNG)::setstate, METH_VARARGS, "GammaRNG setstate"},
  8409. {NULL} /* Sentinel */
  8410. };
  8411. void _init_py_GammaRNG(py::module m) {
  8412. using py_op = PyOp(GammaRNG);
  8413. auto& py_type = PyOpType(GammaRNG);
  8414. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8415. py_type.tp_name = "megengine.core._imperative_rt.ops.GammaRNG";
  8416. py_type.tp_basicsize = sizeof(PyOp(GammaRNG));
  8417. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8418. py_type.tp_doc = "GammaRNG";
  8419. py_type.tp_base = &PyOpType(OpDef);
  8420. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8421. py_type.tp_new = py_new_generic<py_op>;
  8422. py_type.tp_init = py_op::py_init;
  8423. py_type.tp_methods = py_op::tp_methods;
  8424. py_type.tp_getset = py_op::py_getsetters;
  8425. mgb_assert(PyType_Ready(&py_type) >= 0);
  8426. PyType_Modified(&py_type);
  8427. m.add_object("GammaRNG", reinterpret_cast<PyObject*>(&py_type));
  8428. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GammaRNG::typeinfo(), &py_type).second);
  8429. }
  8430. PyOpDefBegin(GaussianRNG) // {
  8431. static PyGetSetDef py_getsetters[];
  8432. static PyMethodDef tp_methods[];
  8433. static PyObject* getstate(PyObject* self, PyObject*) {
  8434. auto& opdef = reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst();
  8435. static_cast<void>(opdef);
  8436. std::unordered_map<std::string, py::object> state {
  8437. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  8438. {"mean", serialization<decltype(opdef.mean)>::dump(opdef.mean)},
  8439. {"std", serialization<decltype(opdef.std)>::dump(opdef.std)},
  8440. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  8441. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  8442. };
  8443. return py::cast(state).release().ptr();
  8444. }
  8445. static PyObject* setstate(PyObject* self, PyObject* args) {
  8446. PyObject* dict = PyTuple_GetItem(args, 0);
  8447. if (!dict) return NULL;
  8448. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8449. auto& opdef = reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst();
  8450. static_cast<void>(opdef);
  8451. {
  8452. auto&& iter = state.find("seed");
  8453. if (iter != state.end()) {
  8454. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  8455. }
  8456. }
  8457. {
  8458. auto&& iter = state.find("mean");
  8459. if (iter != state.end()) {
  8460. opdef.mean = serialization<decltype(opdef.mean)>::load(iter->second);
  8461. }
  8462. }
  8463. {
  8464. auto&& iter = state.find("std");
  8465. if (iter != state.end()) {
  8466. opdef.std = serialization<decltype(opdef.std)>::load(iter->second);
  8467. }
  8468. }
  8469. {
  8470. auto&& iter = state.find("dtype");
  8471. if (iter != state.end()) {
  8472. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  8473. }
  8474. }
  8475. {
  8476. auto&& iter = state.find("handle");
  8477. if (iter != state.end()) {
  8478. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  8479. }
  8480. }
  8481. Py_RETURN_NONE;
  8482. }
  8483. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8484. // };
  8485. PyOpDefEnd(GaussianRNG)
  8486. int PyOp(GaussianRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8487. static const char* kwlist[] = {"seed", "mean", "std", "dtype", "handle", "scope", NULL};
  8488. PyObject *seed = NULL, *mean = NULL, *std = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  8489. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &seed, &mean, &std, &dtype, &handle, &scope))
  8490. return -1;
  8491. if (seed) {
  8492. try {
  8493. // TODO: remove this guard which is used for pybind11 implicit conversion
  8494. py::detail::loader_life_support guard{};
  8495. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().seed =
  8496. py::cast<decltype(GaussianRNG::seed)>(py::handle(seed));
  8497. } CATCH_ALL(-1)
  8498. }
  8499. if (mean) {
  8500. try {
  8501. // TODO: remove this guard which is used for pybind11 implicit conversion
  8502. py::detail::loader_life_support guard{};
  8503. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().mean =
  8504. py::cast<decltype(GaussianRNG::mean)>(py::handle(mean));
  8505. } CATCH_ALL(-1)
  8506. }
  8507. if (std) {
  8508. try {
  8509. // TODO: remove this guard which is used for pybind11 implicit conversion
  8510. py::detail::loader_life_support guard{};
  8511. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().std =
  8512. py::cast<decltype(GaussianRNG::std)>(py::handle(std));
  8513. } CATCH_ALL(-1)
  8514. }
  8515. if (dtype) {
  8516. try {
  8517. // TODO: remove this guard which is used for pybind11 implicit conversion
  8518. py::detail::loader_life_support guard{};
  8519. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().dtype =
  8520. py::cast<decltype(GaussianRNG::dtype)>(py::handle(dtype));
  8521. } CATCH_ALL(-1)
  8522. }
  8523. if (handle) {
  8524. try {
  8525. // TODO: remove this guard which is used for pybind11 implicit conversion
  8526. py::detail::loader_life_support guard{};
  8527. reinterpret_cast<PyOp(GaussianRNG)*>(self)->inst().handle =
  8528. py::cast<decltype(GaussianRNG::handle)>(py::handle(handle));
  8529. } CATCH_ALL(-1)
  8530. }
  8531. if (scope) {
  8532. try {
  8533. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8534. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8535. } CATCH_ALL(-1)
  8536. }
  8537. return 0;
  8538. }
  8539. PyGetSetDef PyOp(GaussianRNG)::py_getsetters[] = {
  8540. {const_cast<char*>("seed"), py_get_generic(GaussianRNG, seed), py_set_generic(GaussianRNG, seed), const_cast<char*>("seed"), NULL},
  8541. {const_cast<char*>("mean"), py_get_generic(GaussianRNG, mean), py_set_generic(GaussianRNG, mean), const_cast<char*>("mean"), NULL},
  8542. {const_cast<char*>("std"), py_get_generic(GaussianRNG, std), py_set_generic(GaussianRNG, std), const_cast<char*>("std"), NULL},
  8543. {const_cast<char*>("dtype"), py_get_generic(GaussianRNG, dtype), py_set_generic(GaussianRNG, dtype), const_cast<char*>("dtype"), NULL},
  8544. {const_cast<char*>("handle"), py_get_generic(GaussianRNG, handle), py_set_generic(GaussianRNG, handle), const_cast<char*>("handle"), NULL},
  8545. {NULL} /* Sentinel */
  8546. };
  8547. PyMethodDef PyOp(GaussianRNG)::tp_methods[] = {
  8548. {const_cast<char*>("__getstate__"), PyOp(GaussianRNG)::getstate, METH_NOARGS, "GaussianRNG getstate"},
  8549. {const_cast<char*>("__setstate__"), PyOp(GaussianRNG)::setstate, METH_VARARGS, "GaussianRNG setstate"},
  8550. {NULL} /* Sentinel */
  8551. };
  8552. void _init_py_GaussianRNG(py::module m) {
  8553. using py_op = PyOp(GaussianRNG);
  8554. auto& py_type = PyOpType(GaussianRNG);
  8555. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8556. py_type.tp_name = "megengine.core._imperative_rt.ops.GaussianRNG";
  8557. py_type.tp_basicsize = sizeof(PyOp(GaussianRNG));
  8558. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8559. py_type.tp_doc = "GaussianRNG";
  8560. py_type.tp_base = &PyOpType(OpDef);
  8561. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8562. py_type.tp_new = py_new_generic<py_op>;
  8563. py_type.tp_init = py_op::py_init;
  8564. py_type.tp_methods = py_op::tp_methods;
  8565. py_type.tp_getset = py_op::py_getsetters;
  8566. mgb_assert(PyType_Ready(&py_type) >= 0);
  8567. PyType_Modified(&py_type);
  8568. m.add_object("GaussianRNG", reinterpret_cast<PyObject*>(&py_type));
  8569. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GaussianRNG::typeinfo(), &py_type).second);
  8570. }
  8571. PyOpDefBegin(GetVarShape) // {
  8572. static PyGetSetDef py_getsetters[];
  8573. static PyMethodDef tp_methods[];
  8574. static PyObject* getstate(PyObject* self, PyObject*) {
  8575. auto& opdef = reinterpret_cast<PyOp(GetVarShape)*>(self)->inst();
  8576. static_cast<void>(opdef);
  8577. std::unordered_map<std::string, py::object> state {
  8578. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  8579. };
  8580. return py::cast(state).release().ptr();
  8581. }
  8582. static PyObject* setstate(PyObject* self, PyObject* args) {
  8583. PyObject* dict = PyTuple_GetItem(args, 0);
  8584. if (!dict) return NULL;
  8585. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8586. auto& opdef = reinterpret_cast<PyOp(GetVarShape)*>(self)->inst();
  8587. static_cast<void>(opdef);
  8588. {
  8589. auto&& iter = state.find("axis");
  8590. if (iter != state.end()) {
  8591. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  8592. }
  8593. }
  8594. Py_RETURN_NONE;
  8595. }
  8596. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8597. // };
  8598. PyOpDefEnd(GetVarShape)
  8599. int PyOp(GetVarShape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8600. static const char* kwlist[] = {"axis", "scope", NULL};
  8601. PyObject *axis = NULL, *scope = NULL;
  8602. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  8603. return -1;
  8604. if (axis) {
  8605. try {
  8606. // TODO: remove this guard which is used for pybind11 implicit conversion
  8607. py::detail::loader_life_support guard{};
  8608. reinterpret_cast<PyOp(GetVarShape)*>(self)->inst().axis =
  8609. py::cast<decltype(GetVarShape::axis)>(py::handle(axis));
  8610. } CATCH_ALL(-1)
  8611. }
  8612. if (scope) {
  8613. try {
  8614. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8615. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8616. } CATCH_ALL(-1)
  8617. }
  8618. return 0;
  8619. }
  8620. PyGetSetDef PyOp(GetVarShape)::py_getsetters[] = {
  8621. {const_cast<char*>("axis"), py_get_generic(GetVarShape, axis), py_set_generic(GetVarShape, axis), const_cast<char*>("axis"), NULL},
  8622. {NULL} /* Sentinel */
  8623. };
  8624. PyMethodDef PyOp(GetVarShape)::tp_methods[] = {
  8625. {const_cast<char*>("__getstate__"), PyOp(GetVarShape)::getstate, METH_NOARGS, "GetVarShape getstate"},
  8626. {const_cast<char*>("__setstate__"), PyOp(GetVarShape)::setstate, METH_VARARGS, "GetVarShape setstate"},
  8627. {NULL} /* Sentinel */
  8628. };
  8629. void _init_py_GetVarShape(py::module m) {
  8630. using py_op = PyOp(GetVarShape);
  8631. auto& py_type = PyOpType(GetVarShape);
  8632. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8633. py_type.tp_name = "megengine.core._imperative_rt.ops.GetVarShape";
  8634. py_type.tp_basicsize = sizeof(PyOp(GetVarShape));
  8635. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8636. py_type.tp_doc = "GetVarShape";
  8637. py_type.tp_base = &PyOpType(OpDef);
  8638. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8639. py_type.tp_new = py_new_generic<py_op>;
  8640. py_type.tp_init = py_op::py_init;
  8641. py_type.tp_methods = py_op::tp_methods;
  8642. py_type.tp_getset = py_op::py_getsetters;
  8643. mgb_assert(PyType_Ready(&py_type) >= 0);
  8644. PyType_Modified(&py_type);
  8645. m.add_object("GetVarShape", reinterpret_cast<PyObject*>(&py_type));
  8646. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GetVarShape::typeinfo(), &py_type).second);
  8647. }
  8648. void _init_py_GroupLocal_Mode(PyTypeObject& py_type) {
  8649. auto& e_type = EnumWrapper<GroupLocal::Mode>::type;
  8650. Py_INCREF(e_type);
  8651. mgb_assert(PyDict_SetItemString(
  8652. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8653. }
  8654. void _init_py_GroupLocal_Sparse(PyTypeObject& py_type) {
  8655. auto& e_type = EnumWrapper<GroupLocal::Sparse>::type;
  8656. Py_INCREF(e_type);
  8657. mgb_assert(PyDict_SetItemString(
  8658. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8659. }
  8660. void _init_py_GroupLocal_Format(PyTypeObject& py_type) {
  8661. auto& e_type = EnumWrapper<GroupLocal::Format>::type;
  8662. Py_INCREF(e_type);
  8663. mgb_assert(PyDict_SetItemString(
  8664. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8665. }
  8666. void _init_py_GroupLocal_ComputeMode(PyTypeObject& py_type) {
  8667. auto& e_type = EnumWrapper<GroupLocal::ComputeMode>::type;
  8668. Py_INCREF(e_type);
  8669. mgb_assert(PyDict_SetItemString(
  8670. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8671. }
  8672. PyOpDefBegin(GroupLocal) // {
  8673. static PyGetSetDef py_getsetters[];
  8674. static PyMethodDef tp_methods[];
  8675. static PyObject* getstate(PyObject* self, PyObject*) {
  8676. auto& opdef = reinterpret_cast<PyOp(GroupLocal)*>(self)->inst();
  8677. static_cast<void>(opdef);
  8678. std::unordered_map<std::string, py::object> state {
  8679. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  8680. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  8681. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  8682. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  8683. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  8684. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  8685. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  8686. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  8687. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  8688. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)}
  8689. };
  8690. return py::cast(state).release().ptr();
  8691. }
  8692. static PyObject* setstate(PyObject* self, PyObject* args) {
  8693. PyObject* dict = PyTuple_GetItem(args, 0);
  8694. if (!dict) return NULL;
  8695. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8696. auto& opdef = reinterpret_cast<PyOp(GroupLocal)*>(self)->inst();
  8697. static_cast<void>(opdef);
  8698. {
  8699. auto&& iter = state.find("mode");
  8700. if (iter != state.end()) {
  8701. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  8702. }
  8703. }
  8704. {
  8705. auto&& iter = state.find("pad_h");
  8706. if (iter != state.end()) {
  8707. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  8708. }
  8709. }
  8710. {
  8711. auto&& iter = state.find("pad_w");
  8712. if (iter != state.end()) {
  8713. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  8714. }
  8715. }
  8716. {
  8717. auto&& iter = state.find("stride_h");
  8718. if (iter != state.end()) {
  8719. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  8720. }
  8721. }
  8722. {
  8723. auto&& iter = state.find("stride_w");
  8724. if (iter != state.end()) {
  8725. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  8726. }
  8727. }
  8728. {
  8729. auto&& iter = state.find("dilate_h");
  8730. if (iter != state.end()) {
  8731. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  8732. }
  8733. }
  8734. {
  8735. auto&& iter = state.find("dilate_w");
  8736. if (iter != state.end()) {
  8737. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  8738. }
  8739. }
  8740. {
  8741. auto&& iter = state.find("sparse");
  8742. if (iter != state.end()) {
  8743. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  8744. }
  8745. }
  8746. {
  8747. auto&& iter = state.find("format");
  8748. if (iter != state.end()) {
  8749. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  8750. }
  8751. }
  8752. {
  8753. auto&& iter = state.find("compute_mode");
  8754. if (iter != state.end()) {
  8755. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  8756. }
  8757. }
  8758. Py_RETURN_NONE;
  8759. }
  8760. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8761. // };
  8762. PyOpDefEnd(GroupLocal)
  8763. int PyOp(GroupLocal)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8764. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL};
  8765. 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;
  8766. 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))
  8767. return -1;
  8768. if (mode) {
  8769. try {
  8770. // TODO: remove this guard which is used for pybind11 implicit conversion
  8771. py::detail::loader_life_support guard{};
  8772. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().mode =
  8773. py::cast<decltype(GroupLocal::mode)>(py::handle(mode));
  8774. } CATCH_ALL(-1)
  8775. }
  8776. if (pad_h) {
  8777. try {
  8778. // TODO: remove this guard which is used for pybind11 implicit conversion
  8779. py::detail::loader_life_support guard{};
  8780. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().pad_h =
  8781. py::cast<decltype(GroupLocal::pad_h)>(py::handle(pad_h));
  8782. } CATCH_ALL(-1)
  8783. }
  8784. if (pad_w) {
  8785. try {
  8786. // TODO: remove this guard which is used for pybind11 implicit conversion
  8787. py::detail::loader_life_support guard{};
  8788. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().pad_w =
  8789. py::cast<decltype(GroupLocal::pad_w)>(py::handle(pad_w));
  8790. } CATCH_ALL(-1)
  8791. }
  8792. if (stride_h) {
  8793. try {
  8794. // TODO: remove this guard which is used for pybind11 implicit conversion
  8795. py::detail::loader_life_support guard{};
  8796. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().stride_h =
  8797. py::cast<decltype(GroupLocal::stride_h)>(py::handle(stride_h));
  8798. } CATCH_ALL(-1)
  8799. }
  8800. if (stride_w) {
  8801. try {
  8802. // TODO: remove this guard which is used for pybind11 implicit conversion
  8803. py::detail::loader_life_support guard{};
  8804. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().stride_w =
  8805. py::cast<decltype(GroupLocal::stride_w)>(py::handle(stride_w));
  8806. } CATCH_ALL(-1)
  8807. }
  8808. if (dilate_h) {
  8809. try {
  8810. // TODO: remove this guard which is used for pybind11 implicit conversion
  8811. py::detail::loader_life_support guard{};
  8812. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().dilate_h =
  8813. py::cast<decltype(GroupLocal::dilate_h)>(py::handle(dilate_h));
  8814. } CATCH_ALL(-1)
  8815. }
  8816. if (dilate_w) {
  8817. try {
  8818. // TODO: remove this guard which is used for pybind11 implicit conversion
  8819. py::detail::loader_life_support guard{};
  8820. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().dilate_w =
  8821. py::cast<decltype(GroupLocal::dilate_w)>(py::handle(dilate_w));
  8822. } CATCH_ALL(-1)
  8823. }
  8824. if (sparse) {
  8825. try {
  8826. // TODO: remove this guard which is used for pybind11 implicit conversion
  8827. py::detail::loader_life_support guard{};
  8828. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().sparse =
  8829. py::cast<decltype(GroupLocal::sparse)>(py::handle(sparse));
  8830. } CATCH_ALL(-1)
  8831. }
  8832. if (format) {
  8833. try {
  8834. // TODO: remove this guard which is used for pybind11 implicit conversion
  8835. py::detail::loader_life_support guard{};
  8836. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().format =
  8837. py::cast<decltype(GroupLocal::format)>(py::handle(format));
  8838. } CATCH_ALL(-1)
  8839. }
  8840. if (compute_mode) {
  8841. try {
  8842. // TODO: remove this guard which is used for pybind11 implicit conversion
  8843. py::detail::loader_life_support guard{};
  8844. reinterpret_cast<PyOp(GroupLocal)*>(self)->inst().compute_mode =
  8845. py::cast<decltype(GroupLocal::compute_mode)>(py::handle(compute_mode));
  8846. } CATCH_ALL(-1)
  8847. }
  8848. if (scope) {
  8849. try {
  8850. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8851. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8852. } CATCH_ALL(-1)
  8853. }
  8854. return 0;
  8855. }
  8856. PyGetSetDef PyOp(GroupLocal)::py_getsetters[] = {
  8857. {const_cast<char*>("mode"), py_get_generic(GroupLocal, mode), py_set_generic(GroupLocal, mode), const_cast<char*>("mode"), NULL},
  8858. {const_cast<char*>("pad_h"), py_get_generic(GroupLocal, pad_h), py_set_generic(GroupLocal, pad_h), const_cast<char*>("pad_h"), NULL},
  8859. {const_cast<char*>("pad_w"), py_get_generic(GroupLocal, pad_w), py_set_generic(GroupLocal, pad_w), const_cast<char*>("pad_w"), NULL},
  8860. {const_cast<char*>("stride_h"), py_get_generic(GroupLocal, stride_h), py_set_generic(GroupLocal, stride_h), const_cast<char*>("stride_h"), NULL},
  8861. {const_cast<char*>("stride_w"), py_get_generic(GroupLocal, stride_w), py_set_generic(GroupLocal, stride_w), const_cast<char*>("stride_w"), NULL},
  8862. {const_cast<char*>("dilate_h"), py_get_generic(GroupLocal, dilate_h), py_set_generic(GroupLocal, dilate_h), const_cast<char*>("dilate_h"), NULL},
  8863. {const_cast<char*>("dilate_w"), py_get_generic(GroupLocal, dilate_w), py_set_generic(GroupLocal, dilate_w), const_cast<char*>("dilate_w"), NULL},
  8864. {const_cast<char*>("sparse"), py_get_generic(GroupLocal, sparse), py_set_generic(GroupLocal, sparse), const_cast<char*>("sparse"), NULL},
  8865. {const_cast<char*>("format"), py_get_generic(GroupLocal, format), py_set_generic(GroupLocal, format), const_cast<char*>("format"), NULL},
  8866. {const_cast<char*>("compute_mode"), py_get_generic(GroupLocal, compute_mode), py_set_generic(GroupLocal, compute_mode), const_cast<char*>("compute_mode"), NULL},
  8867. {NULL} /* Sentinel */
  8868. };
  8869. PyMethodDef PyOp(GroupLocal)::tp_methods[] = {
  8870. {const_cast<char*>("__getstate__"), PyOp(GroupLocal)::getstate, METH_NOARGS, "GroupLocal getstate"},
  8871. {const_cast<char*>("__setstate__"), PyOp(GroupLocal)::setstate, METH_VARARGS, "GroupLocal setstate"},
  8872. {NULL} /* Sentinel */
  8873. };
  8874. void _init_py_GroupLocal(py::module m) {
  8875. using py_op = PyOp(GroupLocal);
  8876. auto& py_type = PyOpType(GroupLocal);
  8877. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  8878. py_type.tp_name = "megengine.core._imperative_rt.ops.GroupLocal";
  8879. py_type.tp_basicsize = sizeof(PyOp(GroupLocal));
  8880. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  8881. py_type.tp_doc = "GroupLocal";
  8882. py_type.tp_base = &PyOpType(OpDef);
  8883. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  8884. py_type.tp_new = py_new_generic<py_op>;
  8885. py_type.tp_init = py_op::py_init;
  8886. py_type.tp_methods = py_op::tp_methods;
  8887. py_type.tp_getset = py_op::py_getsetters;
  8888. mgb_assert(PyType_Ready(&py_type) >= 0);
  8889. _init_py_GroupLocal_Mode(py_type);
  8890. _init_py_GroupLocal_Sparse(py_type);
  8891. _init_py_GroupLocal_Format(py_type);
  8892. _init_py_GroupLocal_ComputeMode(py_type);
  8893. PyType_Modified(&py_type);
  8894. m.add_object("GroupLocal", reinterpret_cast<PyObject*>(&py_type));
  8895. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GroupLocal::typeinfo(), &py_type).second);
  8896. }
  8897. void _init_py_GroupNorm_Format(PyTypeObject& py_type) {
  8898. auto& e_type = EnumWrapper<GroupNorm::Format>::type;
  8899. Py_INCREF(e_type);
  8900. mgb_assert(PyDict_SetItemString(
  8901. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  8902. }
  8903. PyOpDefBegin(GroupNorm) // {
  8904. static PyGetSetDef py_getsetters[];
  8905. static PyMethodDef tp_methods[];
  8906. static PyObject* getstate(PyObject* self, PyObject*) {
  8907. auto& opdef = reinterpret_cast<PyOp(GroupNorm)*>(self)->inst();
  8908. static_cast<void>(opdef);
  8909. std::unordered_map<std::string, py::object> state {
  8910. {"affine", serialization<decltype(opdef.affine)>::dump(opdef.affine)},
  8911. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  8912. {"group", serialization<decltype(opdef.group)>::dump(opdef.group)},
  8913. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  8914. };
  8915. return py::cast(state).release().ptr();
  8916. }
  8917. static PyObject* setstate(PyObject* self, PyObject* args) {
  8918. PyObject* dict = PyTuple_GetItem(args, 0);
  8919. if (!dict) return NULL;
  8920. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  8921. auto& opdef = reinterpret_cast<PyOp(GroupNorm)*>(self)->inst();
  8922. static_cast<void>(opdef);
  8923. {
  8924. auto&& iter = state.find("affine");
  8925. if (iter != state.end()) {
  8926. opdef.affine = serialization<decltype(opdef.affine)>::load(iter->second);
  8927. }
  8928. }
  8929. {
  8930. auto&& iter = state.find("eps");
  8931. if (iter != state.end()) {
  8932. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  8933. }
  8934. }
  8935. {
  8936. auto&& iter = state.find("group");
  8937. if (iter != state.end()) {
  8938. opdef.group = serialization<decltype(opdef.group)>::load(iter->second);
  8939. }
  8940. }
  8941. {
  8942. auto&& iter = state.find("format");
  8943. if (iter != state.end()) {
  8944. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  8945. }
  8946. }
  8947. Py_RETURN_NONE;
  8948. }
  8949. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  8950. // };
  8951. PyOpDefEnd(GroupNorm)
  8952. int PyOp(GroupNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  8953. static const char* kwlist[] = {"affine", "eps", "group", "format", "scope", NULL};
  8954. PyObject *affine = NULL, *eps = NULL, *group = NULL, *format = NULL, *scope = NULL;
  8955. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &affine, &eps, &group, &format, &scope))
  8956. return -1;
  8957. if (affine) {
  8958. try {
  8959. // TODO: remove this guard which is used for pybind11 implicit conversion
  8960. py::detail::loader_life_support guard{};
  8961. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().affine =
  8962. py::cast<decltype(GroupNorm::affine)>(py::handle(affine));
  8963. } CATCH_ALL(-1)
  8964. }
  8965. if (eps) {
  8966. try {
  8967. // TODO: remove this guard which is used for pybind11 implicit conversion
  8968. py::detail::loader_life_support guard{};
  8969. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().eps =
  8970. py::cast<decltype(GroupNorm::eps)>(py::handle(eps));
  8971. } CATCH_ALL(-1)
  8972. }
  8973. if (group) {
  8974. try {
  8975. // TODO: remove this guard which is used for pybind11 implicit conversion
  8976. py::detail::loader_life_support guard{};
  8977. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().group =
  8978. py::cast<decltype(GroupNorm::group)>(py::handle(group));
  8979. } CATCH_ALL(-1)
  8980. }
  8981. if (format) {
  8982. try {
  8983. // TODO: remove this guard which is used for pybind11 implicit conversion
  8984. py::detail::loader_life_support guard{};
  8985. reinterpret_cast<PyOp(GroupNorm)*>(self)->inst().format =
  8986. py::cast<decltype(GroupNorm::format)>(py::handle(format));
  8987. } CATCH_ALL(-1)
  8988. }
  8989. if (scope) {
  8990. try {
  8991. reinterpret_cast<PyOp(OpDef)*>(self)->op
  8992. ->set_scope(py::cast<std::string>(py::handle(scope)));
  8993. } CATCH_ALL(-1)
  8994. }
  8995. return 0;
  8996. }
  8997. PyGetSetDef PyOp(GroupNorm)::py_getsetters[] = {
  8998. {const_cast<char*>("affine"), py_get_generic(GroupNorm, affine), py_set_generic(GroupNorm, affine), const_cast<char*>("affine"), NULL},
  8999. {const_cast<char*>("eps"), py_get_generic(GroupNorm, eps), py_set_generic(GroupNorm, eps), const_cast<char*>("eps"), NULL},
  9000. {const_cast<char*>("group"), py_get_generic(GroupNorm, group), py_set_generic(GroupNorm, group), const_cast<char*>("group"), NULL},
  9001. {const_cast<char*>("format"), py_get_generic(GroupNorm, format), py_set_generic(GroupNorm, format), const_cast<char*>("format"), NULL},
  9002. {NULL} /* Sentinel */
  9003. };
  9004. PyMethodDef PyOp(GroupNorm)::tp_methods[] = {
  9005. {const_cast<char*>("__getstate__"), PyOp(GroupNorm)::getstate, METH_NOARGS, "GroupNorm getstate"},
  9006. {const_cast<char*>("__setstate__"), PyOp(GroupNorm)::setstate, METH_VARARGS, "GroupNorm setstate"},
  9007. {NULL} /* Sentinel */
  9008. };
  9009. void _init_py_GroupNorm(py::module m) {
  9010. using py_op = PyOp(GroupNorm);
  9011. auto& py_type = PyOpType(GroupNorm);
  9012. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9013. py_type.tp_name = "megengine.core._imperative_rt.ops.GroupNorm";
  9014. py_type.tp_basicsize = sizeof(PyOp(GroupNorm));
  9015. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9016. py_type.tp_doc = "GroupNorm";
  9017. py_type.tp_base = &PyOpType(OpDef);
  9018. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9019. py_type.tp_new = py_new_generic<py_op>;
  9020. py_type.tp_init = py_op::py_init;
  9021. py_type.tp_methods = py_op::tp_methods;
  9022. py_type.tp_getset = py_op::py_getsetters;
  9023. mgb_assert(PyType_Ready(&py_type) >= 0);
  9024. _init_py_GroupNorm_Format(py_type);
  9025. PyType_Modified(&py_type);
  9026. m.add_object("GroupNorm", reinterpret_cast<PyObject*>(&py_type));
  9027. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GroupNorm::typeinfo(), &py_type).second);
  9028. }
  9029. PyOpDefBegin(Identity) // {
  9030. static PyGetSetDef py_getsetters[];
  9031. static PyMethodDef tp_methods[];
  9032. static PyObject* getstate(PyObject* self, PyObject*) {
  9033. auto& opdef = reinterpret_cast<PyOp(Identity)*>(self)->inst();
  9034. static_cast<void>(opdef);
  9035. std::unordered_map<std::string, py::object> state {
  9036. };
  9037. return py::cast(state).release().ptr();
  9038. }
  9039. static PyObject* setstate(PyObject* self, PyObject* args) {
  9040. PyObject* dict = PyTuple_GetItem(args, 0);
  9041. if (!dict) return NULL;
  9042. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9043. auto& opdef = reinterpret_cast<PyOp(Identity)*>(self)->inst();
  9044. static_cast<void>(opdef);
  9045. Py_RETURN_NONE;
  9046. }
  9047. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9048. // };
  9049. PyOpDefEnd(Identity)
  9050. int PyOp(Identity)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9051. return 0;
  9052. }
  9053. PyGetSetDef PyOp(Identity)::py_getsetters[] = {
  9054. {NULL} /* Sentinel */
  9055. };
  9056. PyMethodDef PyOp(Identity)::tp_methods[] = {
  9057. {const_cast<char*>("__getstate__"), PyOp(Identity)::getstate, METH_NOARGS, "Identity getstate"},
  9058. {const_cast<char*>("__setstate__"), PyOp(Identity)::setstate, METH_VARARGS, "Identity setstate"},
  9059. {NULL} /* Sentinel */
  9060. };
  9061. void _init_py_Identity(py::module m) {
  9062. using py_op = PyOp(Identity);
  9063. auto& py_type = PyOpType(Identity);
  9064. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9065. py_type.tp_name = "megengine.core._imperative_rt.ops.Identity";
  9066. py_type.tp_basicsize = sizeof(PyOp(Identity));
  9067. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9068. py_type.tp_doc = "Identity";
  9069. py_type.tp_base = &PyOpType(OpDef);
  9070. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9071. py_type.tp_new = py_new_generic<py_op>;
  9072. py_type.tp_init = py_op::py_init;
  9073. py_type.tp_methods = py_op::tp_methods;
  9074. py_type.tp_getset = py_op::py_getsetters;
  9075. mgb_assert(PyType_Ready(&py_type) >= 0);
  9076. PyType_Modified(&py_type);
  9077. m.add_object("Identity", reinterpret_cast<PyObject*>(&py_type));
  9078. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Identity::typeinfo(), &py_type).second);
  9079. }
  9080. PyOpDefBegin(Images2Neibs) // {
  9081. static PyGetSetDef py_getsetters[];
  9082. static PyMethodDef tp_methods[];
  9083. static PyObject* getstate(PyObject* self, PyObject*) {
  9084. auto& opdef = reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst();
  9085. static_cast<void>(opdef);
  9086. std::unordered_map<std::string, py::object> state {
  9087. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  9088. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  9089. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  9090. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  9091. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  9092. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  9093. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  9094. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)}
  9095. };
  9096. return py::cast(state).release().ptr();
  9097. }
  9098. static PyObject* setstate(PyObject* self, PyObject* args) {
  9099. PyObject* dict = PyTuple_GetItem(args, 0);
  9100. if (!dict) return NULL;
  9101. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9102. auto& opdef = reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst();
  9103. static_cast<void>(opdef);
  9104. {
  9105. auto&& iter = state.find("pad_h");
  9106. if (iter != state.end()) {
  9107. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  9108. }
  9109. }
  9110. {
  9111. auto&& iter = state.find("pad_w");
  9112. if (iter != state.end()) {
  9113. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  9114. }
  9115. }
  9116. {
  9117. auto&& iter = state.find("stride_h");
  9118. if (iter != state.end()) {
  9119. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  9120. }
  9121. }
  9122. {
  9123. auto&& iter = state.find("stride_w");
  9124. if (iter != state.end()) {
  9125. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  9126. }
  9127. }
  9128. {
  9129. auto&& iter = state.find("dilate_h");
  9130. if (iter != state.end()) {
  9131. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  9132. }
  9133. }
  9134. {
  9135. auto&& iter = state.find("dilate_w");
  9136. if (iter != state.end()) {
  9137. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  9138. }
  9139. }
  9140. {
  9141. auto&& iter = state.find("window_h");
  9142. if (iter != state.end()) {
  9143. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  9144. }
  9145. }
  9146. {
  9147. auto&& iter = state.find("window_w");
  9148. if (iter != state.end()) {
  9149. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  9150. }
  9151. }
  9152. Py_RETURN_NONE;
  9153. }
  9154. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9155. // };
  9156. PyOpDefEnd(Images2Neibs)
  9157. int PyOp(Images2Neibs)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9158. static const char* kwlist[] = {"pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "window_h", "window_w", "scope", NULL};
  9159. 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;
  9160. 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))
  9161. return -1;
  9162. if (pad_h) {
  9163. try {
  9164. // TODO: remove this guard which is used for pybind11 implicit conversion
  9165. py::detail::loader_life_support guard{};
  9166. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().pad_h =
  9167. py::cast<decltype(Images2Neibs::pad_h)>(py::handle(pad_h));
  9168. } CATCH_ALL(-1)
  9169. }
  9170. if (pad_w) {
  9171. try {
  9172. // TODO: remove this guard which is used for pybind11 implicit conversion
  9173. py::detail::loader_life_support guard{};
  9174. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().pad_w =
  9175. py::cast<decltype(Images2Neibs::pad_w)>(py::handle(pad_w));
  9176. } CATCH_ALL(-1)
  9177. }
  9178. if (stride_h) {
  9179. try {
  9180. // TODO: remove this guard which is used for pybind11 implicit conversion
  9181. py::detail::loader_life_support guard{};
  9182. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().stride_h =
  9183. py::cast<decltype(Images2Neibs::stride_h)>(py::handle(stride_h));
  9184. } CATCH_ALL(-1)
  9185. }
  9186. if (stride_w) {
  9187. try {
  9188. // TODO: remove this guard which is used for pybind11 implicit conversion
  9189. py::detail::loader_life_support guard{};
  9190. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().stride_w =
  9191. py::cast<decltype(Images2Neibs::stride_w)>(py::handle(stride_w));
  9192. } CATCH_ALL(-1)
  9193. }
  9194. if (dilate_h) {
  9195. try {
  9196. // TODO: remove this guard which is used for pybind11 implicit conversion
  9197. py::detail::loader_life_support guard{};
  9198. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().dilate_h =
  9199. py::cast<decltype(Images2Neibs::dilate_h)>(py::handle(dilate_h));
  9200. } CATCH_ALL(-1)
  9201. }
  9202. if (dilate_w) {
  9203. try {
  9204. // TODO: remove this guard which is used for pybind11 implicit conversion
  9205. py::detail::loader_life_support guard{};
  9206. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().dilate_w =
  9207. py::cast<decltype(Images2Neibs::dilate_w)>(py::handle(dilate_w));
  9208. } CATCH_ALL(-1)
  9209. }
  9210. if (window_h) {
  9211. try {
  9212. // TODO: remove this guard which is used for pybind11 implicit conversion
  9213. py::detail::loader_life_support guard{};
  9214. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().window_h =
  9215. py::cast<decltype(Images2Neibs::window_h)>(py::handle(window_h));
  9216. } CATCH_ALL(-1)
  9217. }
  9218. if (window_w) {
  9219. try {
  9220. // TODO: remove this guard which is used for pybind11 implicit conversion
  9221. py::detail::loader_life_support guard{};
  9222. reinterpret_cast<PyOp(Images2Neibs)*>(self)->inst().window_w =
  9223. py::cast<decltype(Images2Neibs::window_w)>(py::handle(window_w));
  9224. } CATCH_ALL(-1)
  9225. }
  9226. if (scope) {
  9227. try {
  9228. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9229. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9230. } CATCH_ALL(-1)
  9231. }
  9232. return 0;
  9233. }
  9234. PyGetSetDef PyOp(Images2Neibs)::py_getsetters[] = {
  9235. {const_cast<char*>("pad_h"), py_get_generic(Images2Neibs, pad_h), py_set_generic(Images2Neibs, pad_h), const_cast<char*>("pad_h"), NULL},
  9236. {const_cast<char*>("pad_w"), py_get_generic(Images2Neibs, pad_w), py_set_generic(Images2Neibs, pad_w), const_cast<char*>("pad_w"), NULL},
  9237. {const_cast<char*>("stride_h"), py_get_generic(Images2Neibs, stride_h), py_set_generic(Images2Neibs, stride_h), const_cast<char*>("stride_h"), NULL},
  9238. {const_cast<char*>("stride_w"), py_get_generic(Images2Neibs, stride_w), py_set_generic(Images2Neibs, stride_w), const_cast<char*>("stride_w"), NULL},
  9239. {const_cast<char*>("dilate_h"), py_get_generic(Images2Neibs, dilate_h), py_set_generic(Images2Neibs, dilate_h), const_cast<char*>("dilate_h"), NULL},
  9240. {const_cast<char*>("dilate_w"), py_get_generic(Images2Neibs, dilate_w), py_set_generic(Images2Neibs, dilate_w), const_cast<char*>("dilate_w"), NULL},
  9241. {const_cast<char*>("window_h"), py_get_generic(Images2Neibs, window_h), py_set_generic(Images2Neibs, window_h), const_cast<char*>("window_h"), NULL},
  9242. {const_cast<char*>("window_w"), py_get_generic(Images2Neibs, window_w), py_set_generic(Images2Neibs, window_w), const_cast<char*>("window_w"), NULL},
  9243. {NULL} /* Sentinel */
  9244. };
  9245. PyMethodDef PyOp(Images2Neibs)::tp_methods[] = {
  9246. {const_cast<char*>("__getstate__"), PyOp(Images2Neibs)::getstate, METH_NOARGS, "Images2Neibs getstate"},
  9247. {const_cast<char*>("__setstate__"), PyOp(Images2Neibs)::setstate, METH_VARARGS, "Images2Neibs setstate"},
  9248. {NULL} /* Sentinel */
  9249. };
  9250. void _init_py_Images2Neibs(py::module m) {
  9251. using py_op = PyOp(Images2Neibs);
  9252. auto& py_type = PyOpType(Images2Neibs);
  9253. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9254. py_type.tp_name = "megengine.core._imperative_rt.ops.Images2Neibs";
  9255. py_type.tp_basicsize = sizeof(PyOp(Images2Neibs));
  9256. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9257. py_type.tp_doc = "Images2Neibs";
  9258. py_type.tp_base = &PyOpType(OpDef);
  9259. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9260. py_type.tp_new = py_new_generic<py_op>;
  9261. py_type.tp_init = py_op::py_init;
  9262. py_type.tp_methods = py_op::tp_methods;
  9263. py_type.tp_getset = py_op::py_getsetters;
  9264. mgb_assert(PyType_Ready(&py_type) >= 0);
  9265. PyType_Modified(&py_type);
  9266. m.add_object("Images2Neibs", reinterpret_cast<PyObject*>(&py_type));
  9267. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Images2Neibs::typeinfo(), &py_type).second);
  9268. }
  9269. PyOpDefBegin(IncrMeshIndexing) // {
  9270. static PyGetSetDef py_getsetters[];
  9271. static PyMethodDef tp_methods[];
  9272. static PyObject* getstate(PyObject* self, PyObject*) {
  9273. auto& opdef = reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst();
  9274. static_cast<void>(opdef);
  9275. std::unordered_map<std::string, py::object> state {
  9276. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9277. };
  9278. return py::cast(state).release().ptr();
  9279. }
  9280. static PyObject* setstate(PyObject* self, PyObject* args) {
  9281. PyObject* dict = PyTuple_GetItem(args, 0);
  9282. if (!dict) return NULL;
  9283. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9284. auto& opdef = reinterpret_cast<PyOp(IncrMeshIndexing)*>(self)->inst();
  9285. static_cast<void>(opdef);
  9286. {
  9287. auto&& iter = state.find("items");
  9288. if (iter != state.end()) {
  9289. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9290. }
  9291. }
  9292. Py_RETURN_NONE;
  9293. }
  9294. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9295. // };
  9296. PyOpDefEnd(IncrMeshIndexing)
  9297. int PyOp(IncrMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9298. static const char* kwlist[] = {"items", "scope", NULL};
  9299. PyObject *items = NULL, *scope = NULL;
  9300. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9301. return -1;
  9302. if (items) {
  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(IncrMeshIndexing)*>(self)->inst().items =
  9307. py::cast<decltype(IncrMeshIndexing::items)>(py::handle(items));
  9308. } CATCH_ALL(-1)
  9309. }
  9310. if (scope) {
  9311. try {
  9312. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9313. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9314. } CATCH_ALL(-1)
  9315. }
  9316. return 0;
  9317. }
  9318. PyGetSetDef PyOp(IncrMeshIndexing)::py_getsetters[] = {
  9319. {const_cast<char*>("items"), py_get_generic(IncrMeshIndexing, items), py_set_generic(IncrMeshIndexing, items), const_cast<char*>("items"), NULL},
  9320. {NULL} /* Sentinel */
  9321. };
  9322. PyMethodDef PyOp(IncrMeshIndexing)::tp_methods[] = {
  9323. {const_cast<char*>("__getstate__"), PyOp(IncrMeshIndexing)::getstate, METH_NOARGS, "IncrMeshIndexing getstate"},
  9324. {const_cast<char*>("__setstate__"), PyOp(IncrMeshIndexing)::setstate, METH_VARARGS, "IncrMeshIndexing setstate"},
  9325. {NULL} /* Sentinel */
  9326. };
  9327. void _init_py_IncrMeshIndexing(py::module m) {
  9328. using py_op = PyOp(IncrMeshIndexing);
  9329. auto& py_type = PyOpType(IncrMeshIndexing);
  9330. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9331. py_type.tp_name = "megengine.core._imperative_rt.ops.IncrMeshIndexing";
  9332. py_type.tp_basicsize = sizeof(PyOp(IncrMeshIndexing));
  9333. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9334. py_type.tp_doc = "IncrMeshIndexing";
  9335. py_type.tp_base = &PyOpType(OpDef);
  9336. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9337. py_type.tp_new = py_new_generic<py_op>;
  9338. py_type.tp_init = py_op::py_init;
  9339. py_type.tp_methods = py_op::tp_methods;
  9340. py_type.tp_getset = py_op::py_getsetters;
  9341. mgb_assert(PyType_Ready(&py_type) >= 0);
  9342. PyType_Modified(&py_type);
  9343. m.add_object("IncrMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  9344. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrMeshIndexing::typeinfo(), &py_type).second);
  9345. }
  9346. PyOpDefBegin(IncrSubtensor) // {
  9347. static PyGetSetDef py_getsetters[];
  9348. static PyMethodDef tp_methods[];
  9349. static PyObject* getstate(PyObject* self, PyObject*) {
  9350. auto& opdef = reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst();
  9351. static_cast<void>(opdef);
  9352. std::unordered_map<std::string, py::object> state {
  9353. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9354. };
  9355. return py::cast(state).release().ptr();
  9356. }
  9357. static PyObject* setstate(PyObject* self, PyObject* args) {
  9358. PyObject* dict = PyTuple_GetItem(args, 0);
  9359. if (!dict) return NULL;
  9360. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9361. auto& opdef = reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst();
  9362. static_cast<void>(opdef);
  9363. {
  9364. auto&& iter = state.find("items");
  9365. if (iter != state.end()) {
  9366. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9367. }
  9368. }
  9369. Py_RETURN_NONE;
  9370. }
  9371. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9372. // };
  9373. PyOpDefEnd(IncrSubtensor)
  9374. int PyOp(IncrSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9375. static const char* kwlist[] = {"items", "scope", NULL};
  9376. PyObject *items = NULL, *scope = NULL;
  9377. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9378. return -1;
  9379. if (items) {
  9380. try {
  9381. // TODO: remove this guard which is used for pybind11 implicit conversion
  9382. py::detail::loader_life_support guard{};
  9383. reinterpret_cast<PyOp(IncrSubtensor)*>(self)->inst().items =
  9384. py::cast<decltype(IncrSubtensor::items)>(py::handle(items));
  9385. } CATCH_ALL(-1)
  9386. }
  9387. if (scope) {
  9388. try {
  9389. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9390. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9391. } CATCH_ALL(-1)
  9392. }
  9393. return 0;
  9394. }
  9395. PyGetSetDef PyOp(IncrSubtensor)::py_getsetters[] = {
  9396. {const_cast<char*>("items"), py_get_generic(IncrSubtensor, items), py_set_generic(IncrSubtensor, items), const_cast<char*>("items"), NULL},
  9397. {NULL} /* Sentinel */
  9398. };
  9399. PyMethodDef PyOp(IncrSubtensor)::tp_methods[] = {
  9400. {const_cast<char*>("__getstate__"), PyOp(IncrSubtensor)::getstate, METH_NOARGS, "IncrSubtensor getstate"},
  9401. {const_cast<char*>("__setstate__"), PyOp(IncrSubtensor)::setstate, METH_VARARGS, "IncrSubtensor setstate"},
  9402. {NULL} /* Sentinel */
  9403. };
  9404. void _init_py_IncrSubtensor(py::module m) {
  9405. using py_op = PyOp(IncrSubtensor);
  9406. auto& py_type = PyOpType(IncrSubtensor);
  9407. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9408. py_type.tp_name = "megengine.core._imperative_rt.ops.IncrSubtensor";
  9409. py_type.tp_basicsize = sizeof(PyOp(IncrSubtensor));
  9410. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9411. py_type.tp_doc = "IncrSubtensor";
  9412. py_type.tp_base = &PyOpType(OpDef);
  9413. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9414. py_type.tp_new = py_new_generic<py_op>;
  9415. py_type.tp_init = py_op::py_init;
  9416. py_type.tp_methods = py_op::tp_methods;
  9417. py_type.tp_getset = py_op::py_getsetters;
  9418. mgb_assert(PyType_Ready(&py_type) >= 0);
  9419. PyType_Modified(&py_type);
  9420. m.add_object("IncrSubtensor", reinterpret_cast<PyObject*>(&py_type));
  9421. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrSubtensor::typeinfo(), &py_type).second);
  9422. }
  9423. PyOpDefBegin(IndexingIncrMultiAxisVec) // {
  9424. static PyGetSetDef py_getsetters[];
  9425. static PyMethodDef tp_methods[];
  9426. static PyObject* getstate(PyObject* self, PyObject*) {
  9427. auto& opdef = reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst();
  9428. static_cast<void>(opdef);
  9429. std::unordered_map<std::string, py::object> state {
  9430. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9431. };
  9432. return py::cast(state).release().ptr();
  9433. }
  9434. static PyObject* setstate(PyObject* self, PyObject* args) {
  9435. PyObject* dict = PyTuple_GetItem(args, 0);
  9436. if (!dict) return NULL;
  9437. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9438. auto& opdef = reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst();
  9439. static_cast<void>(opdef);
  9440. {
  9441. auto&& iter = state.find("items");
  9442. if (iter != state.end()) {
  9443. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9444. }
  9445. }
  9446. Py_RETURN_NONE;
  9447. }
  9448. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9449. // };
  9450. PyOpDefEnd(IndexingIncrMultiAxisVec)
  9451. int PyOp(IndexingIncrMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9452. static const char* kwlist[] = {"items", "scope", NULL};
  9453. PyObject *items = NULL, *scope = NULL;
  9454. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9455. return -1;
  9456. if (items) {
  9457. try {
  9458. // TODO: remove this guard which is used for pybind11 implicit conversion
  9459. py::detail::loader_life_support guard{};
  9460. reinterpret_cast<PyOp(IndexingIncrMultiAxisVec)*>(self)->inst().items =
  9461. py::cast<decltype(IndexingIncrMultiAxisVec::items)>(py::handle(items));
  9462. } CATCH_ALL(-1)
  9463. }
  9464. if (scope) {
  9465. try {
  9466. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9467. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9468. } CATCH_ALL(-1)
  9469. }
  9470. return 0;
  9471. }
  9472. PyGetSetDef PyOp(IndexingIncrMultiAxisVec)::py_getsetters[] = {
  9473. {const_cast<char*>("items"), py_get_generic(IndexingIncrMultiAxisVec, items), py_set_generic(IndexingIncrMultiAxisVec, items), const_cast<char*>("items"), NULL},
  9474. {NULL} /* Sentinel */
  9475. };
  9476. PyMethodDef PyOp(IndexingIncrMultiAxisVec)::tp_methods[] = {
  9477. {const_cast<char*>("__getstate__"), PyOp(IndexingIncrMultiAxisVec)::getstate, METH_NOARGS, "IndexingIncrMultiAxisVec getstate"},
  9478. {const_cast<char*>("__setstate__"), PyOp(IndexingIncrMultiAxisVec)::setstate, METH_VARARGS, "IndexingIncrMultiAxisVec setstate"},
  9479. {NULL} /* Sentinel */
  9480. };
  9481. void _init_py_IndexingIncrMultiAxisVec(py::module m) {
  9482. using py_op = PyOp(IndexingIncrMultiAxisVec);
  9483. auto& py_type = PyOpType(IndexingIncrMultiAxisVec);
  9484. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9485. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingIncrMultiAxisVec";
  9486. py_type.tp_basicsize = sizeof(PyOp(IndexingIncrMultiAxisVec));
  9487. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9488. py_type.tp_doc = "IndexingIncrMultiAxisVec";
  9489. py_type.tp_base = &PyOpType(OpDef);
  9490. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9491. py_type.tp_new = py_new_generic<py_op>;
  9492. py_type.tp_init = py_op::py_init;
  9493. py_type.tp_methods = py_op::tp_methods;
  9494. py_type.tp_getset = py_op::py_getsetters;
  9495. mgb_assert(PyType_Ready(&py_type) >= 0);
  9496. PyType_Modified(&py_type);
  9497. m.add_object("IndexingIncrMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  9498. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingIncrMultiAxisVec::typeinfo(), &py_type).second);
  9499. }
  9500. PyOpDefBegin(IndexingMultiAxisVec) // {
  9501. static PyGetSetDef py_getsetters[];
  9502. static PyMethodDef tp_methods[];
  9503. static PyObject* getstate(PyObject* self, PyObject*) {
  9504. auto& opdef = reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst();
  9505. static_cast<void>(opdef);
  9506. std::unordered_map<std::string, py::object> state {
  9507. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  9508. };
  9509. return py::cast(state).release().ptr();
  9510. }
  9511. static PyObject* setstate(PyObject* self, PyObject* args) {
  9512. PyObject* dict = PyTuple_GetItem(args, 0);
  9513. if (!dict) return NULL;
  9514. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9515. auto& opdef = reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst();
  9516. static_cast<void>(opdef);
  9517. {
  9518. auto&& iter = state.find("items");
  9519. if (iter != state.end()) {
  9520. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9521. }
  9522. }
  9523. Py_RETURN_NONE;
  9524. }
  9525. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9526. // };
  9527. PyOpDefEnd(IndexingMultiAxisVec)
  9528. int PyOp(IndexingMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9529. static const char* kwlist[] = {"items", "scope", NULL};
  9530. PyObject *items = NULL, *scope = NULL;
  9531. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9532. return -1;
  9533. if (items) {
  9534. try {
  9535. // TODO: remove this guard which is used for pybind11 implicit conversion
  9536. py::detail::loader_life_support guard{};
  9537. reinterpret_cast<PyOp(IndexingMultiAxisVec)*>(self)->inst().items =
  9538. py::cast<decltype(IndexingMultiAxisVec::items)>(py::handle(items));
  9539. } CATCH_ALL(-1)
  9540. }
  9541. if (scope) {
  9542. try {
  9543. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9544. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9545. } CATCH_ALL(-1)
  9546. }
  9547. return 0;
  9548. }
  9549. PyGetSetDef PyOp(IndexingMultiAxisVec)::py_getsetters[] = {
  9550. {const_cast<char*>("items"), py_get_generic(IndexingMultiAxisVec, items), py_set_generic(IndexingMultiAxisVec, items), const_cast<char*>("items"), NULL},
  9551. {NULL} /* Sentinel */
  9552. };
  9553. PyMethodDef PyOp(IndexingMultiAxisVec)::tp_methods[] = {
  9554. {const_cast<char*>("__getstate__"), PyOp(IndexingMultiAxisVec)::getstate, METH_NOARGS, "IndexingMultiAxisVec getstate"},
  9555. {const_cast<char*>("__setstate__"), PyOp(IndexingMultiAxisVec)::setstate, METH_VARARGS, "IndexingMultiAxisVec setstate"},
  9556. {NULL} /* Sentinel */
  9557. };
  9558. void _init_py_IndexingMultiAxisVec(py::module m) {
  9559. using py_op = PyOp(IndexingMultiAxisVec);
  9560. auto& py_type = PyOpType(IndexingMultiAxisVec);
  9561. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9562. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingMultiAxisVec";
  9563. py_type.tp_basicsize = sizeof(PyOp(IndexingMultiAxisVec));
  9564. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9565. py_type.tp_doc = "IndexingMultiAxisVec";
  9566. py_type.tp_base = &PyOpType(OpDef);
  9567. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9568. py_type.tp_new = py_new_generic<py_op>;
  9569. py_type.tp_init = py_op::py_init;
  9570. py_type.tp_methods = py_op::tp_methods;
  9571. py_type.tp_getset = py_op::py_getsetters;
  9572. mgb_assert(PyType_Ready(&py_type) >= 0);
  9573. PyType_Modified(&py_type);
  9574. m.add_object("IndexingMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  9575. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingMultiAxisVec::typeinfo(), &py_type).second);
  9576. }
  9577. PyOpDefBegin(IndexingOneHot) // {
  9578. static PyGetSetDef py_getsetters[];
  9579. static PyMethodDef tp_methods[];
  9580. static PyObject* getstate(PyObject* self, PyObject*) {
  9581. auto& opdef = reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst();
  9582. static_cast<void>(opdef);
  9583. std::unordered_map<std::string, py::object> state {
  9584. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  9585. {"ndim", serialization<decltype(opdef.ndim)>::dump(opdef.ndim)}
  9586. };
  9587. return py::cast(state).release().ptr();
  9588. }
  9589. static PyObject* setstate(PyObject* self, PyObject* args) {
  9590. PyObject* dict = PyTuple_GetItem(args, 0);
  9591. if (!dict) return NULL;
  9592. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9593. auto& opdef = reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst();
  9594. static_cast<void>(opdef);
  9595. {
  9596. auto&& iter = state.find("axis");
  9597. if (iter != state.end()) {
  9598. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  9599. }
  9600. }
  9601. {
  9602. auto&& iter = state.find("ndim");
  9603. if (iter != state.end()) {
  9604. opdef.ndim = serialization<decltype(opdef.ndim)>::load(iter->second);
  9605. }
  9606. }
  9607. Py_RETURN_NONE;
  9608. }
  9609. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9610. // };
  9611. PyOpDefEnd(IndexingOneHot)
  9612. int PyOp(IndexingOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9613. static const char* kwlist[] = {"axis", "ndim", "scope", NULL};
  9614. PyObject *axis = NULL, *ndim = NULL, *scope = NULL;
  9615. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &ndim, &scope))
  9616. return -1;
  9617. if (axis) {
  9618. try {
  9619. // TODO: remove this guard which is used for pybind11 implicit conversion
  9620. py::detail::loader_life_support guard{};
  9621. reinterpret_cast<PyOp(IndexingOneHot)*>(self)->inst().axis =
  9622. py::cast<decltype(IndexingOneHot::axis)>(py::handle(axis));
  9623. } CATCH_ALL(-1)
  9624. }
  9625. if (ndim) {
  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(IndexingOneHot)*>(self)->inst().ndim =
  9630. py::cast<decltype(IndexingOneHot::ndim)>(py::handle(ndim));
  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(IndexingOneHot)::py_getsetters[] = {
  9642. {const_cast<char*>("axis"), py_get_generic(IndexingOneHot, axis), py_set_generic(IndexingOneHot, axis), const_cast<char*>("axis"), NULL},
  9643. {const_cast<char*>("ndim"), py_get_generic(IndexingOneHot, ndim), py_set_generic(IndexingOneHot, ndim), const_cast<char*>("ndim"), NULL},
  9644. {NULL} /* Sentinel */
  9645. };
  9646. PyMethodDef PyOp(IndexingOneHot)::tp_methods[] = {
  9647. {const_cast<char*>("__getstate__"), PyOp(IndexingOneHot)::getstate, METH_NOARGS, "IndexingOneHot getstate"},
  9648. {const_cast<char*>("__setstate__"), PyOp(IndexingOneHot)::setstate, METH_VARARGS, "IndexingOneHot setstate"},
  9649. {NULL} /* Sentinel */
  9650. };
  9651. void _init_py_IndexingOneHot(py::module m) {
  9652. using py_op = PyOp(IndexingOneHot);
  9653. auto& py_type = PyOpType(IndexingOneHot);
  9654. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9655. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingOneHot";
  9656. py_type.tp_basicsize = sizeof(PyOp(IndexingOneHot));
  9657. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9658. py_type.tp_doc = "IndexingOneHot";
  9659. py_type.tp_base = &PyOpType(OpDef);
  9660. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9661. py_type.tp_new = py_new_generic<py_op>;
  9662. py_type.tp_init = py_op::py_init;
  9663. py_type.tp_methods = py_op::tp_methods;
  9664. py_type.tp_getset = py_op::py_getsetters;
  9665. mgb_assert(PyType_Ready(&py_type) >= 0);
  9666. PyType_Modified(&py_type);
  9667. m.add_object("IndexingOneHot", reinterpret_cast<PyObject*>(&py_type));
  9668. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingOneHot::typeinfo(), &py_type).second);
  9669. }
  9670. PyOpDefBegin(IndexingSetMultiAxisVec) // {
  9671. static PyGetSetDef py_getsetters[];
  9672. static PyMethodDef tp_methods[];
  9673. static PyObject* getstate(PyObject* self, PyObject*) {
  9674. auto& opdef = reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst();
  9675. static_cast<void>(opdef);
  9676. std::unordered_map<std::string, py::object> state {
  9677. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  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(IndexingSetMultiAxisVec)*>(self)->inst();
  9686. static_cast<void>(opdef);
  9687. {
  9688. auto&& iter = state.find("items");
  9689. if (iter != state.end()) {
  9690. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  9691. }
  9692. }
  9693. Py_RETURN_NONE;
  9694. }
  9695. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9696. // };
  9697. PyOpDefEnd(IndexingSetMultiAxisVec)
  9698. int PyOp(IndexingSetMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9699. static const char* kwlist[] = {"items", "scope", NULL};
  9700. PyObject *items = NULL, *scope = NULL;
  9701. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  9702. return -1;
  9703. if (items) {
  9704. try {
  9705. // TODO: remove this guard which is used for pybind11 implicit conversion
  9706. py::detail::loader_life_support guard{};
  9707. reinterpret_cast<PyOp(IndexingSetMultiAxisVec)*>(self)->inst().items =
  9708. py::cast<decltype(IndexingSetMultiAxisVec::items)>(py::handle(items));
  9709. } CATCH_ALL(-1)
  9710. }
  9711. if (scope) {
  9712. try {
  9713. reinterpret_cast<PyOp(OpDef)*>(self)->op
  9714. ->set_scope(py::cast<std::string>(py::handle(scope)));
  9715. } CATCH_ALL(-1)
  9716. }
  9717. return 0;
  9718. }
  9719. PyGetSetDef PyOp(IndexingSetMultiAxisVec)::py_getsetters[] = {
  9720. {const_cast<char*>("items"), py_get_generic(IndexingSetMultiAxisVec, items), py_set_generic(IndexingSetMultiAxisVec, items), const_cast<char*>("items"), NULL},
  9721. {NULL} /* Sentinel */
  9722. };
  9723. PyMethodDef PyOp(IndexingSetMultiAxisVec)::tp_methods[] = {
  9724. {const_cast<char*>("__getstate__"), PyOp(IndexingSetMultiAxisVec)::getstate, METH_NOARGS, "IndexingSetMultiAxisVec getstate"},
  9725. {const_cast<char*>("__setstate__"), PyOp(IndexingSetMultiAxisVec)::setstate, METH_VARARGS, "IndexingSetMultiAxisVec setstate"},
  9726. {NULL} /* Sentinel */
  9727. };
  9728. void _init_py_IndexingSetMultiAxisVec(py::module m) {
  9729. using py_op = PyOp(IndexingSetMultiAxisVec);
  9730. auto& py_type = PyOpType(IndexingSetMultiAxisVec);
  9731. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9732. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetMultiAxisVec";
  9733. py_type.tp_basicsize = sizeof(PyOp(IndexingSetMultiAxisVec));
  9734. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9735. py_type.tp_doc = "IndexingSetMultiAxisVec";
  9736. py_type.tp_base = &PyOpType(OpDef);
  9737. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9738. py_type.tp_new = py_new_generic<py_op>;
  9739. py_type.tp_init = py_op::py_init;
  9740. py_type.tp_methods = py_op::tp_methods;
  9741. py_type.tp_getset = py_op::py_getsetters;
  9742. mgb_assert(PyType_Ready(&py_type) >= 0);
  9743. PyType_Modified(&py_type);
  9744. m.add_object("IndexingSetMultiAxisVec", reinterpret_cast<PyObject*>(&py_type));
  9745. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetMultiAxisVec::typeinfo(), &py_type).second);
  9746. }
  9747. PyOpDefBegin(IndexingSetOneHot) // {
  9748. static PyGetSetDef py_getsetters[];
  9749. static PyMethodDef tp_methods[];
  9750. static PyObject* getstate(PyObject* self, PyObject*) {
  9751. auto& opdef = reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst();
  9752. static_cast<void>(opdef);
  9753. std::unordered_map<std::string, py::object> state {
  9754. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  9755. {"ndim", serialization<decltype(opdef.ndim)>::dump(opdef.ndim)}
  9756. };
  9757. return py::cast(state).release().ptr();
  9758. }
  9759. static PyObject* setstate(PyObject* self, PyObject* args) {
  9760. PyObject* dict = PyTuple_GetItem(args, 0);
  9761. if (!dict) return NULL;
  9762. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9763. auto& opdef = reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst();
  9764. static_cast<void>(opdef);
  9765. {
  9766. auto&& iter = state.find("axis");
  9767. if (iter != state.end()) {
  9768. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  9769. }
  9770. }
  9771. {
  9772. auto&& iter = state.find("ndim");
  9773. if (iter != state.end()) {
  9774. opdef.ndim = serialization<decltype(opdef.ndim)>::load(iter->second);
  9775. }
  9776. }
  9777. Py_RETURN_NONE;
  9778. }
  9779. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9780. // };
  9781. PyOpDefEnd(IndexingSetOneHot)
  9782. int PyOp(IndexingSetOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9783. static const char* kwlist[] = {"axis", "ndim", "scope", NULL};
  9784. PyObject *axis = NULL, *ndim = NULL, *scope = NULL;
  9785. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &ndim, &scope))
  9786. return -1;
  9787. if (axis) {
  9788. try {
  9789. // TODO: remove this guard which is used for pybind11 implicit conversion
  9790. py::detail::loader_life_support guard{};
  9791. reinterpret_cast<PyOp(IndexingSetOneHot)*>(self)->inst().axis =
  9792. py::cast<decltype(IndexingSetOneHot::axis)>(py::handle(axis));
  9793. } CATCH_ALL(-1)
  9794. }
  9795. if (ndim) {
  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(IndexingSetOneHot)*>(self)->inst().ndim =
  9800. py::cast<decltype(IndexingSetOneHot::ndim)>(py::handle(ndim));
  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(IndexingSetOneHot)::py_getsetters[] = {
  9812. {const_cast<char*>("axis"), py_get_generic(IndexingSetOneHot, axis), py_set_generic(IndexingSetOneHot, axis), const_cast<char*>("axis"), NULL},
  9813. {const_cast<char*>("ndim"), py_get_generic(IndexingSetOneHot, ndim), py_set_generic(IndexingSetOneHot, ndim), const_cast<char*>("ndim"), NULL},
  9814. {NULL} /* Sentinel */
  9815. };
  9816. PyMethodDef PyOp(IndexingSetOneHot)::tp_methods[] = {
  9817. {const_cast<char*>("__getstate__"), PyOp(IndexingSetOneHot)::getstate, METH_NOARGS, "IndexingSetOneHot getstate"},
  9818. {const_cast<char*>("__setstate__"), PyOp(IndexingSetOneHot)::setstate, METH_VARARGS, "IndexingSetOneHot setstate"},
  9819. {NULL} /* Sentinel */
  9820. };
  9821. void _init_py_IndexingSetOneHot(py::module m) {
  9822. using py_op = PyOp(IndexingSetOneHot);
  9823. auto& py_type = PyOpType(IndexingSetOneHot);
  9824. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9825. py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetOneHot";
  9826. py_type.tp_basicsize = sizeof(PyOp(IndexingSetOneHot));
  9827. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9828. py_type.tp_doc = "IndexingSetOneHot";
  9829. py_type.tp_base = &PyOpType(OpDef);
  9830. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9831. py_type.tp_new = py_new_generic<py_op>;
  9832. py_type.tp_init = py_op::py_init;
  9833. py_type.tp_methods = py_op::tp_methods;
  9834. py_type.tp_getset = py_op::py_getsetters;
  9835. mgb_assert(PyType_Ready(&py_type) >= 0);
  9836. PyType_Modified(&py_type);
  9837. m.add_object("IndexingSetOneHot", reinterpret_cast<PyObject*>(&py_type));
  9838. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetOneHot::typeinfo(), &py_type).second);
  9839. }
  9840. PyOpDefBegin(InplaceAdd) // {
  9841. static PyGetSetDef py_getsetters[];
  9842. static PyMethodDef tp_methods[];
  9843. static PyObject* getstate(PyObject* self, PyObject*) {
  9844. auto& opdef = reinterpret_cast<PyOp(InplaceAdd)*>(self)->inst();
  9845. static_cast<void>(opdef);
  9846. std::unordered_map<std::string, py::object> state {
  9847. };
  9848. return py::cast(state).release().ptr();
  9849. }
  9850. static PyObject* setstate(PyObject* self, PyObject* args) {
  9851. PyObject* dict = PyTuple_GetItem(args, 0);
  9852. if (!dict) return NULL;
  9853. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9854. auto& opdef = reinterpret_cast<PyOp(InplaceAdd)*>(self)->inst();
  9855. static_cast<void>(opdef);
  9856. Py_RETURN_NONE;
  9857. }
  9858. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9859. // };
  9860. PyOpDefEnd(InplaceAdd)
  9861. int PyOp(InplaceAdd)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9862. return 0;
  9863. }
  9864. PyGetSetDef PyOp(InplaceAdd)::py_getsetters[] = {
  9865. {NULL} /* Sentinel */
  9866. };
  9867. PyMethodDef PyOp(InplaceAdd)::tp_methods[] = {
  9868. {const_cast<char*>("__getstate__"), PyOp(InplaceAdd)::getstate, METH_NOARGS, "InplaceAdd getstate"},
  9869. {const_cast<char*>("__setstate__"), PyOp(InplaceAdd)::setstate, METH_VARARGS, "InplaceAdd setstate"},
  9870. {NULL} /* Sentinel */
  9871. };
  9872. void _init_py_InplaceAdd(py::module m) {
  9873. using py_op = PyOp(InplaceAdd);
  9874. auto& py_type = PyOpType(InplaceAdd);
  9875. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  9876. py_type.tp_name = "megengine.core._imperative_rt.ops.InplaceAdd";
  9877. py_type.tp_basicsize = sizeof(PyOp(InplaceAdd));
  9878. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  9879. py_type.tp_doc = "InplaceAdd";
  9880. py_type.tp_base = &PyOpType(OpDef);
  9881. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  9882. py_type.tp_new = py_new_generic<py_op>;
  9883. py_type.tp_init = py_op::py_init;
  9884. py_type.tp_methods = py_op::tp_methods;
  9885. py_type.tp_getset = py_op::py_getsetters;
  9886. mgb_assert(PyType_Ready(&py_type) >= 0);
  9887. PyType_Modified(&py_type);
  9888. m.add_object("InplaceAdd", reinterpret_cast<PyObject*>(&py_type));
  9889. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(InplaceAdd::typeinfo(), &py_type).second);
  9890. }
  9891. PyOpDefBegin(LAMBUpdate) // {
  9892. static PyGetSetDef py_getsetters[];
  9893. static PyMethodDef tp_methods[];
  9894. static PyObject* getstate(PyObject* self, PyObject*) {
  9895. auto& opdef = reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst();
  9896. static_cast<void>(opdef);
  9897. std::unordered_map<std::string, py::object> state {
  9898. {"beta_1", serialization<decltype(opdef.beta_1)>::dump(opdef.beta_1)},
  9899. {"beta_2", serialization<decltype(opdef.beta_2)>::dump(opdef.beta_2)},
  9900. {"step", serialization<decltype(opdef.step)>::dump(opdef.step)},
  9901. {"lr", serialization<decltype(opdef.lr)>::dump(opdef.lr)},
  9902. {"weight_decay", serialization<decltype(opdef.weight_decay)>::dump(opdef.weight_decay)},
  9903. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  9904. {"bias_correction", serialization<decltype(opdef.bias_correction)>::dump(opdef.bias_correction)},
  9905. {"always_adapt", serialization<decltype(opdef.always_adapt)>::dump(opdef.always_adapt)}
  9906. };
  9907. return py::cast(state).release().ptr();
  9908. }
  9909. static PyObject* setstate(PyObject* self, PyObject* args) {
  9910. PyObject* dict = PyTuple_GetItem(args, 0);
  9911. if (!dict) return NULL;
  9912. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  9913. auto& opdef = reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst();
  9914. static_cast<void>(opdef);
  9915. {
  9916. auto&& iter = state.find("beta_1");
  9917. if (iter != state.end()) {
  9918. opdef.beta_1 = serialization<decltype(opdef.beta_1)>::load(iter->second);
  9919. }
  9920. }
  9921. {
  9922. auto&& iter = state.find("beta_2");
  9923. if (iter != state.end()) {
  9924. opdef.beta_2 = serialization<decltype(opdef.beta_2)>::load(iter->second);
  9925. }
  9926. }
  9927. {
  9928. auto&& iter = state.find("step");
  9929. if (iter != state.end()) {
  9930. opdef.step = serialization<decltype(opdef.step)>::load(iter->second);
  9931. }
  9932. }
  9933. {
  9934. auto&& iter = state.find("lr");
  9935. if (iter != state.end()) {
  9936. opdef.lr = serialization<decltype(opdef.lr)>::load(iter->second);
  9937. }
  9938. }
  9939. {
  9940. auto&& iter = state.find("weight_decay");
  9941. if (iter != state.end()) {
  9942. opdef.weight_decay = serialization<decltype(opdef.weight_decay)>::load(iter->second);
  9943. }
  9944. }
  9945. {
  9946. auto&& iter = state.find("eps");
  9947. if (iter != state.end()) {
  9948. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  9949. }
  9950. }
  9951. {
  9952. auto&& iter = state.find("bias_correction");
  9953. if (iter != state.end()) {
  9954. opdef.bias_correction = serialization<decltype(opdef.bias_correction)>::load(iter->second);
  9955. }
  9956. }
  9957. {
  9958. auto&& iter = state.find("always_adapt");
  9959. if (iter != state.end()) {
  9960. opdef.always_adapt = serialization<decltype(opdef.always_adapt)>::load(iter->second);
  9961. }
  9962. }
  9963. Py_RETURN_NONE;
  9964. }
  9965. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  9966. // };
  9967. PyOpDefEnd(LAMBUpdate)
  9968. int PyOp(LAMBUpdate)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  9969. static const char* kwlist[] = {"beta_1", "beta_2", "step", "lr", "weight_decay", "eps", "bias_correction", "always_adapt", "scope", NULL};
  9970. PyObject *beta_1 = NULL, *beta_2 = NULL, *step = NULL, *lr = NULL, *weight_decay = NULL, *eps = NULL, *bias_correction = NULL, *always_adapt = NULL, *scope = NULL;
  9971. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &beta_1, &beta_2, &step, &lr, &weight_decay, &eps, &bias_correction, &always_adapt, &scope))
  9972. return -1;
  9973. if (beta_1) {
  9974. try {
  9975. // TODO: remove this guard which is used for pybind11 implicit conversion
  9976. py::detail::loader_life_support guard{};
  9977. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().beta_1 =
  9978. py::cast<decltype(LAMBUpdate::beta_1)>(py::handle(beta_1));
  9979. } CATCH_ALL(-1)
  9980. }
  9981. if (beta_2) {
  9982. try {
  9983. // TODO: remove this guard which is used for pybind11 implicit conversion
  9984. py::detail::loader_life_support guard{};
  9985. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().beta_2 =
  9986. py::cast<decltype(LAMBUpdate::beta_2)>(py::handle(beta_2));
  9987. } CATCH_ALL(-1)
  9988. }
  9989. if (step) {
  9990. try {
  9991. // TODO: remove this guard which is used for pybind11 implicit conversion
  9992. py::detail::loader_life_support guard{};
  9993. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().step =
  9994. py::cast<decltype(LAMBUpdate::step)>(py::handle(step));
  9995. } CATCH_ALL(-1)
  9996. }
  9997. if (lr) {
  9998. try {
  9999. // TODO: remove this guard which is used for pybind11 implicit conversion
  10000. py::detail::loader_life_support guard{};
  10001. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().lr =
  10002. py::cast<decltype(LAMBUpdate::lr)>(py::handle(lr));
  10003. } CATCH_ALL(-1)
  10004. }
  10005. if (weight_decay) {
  10006. try {
  10007. // TODO: remove this guard which is used for pybind11 implicit conversion
  10008. py::detail::loader_life_support guard{};
  10009. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().weight_decay =
  10010. py::cast<decltype(LAMBUpdate::weight_decay)>(py::handle(weight_decay));
  10011. } CATCH_ALL(-1)
  10012. }
  10013. if (eps) {
  10014. try {
  10015. // TODO: remove this guard which is used for pybind11 implicit conversion
  10016. py::detail::loader_life_support guard{};
  10017. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().eps =
  10018. py::cast<decltype(LAMBUpdate::eps)>(py::handle(eps));
  10019. } CATCH_ALL(-1)
  10020. }
  10021. if (bias_correction) {
  10022. try {
  10023. // TODO: remove this guard which is used for pybind11 implicit conversion
  10024. py::detail::loader_life_support guard{};
  10025. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().bias_correction =
  10026. py::cast<decltype(LAMBUpdate::bias_correction)>(py::handle(bias_correction));
  10027. } CATCH_ALL(-1)
  10028. }
  10029. if (always_adapt) {
  10030. try {
  10031. // TODO: remove this guard which is used for pybind11 implicit conversion
  10032. py::detail::loader_life_support guard{};
  10033. reinterpret_cast<PyOp(LAMBUpdate)*>(self)->inst().always_adapt =
  10034. py::cast<decltype(LAMBUpdate::always_adapt)>(py::handle(always_adapt));
  10035. } CATCH_ALL(-1)
  10036. }
  10037. if (scope) {
  10038. try {
  10039. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10040. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10041. } CATCH_ALL(-1)
  10042. }
  10043. return 0;
  10044. }
  10045. PyGetSetDef PyOp(LAMBUpdate)::py_getsetters[] = {
  10046. {const_cast<char*>("beta_1"), py_get_generic(LAMBUpdate, beta_1), py_set_generic(LAMBUpdate, beta_1), const_cast<char*>("beta_1"), NULL},
  10047. {const_cast<char*>("beta_2"), py_get_generic(LAMBUpdate, beta_2), py_set_generic(LAMBUpdate, beta_2), const_cast<char*>("beta_2"), NULL},
  10048. {const_cast<char*>("step"), py_get_generic(LAMBUpdate, step), py_set_generic(LAMBUpdate, step), const_cast<char*>("step"), NULL},
  10049. {const_cast<char*>("lr"), py_get_generic(LAMBUpdate, lr), py_set_generic(LAMBUpdate, lr), const_cast<char*>("lr"), NULL},
  10050. {const_cast<char*>("weight_decay"), py_get_generic(LAMBUpdate, weight_decay), py_set_generic(LAMBUpdate, weight_decay), const_cast<char*>("weight_decay"), NULL},
  10051. {const_cast<char*>("eps"), py_get_generic(LAMBUpdate, eps), py_set_generic(LAMBUpdate, eps), const_cast<char*>("eps"), NULL},
  10052. {const_cast<char*>("bias_correction"), py_get_generic(LAMBUpdate, bias_correction), py_set_generic(LAMBUpdate, bias_correction), const_cast<char*>("bias_correction"), NULL},
  10053. {const_cast<char*>("always_adapt"), py_get_generic(LAMBUpdate, always_adapt), py_set_generic(LAMBUpdate, always_adapt), const_cast<char*>("always_adapt"), NULL},
  10054. {NULL} /* Sentinel */
  10055. };
  10056. PyMethodDef PyOp(LAMBUpdate)::tp_methods[] = {
  10057. {const_cast<char*>("__getstate__"), PyOp(LAMBUpdate)::getstate, METH_NOARGS, "LAMBUpdate getstate"},
  10058. {const_cast<char*>("__setstate__"), PyOp(LAMBUpdate)::setstate, METH_VARARGS, "LAMBUpdate setstate"},
  10059. {NULL} /* Sentinel */
  10060. };
  10061. void _init_py_LAMBUpdate(py::module m) {
  10062. using py_op = PyOp(LAMBUpdate);
  10063. auto& py_type = PyOpType(LAMBUpdate);
  10064. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10065. py_type.tp_name = "megengine.core._imperative_rt.ops.LAMBUpdate";
  10066. py_type.tp_basicsize = sizeof(PyOp(LAMBUpdate));
  10067. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10068. py_type.tp_doc = "LAMBUpdate";
  10069. py_type.tp_base = &PyOpType(OpDef);
  10070. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10071. py_type.tp_new = py_new_generic<py_op>;
  10072. py_type.tp_init = py_op::py_init;
  10073. py_type.tp_methods = py_op::tp_methods;
  10074. py_type.tp_getset = py_op::py_getsetters;
  10075. mgb_assert(PyType_Ready(&py_type) >= 0);
  10076. PyType_Modified(&py_type);
  10077. m.add_object("LAMBUpdate", reinterpret_cast<PyObject*>(&py_type));
  10078. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LAMBUpdate::typeinfo(), &py_type).second);
  10079. }
  10080. PyOpDefBegin(LRN) // {
  10081. static PyGetSetDef py_getsetters[];
  10082. static PyMethodDef tp_methods[];
  10083. static PyObject* getstate(PyObject* self, PyObject*) {
  10084. auto& opdef = reinterpret_cast<PyOp(LRN)*>(self)->inst();
  10085. static_cast<void>(opdef);
  10086. std::unordered_map<std::string, py::object> state {
  10087. {"n", serialization<decltype(opdef.n)>::dump(opdef.n)},
  10088. {"k", serialization<decltype(opdef.k)>::dump(opdef.k)},
  10089. {"alpha", serialization<decltype(opdef.alpha)>::dump(opdef.alpha)},
  10090. {"beta", serialization<decltype(opdef.beta)>::dump(opdef.beta)}
  10091. };
  10092. return py::cast(state).release().ptr();
  10093. }
  10094. static PyObject* setstate(PyObject* self, PyObject* args) {
  10095. PyObject* dict = PyTuple_GetItem(args, 0);
  10096. if (!dict) return NULL;
  10097. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10098. auto& opdef = reinterpret_cast<PyOp(LRN)*>(self)->inst();
  10099. static_cast<void>(opdef);
  10100. {
  10101. auto&& iter = state.find("n");
  10102. if (iter != state.end()) {
  10103. opdef.n = serialization<decltype(opdef.n)>::load(iter->second);
  10104. }
  10105. }
  10106. {
  10107. auto&& iter = state.find("k");
  10108. if (iter != state.end()) {
  10109. opdef.k = serialization<decltype(opdef.k)>::load(iter->second);
  10110. }
  10111. }
  10112. {
  10113. auto&& iter = state.find("alpha");
  10114. if (iter != state.end()) {
  10115. opdef.alpha = serialization<decltype(opdef.alpha)>::load(iter->second);
  10116. }
  10117. }
  10118. {
  10119. auto&& iter = state.find("beta");
  10120. if (iter != state.end()) {
  10121. opdef.beta = serialization<decltype(opdef.beta)>::load(iter->second);
  10122. }
  10123. }
  10124. Py_RETURN_NONE;
  10125. }
  10126. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10127. // };
  10128. PyOpDefEnd(LRN)
  10129. int PyOp(LRN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10130. static const char* kwlist[] = {"n", "k", "alpha", "beta", "scope", NULL};
  10131. PyObject *n = NULL, *k = NULL, *alpha = NULL, *beta = NULL, *scope = NULL;
  10132. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &n, &k, &alpha, &beta, &scope))
  10133. return -1;
  10134. if (n) {
  10135. try {
  10136. // TODO: remove this guard which is used for pybind11 implicit conversion
  10137. py::detail::loader_life_support guard{};
  10138. reinterpret_cast<PyOp(LRN)*>(self)->inst().n =
  10139. py::cast<decltype(LRN::n)>(py::handle(n));
  10140. } CATCH_ALL(-1)
  10141. }
  10142. if (k) {
  10143. try {
  10144. // TODO: remove this guard which is used for pybind11 implicit conversion
  10145. py::detail::loader_life_support guard{};
  10146. reinterpret_cast<PyOp(LRN)*>(self)->inst().k =
  10147. py::cast<decltype(LRN::k)>(py::handle(k));
  10148. } CATCH_ALL(-1)
  10149. }
  10150. if (alpha) {
  10151. try {
  10152. // TODO: remove this guard which is used for pybind11 implicit conversion
  10153. py::detail::loader_life_support guard{};
  10154. reinterpret_cast<PyOp(LRN)*>(self)->inst().alpha =
  10155. py::cast<decltype(LRN::alpha)>(py::handle(alpha));
  10156. } CATCH_ALL(-1)
  10157. }
  10158. if (beta) {
  10159. try {
  10160. // TODO: remove this guard which is used for pybind11 implicit conversion
  10161. py::detail::loader_life_support guard{};
  10162. reinterpret_cast<PyOp(LRN)*>(self)->inst().beta =
  10163. py::cast<decltype(LRN::beta)>(py::handle(beta));
  10164. } CATCH_ALL(-1)
  10165. }
  10166. if (scope) {
  10167. try {
  10168. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10169. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10170. } CATCH_ALL(-1)
  10171. }
  10172. return 0;
  10173. }
  10174. PyGetSetDef PyOp(LRN)::py_getsetters[] = {
  10175. {const_cast<char*>("n"), py_get_generic(LRN, n), py_set_generic(LRN, n), const_cast<char*>("n"), NULL},
  10176. {const_cast<char*>("k"), py_get_generic(LRN, k), py_set_generic(LRN, k), const_cast<char*>("k"), NULL},
  10177. {const_cast<char*>("alpha"), py_get_generic(LRN, alpha), py_set_generic(LRN, alpha), const_cast<char*>("alpha"), NULL},
  10178. {const_cast<char*>("beta"), py_get_generic(LRN, beta), py_set_generic(LRN, beta), const_cast<char*>("beta"), NULL},
  10179. {NULL} /* Sentinel */
  10180. };
  10181. PyMethodDef PyOp(LRN)::tp_methods[] = {
  10182. {const_cast<char*>("__getstate__"), PyOp(LRN)::getstate, METH_NOARGS, "LRN getstate"},
  10183. {const_cast<char*>("__setstate__"), PyOp(LRN)::setstate, METH_VARARGS, "LRN setstate"},
  10184. {NULL} /* Sentinel */
  10185. };
  10186. void _init_py_LRN(py::module m) {
  10187. using py_op = PyOp(LRN);
  10188. auto& py_type = PyOpType(LRN);
  10189. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10190. py_type.tp_name = "megengine.core._imperative_rt.ops.LRN";
  10191. py_type.tp_basicsize = sizeof(PyOp(LRN));
  10192. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10193. py_type.tp_doc = "LRN";
  10194. py_type.tp_base = &PyOpType(OpDef);
  10195. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10196. py_type.tp_new = py_new_generic<py_op>;
  10197. py_type.tp_init = py_op::py_init;
  10198. py_type.tp_methods = py_op::tp_methods;
  10199. py_type.tp_getset = py_op::py_getsetters;
  10200. mgb_assert(PyType_Ready(&py_type) >= 0);
  10201. PyType_Modified(&py_type);
  10202. m.add_object("LRN", reinterpret_cast<PyObject*>(&py_type));
  10203. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LRN::typeinfo(), &py_type).second);
  10204. }
  10205. PyOpDefBegin(LSQ) // {
  10206. static PyGetSetDef py_getsetters[];
  10207. static PyMethodDef tp_methods[];
  10208. static PyObject* getstate(PyObject* self, PyObject*) {
  10209. auto& opdef = reinterpret_cast<PyOp(LSQ)*>(self)->inst();
  10210. static_cast<void>(opdef);
  10211. std::unordered_map<std::string, py::object> state {
  10212. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  10213. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  10214. };
  10215. return py::cast(state).release().ptr();
  10216. }
  10217. static PyObject* setstate(PyObject* self, PyObject* args) {
  10218. PyObject* dict = PyTuple_GetItem(args, 0);
  10219. if (!dict) return NULL;
  10220. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10221. auto& opdef = reinterpret_cast<PyOp(LSQ)*>(self)->inst();
  10222. static_cast<void>(opdef);
  10223. {
  10224. auto&& iter = state.find("qmin");
  10225. if (iter != state.end()) {
  10226. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  10227. }
  10228. }
  10229. {
  10230. auto&& iter = state.find("qmax");
  10231. if (iter != state.end()) {
  10232. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  10233. }
  10234. }
  10235. Py_RETURN_NONE;
  10236. }
  10237. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10238. // };
  10239. PyOpDefEnd(LSQ)
  10240. int PyOp(LSQ)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10241. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  10242. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  10243. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  10244. return -1;
  10245. if (qmin) {
  10246. try {
  10247. // TODO: remove this guard which is used for pybind11 implicit conversion
  10248. py::detail::loader_life_support guard{};
  10249. reinterpret_cast<PyOp(LSQ)*>(self)->inst().qmin =
  10250. py::cast<decltype(LSQ::qmin)>(py::handle(qmin));
  10251. } CATCH_ALL(-1)
  10252. }
  10253. if (qmax) {
  10254. try {
  10255. // TODO: remove this guard which is used for pybind11 implicit conversion
  10256. py::detail::loader_life_support guard{};
  10257. reinterpret_cast<PyOp(LSQ)*>(self)->inst().qmax =
  10258. py::cast<decltype(LSQ::qmax)>(py::handle(qmax));
  10259. } CATCH_ALL(-1)
  10260. }
  10261. if (scope) {
  10262. try {
  10263. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10264. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10265. } CATCH_ALL(-1)
  10266. }
  10267. return 0;
  10268. }
  10269. PyGetSetDef PyOp(LSQ)::py_getsetters[] = {
  10270. {const_cast<char*>("qmin"), py_get_generic(LSQ, qmin), py_set_generic(LSQ, qmin), const_cast<char*>("qmin"), NULL},
  10271. {const_cast<char*>("qmax"), py_get_generic(LSQ, qmax), py_set_generic(LSQ, qmax), const_cast<char*>("qmax"), NULL},
  10272. {NULL} /* Sentinel */
  10273. };
  10274. PyMethodDef PyOp(LSQ)::tp_methods[] = {
  10275. {const_cast<char*>("__getstate__"), PyOp(LSQ)::getstate, METH_NOARGS, "LSQ getstate"},
  10276. {const_cast<char*>("__setstate__"), PyOp(LSQ)::setstate, METH_VARARGS, "LSQ setstate"},
  10277. {NULL} /* Sentinel */
  10278. };
  10279. void _init_py_LSQ(py::module m) {
  10280. using py_op = PyOp(LSQ);
  10281. auto& py_type = PyOpType(LSQ);
  10282. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10283. py_type.tp_name = "megengine.core._imperative_rt.ops.LSQ";
  10284. py_type.tp_basicsize = sizeof(PyOp(LSQ));
  10285. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10286. py_type.tp_doc = "LSQ";
  10287. py_type.tp_base = &PyOpType(OpDef);
  10288. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10289. py_type.tp_new = py_new_generic<py_op>;
  10290. py_type.tp_init = py_op::py_init;
  10291. py_type.tp_methods = py_op::tp_methods;
  10292. py_type.tp_getset = py_op::py_getsetters;
  10293. mgb_assert(PyType_Ready(&py_type) >= 0);
  10294. PyType_Modified(&py_type);
  10295. m.add_object("LSQ", reinterpret_cast<PyObject*>(&py_type));
  10296. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSQ::typeinfo(), &py_type).second);
  10297. }
  10298. void _init_py_LSTM_FwdMode(PyTypeObject& py_type) {
  10299. auto& e_type = EnumWrapper<LSTM::FwdMode>::type;
  10300. Py_INCREF(e_type);
  10301. mgb_assert(PyDict_SetItemString(
  10302. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  10303. }
  10304. PyOpDefBegin(LSTM) // {
  10305. static PyGetSetDef py_getsetters[];
  10306. static PyMethodDef tp_methods[];
  10307. static PyObject* getstate(PyObject* self, PyObject*) {
  10308. auto& opdef = reinterpret_cast<PyOp(LSTM)*>(self)->inst();
  10309. static_cast<void>(opdef);
  10310. std::unordered_map<std::string, py::object> state {
  10311. {"num_layers", serialization<decltype(opdef.num_layers)>::dump(opdef.num_layers)},
  10312. {"bidirectional", serialization<decltype(opdef.bidirectional)>::dump(opdef.bidirectional)},
  10313. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)},
  10314. {"hidden_size", serialization<decltype(opdef.hidden_size)>::dump(opdef.hidden_size)},
  10315. {"proj_size", serialization<decltype(opdef.proj_size)>::dump(opdef.proj_size)},
  10316. {"dropout", serialization<decltype(opdef.dropout)>::dump(opdef.dropout)},
  10317. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)}
  10318. };
  10319. return py::cast(state).release().ptr();
  10320. }
  10321. static PyObject* setstate(PyObject* self, PyObject* args) {
  10322. PyObject* dict = PyTuple_GetItem(args, 0);
  10323. if (!dict) return NULL;
  10324. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10325. auto& opdef = reinterpret_cast<PyOp(LSTM)*>(self)->inst();
  10326. static_cast<void>(opdef);
  10327. {
  10328. auto&& iter = state.find("num_layers");
  10329. if (iter != state.end()) {
  10330. opdef.num_layers = serialization<decltype(opdef.num_layers)>::load(iter->second);
  10331. }
  10332. }
  10333. {
  10334. auto&& iter = state.find("bidirectional");
  10335. if (iter != state.end()) {
  10336. opdef.bidirectional = serialization<decltype(opdef.bidirectional)>::load(iter->second);
  10337. }
  10338. }
  10339. {
  10340. auto&& iter = state.find("bias");
  10341. if (iter != state.end()) {
  10342. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  10343. }
  10344. }
  10345. {
  10346. auto&& iter = state.find("hidden_size");
  10347. if (iter != state.end()) {
  10348. opdef.hidden_size = serialization<decltype(opdef.hidden_size)>::load(iter->second);
  10349. }
  10350. }
  10351. {
  10352. auto&& iter = state.find("proj_size");
  10353. if (iter != state.end()) {
  10354. opdef.proj_size = serialization<decltype(opdef.proj_size)>::load(iter->second);
  10355. }
  10356. }
  10357. {
  10358. auto&& iter = state.find("dropout");
  10359. if (iter != state.end()) {
  10360. opdef.dropout = serialization<decltype(opdef.dropout)>::load(iter->second);
  10361. }
  10362. }
  10363. {
  10364. auto&& iter = state.find("fwd_mode");
  10365. if (iter != state.end()) {
  10366. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  10367. }
  10368. }
  10369. Py_RETURN_NONE;
  10370. }
  10371. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10372. // };
  10373. PyOpDefEnd(LSTM)
  10374. int PyOp(LSTM)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10375. static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "proj_size", "dropout", "fwd_mode", "scope", NULL};
  10376. PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *proj_size = NULL, *dropout = NULL, *fwd_mode = NULL, *scope = NULL;
  10377. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &proj_size, &dropout, &fwd_mode, &scope))
  10378. return -1;
  10379. if (num_layers) {
  10380. try {
  10381. // TODO: remove this guard which is used for pybind11 implicit conversion
  10382. py::detail::loader_life_support guard{};
  10383. reinterpret_cast<PyOp(LSTM)*>(self)->inst().num_layers =
  10384. py::cast<decltype(LSTM::num_layers)>(py::handle(num_layers));
  10385. } CATCH_ALL(-1)
  10386. }
  10387. if (bidirectional) {
  10388. try {
  10389. // TODO: remove this guard which is used for pybind11 implicit conversion
  10390. py::detail::loader_life_support guard{};
  10391. reinterpret_cast<PyOp(LSTM)*>(self)->inst().bidirectional =
  10392. py::cast<decltype(LSTM::bidirectional)>(py::handle(bidirectional));
  10393. } CATCH_ALL(-1)
  10394. }
  10395. if (bias) {
  10396. try {
  10397. // TODO: remove this guard which is used for pybind11 implicit conversion
  10398. py::detail::loader_life_support guard{};
  10399. reinterpret_cast<PyOp(LSTM)*>(self)->inst().bias =
  10400. py::cast<decltype(LSTM::bias)>(py::handle(bias));
  10401. } CATCH_ALL(-1)
  10402. }
  10403. if (hidden_size) {
  10404. try {
  10405. // TODO: remove this guard which is used for pybind11 implicit conversion
  10406. py::detail::loader_life_support guard{};
  10407. reinterpret_cast<PyOp(LSTM)*>(self)->inst().hidden_size =
  10408. py::cast<decltype(LSTM::hidden_size)>(py::handle(hidden_size));
  10409. } CATCH_ALL(-1)
  10410. }
  10411. if (proj_size) {
  10412. try {
  10413. // TODO: remove this guard which is used for pybind11 implicit conversion
  10414. py::detail::loader_life_support guard{};
  10415. reinterpret_cast<PyOp(LSTM)*>(self)->inst().proj_size =
  10416. py::cast<decltype(LSTM::proj_size)>(py::handle(proj_size));
  10417. } CATCH_ALL(-1)
  10418. }
  10419. if (dropout) {
  10420. try {
  10421. // TODO: remove this guard which is used for pybind11 implicit conversion
  10422. py::detail::loader_life_support guard{};
  10423. reinterpret_cast<PyOp(LSTM)*>(self)->inst().dropout =
  10424. py::cast<decltype(LSTM::dropout)>(py::handle(dropout));
  10425. } CATCH_ALL(-1)
  10426. }
  10427. if (fwd_mode) {
  10428. try {
  10429. // TODO: remove this guard which is used for pybind11 implicit conversion
  10430. py::detail::loader_life_support guard{};
  10431. reinterpret_cast<PyOp(LSTM)*>(self)->inst().fwd_mode =
  10432. py::cast<decltype(LSTM::fwd_mode)>(py::handle(fwd_mode));
  10433. } CATCH_ALL(-1)
  10434. }
  10435. if (scope) {
  10436. try {
  10437. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10438. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10439. } CATCH_ALL(-1)
  10440. }
  10441. return 0;
  10442. }
  10443. PyGetSetDef PyOp(LSTM)::py_getsetters[] = {
  10444. {const_cast<char*>("num_layers"), py_get_generic(LSTM, num_layers), py_set_generic(LSTM, num_layers), const_cast<char*>("num_layers"), NULL},
  10445. {const_cast<char*>("bidirectional"), py_get_generic(LSTM, bidirectional), py_set_generic(LSTM, bidirectional), const_cast<char*>("bidirectional"), NULL},
  10446. {const_cast<char*>("bias"), py_get_generic(LSTM, bias), py_set_generic(LSTM, bias), const_cast<char*>("bias"), NULL},
  10447. {const_cast<char*>("hidden_size"), py_get_generic(LSTM, hidden_size), py_set_generic(LSTM, hidden_size), const_cast<char*>("hidden_size"), NULL},
  10448. {const_cast<char*>("proj_size"), py_get_generic(LSTM, proj_size), py_set_generic(LSTM, proj_size), const_cast<char*>("proj_size"), NULL},
  10449. {const_cast<char*>("dropout"), py_get_generic(LSTM, dropout), py_set_generic(LSTM, dropout), const_cast<char*>("dropout"), NULL},
  10450. {const_cast<char*>("fwd_mode"), py_get_generic(LSTM, fwd_mode), py_set_generic(LSTM, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  10451. {NULL} /* Sentinel */
  10452. };
  10453. PyMethodDef PyOp(LSTM)::tp_methods[] = {
  10454. {const_cast<char*>("__getstate__"), PyOp(LSTM)::getstate, METH_NOARGS, "LSTM getstate"},
  10455. {const_cast<char*>("__setstate__"), PyOp(LSTM)::setstate, METH_VARARGS, "LSTM setstate"},
  10456. {NULL} /* Sentinel */
  10457. };
  10458. void _init_py_LSTM(py::module m) {
  10459. using py_op = PyOp(LSTM);
  10460. auto& py_type = PyOpType(LSTM);
  10461. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10462. py_type.tp_name = "megengine.core._imperative_rt.ops.LSTM";
  10463. py_type.tp_basicsize = sizeof(PyOp(LSTM));
  10464. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10465. py_type.tp_doc = "LSTM";
  10466. py_type.tp_base = &PyOpType(OpDef);
  10467. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10468. py_type.tp_new = py_new_generic<py_op>;
  10469. py_type.tp_init = py_op::py_init;
  10470. py_type.tp_methods = py_op::tp_methods;
  10471. py_type.tp_getset = py_op::py_getsetters;
  10472. mgb_assert(PyType_Ready(&py_type) >= 0);
  10473. _init_py_LSTM_FwdMode(py_type);
  10474. PyType_Modified(&py_type);
  10475. m.add_object("LSTM", reinterpret_cast<PyObject*>(&py_type));
  10476. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTM::typeinfo(), &py_type).second);
  10477. }
  10478. PyOpDefBegin(LSTMCell) // {
  10479. static PyGetSetDef py_getsetters[];
  10480. static PyMethodDef tp_methods[];
  10481. static PyObject* getstate(PyObject* self, PyObject*) {
  10482. auto& opdef = reinterpret_cast<PyOp(LSTMCell)*>(self)->inst();
  10483. static_cast<void>(opdef);
  10484. std::unordered_map<std::string, py::object> state {
  10485. };
  10486. return py::cast(state).release().ptr();
  10487. }
  10488. static PyObject* setstate(PyObject* self, PyObject* args) {
  10489. PyObject* dict = PyTuple_GetItem(args, 0);
  10490. if (!dict) return NULL;
  10491. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10492. auto& opdef = reinterpret_cast<PyOp(LSTMCell)*>(self)->inst();
  10493. static_cast<void>(opdef);
  10494. Py_RETURN_NONE;
  10495. }
  10496. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10497. // };
  10498. PyOpDefEnd(LSTMCell)
  10499. int PyOp(LSTMCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10500. return 0;
  10501. }
  10502. PyGetSetDef PyOp(LSTMCell)::py_getsetters[] = {
  10503. {NULL} /* Sentinel */
  10504. };
  10505. PyMethodDef PyOp(LSTMCell)::tp_methods[] = {
  10506. {const_cast<char*>("__getstate__"), PyOp(LSTMCell)::getstate, METH_NOARGS, "LSTMCell getstate"},
  10507. {const_cast<char*>("__setstate__"), PyOp(LSTMCell)::setstate, METH_VARARGS, "LSTMCell setstate"},
  10508. {NULL} /* Sentinel */
  10509. };
  10510. void _init_py_LSTMCell(py::module m) {
  10511. using py_op = PyOp(LSTMCell);
  10512. auto& py_type = PyOpType(LSTMCell);
  10513. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10514. py_type.tp_name = "megengine.core._imperative_rt.ops.LSTMCell";
  10515. py_type.tp_basicsize = sizeof(PyOp(LSTMCell));
  10516. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10517. py_type.tp_doc = "LSTMCell";
  10518. py_type.tp_base = &PyOpType(OpDef);
  10519. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10520. py_type.tp_new = py_new_generic<py_op>;
  10521. py_type.tp_init = py_op::py_init;
  10522. py_type.tp_methods = py_op::tp_methods;
  10523. py_type.tp_getset = py_op::py_getsetters;
  10524. mgb_assert(PyType_Ready(&py_type) >= 0);
  10525. PyType_Modified(&py_type);
  10526. m.add_object("LSTMCell", reinterpret_cast<PyObject*>(&py_type));
  10527. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTMCell::typeinfo(), &py_type).second);
  10528. }
  10529. PyOpDefBegin(LayerNorm) // {
  10530. static PyGetSetDef py_getsetters[];
  10531. static PyMethodDef tp_methods[];
  10532. static PyObject* getstate(PyObject* self, PyObject*) {
  10533. auto& opdef = reinterpret_cast<PyOp(LayerNorm)*>(self)->inst();
  10534. static_cast<void>(opdef);
  10535. std::unordered_map<std::string, py::object> state {
  10536. {"affine", serialization<decltype(opdef.affine)>::dump(opdef.affine)},
  10537. {"eps", serialization<decltype(opdef.eps)>::dump(opdef.eps)},
  10538. {"normalized_dim", serialization<decltype(opdef.normalized_dim)>::dump(opdef.normalized_dim)},
  10539. {"normalized_size", serialization<decltype(opdef.normalized_size)>::dump(opdef.normalized_size)}
  10540. };
  10541. return py::cast(state).release().ptr();
  10542. }
  10543. static PyObject* setstate(PyObject* self, PyObject* args) {
  10544. PyObject* dict = PyTuple_GetItem(args, 0);
  10545. if (!dict) return NULL;
  10546. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10547. auto& opdef = reinterpret_cast<PyOp(LayerNorm)*>(self)->inst();
  10548. static_cast<void>(opdef);
  10549. {
  10550. auto&& iter = state.find("affine");
  10551. if (iter != state.end()) {
  10552. opdef.affine = serialization<decltype(opdef.affine)>::load(iter->second);
  10553. }
  10554. }
  10555. {
  10556. auto&& iter = state.find("eps");
  10557. if (iter != state.end()) {
  10558. opdef.eps = serialization<decltype(opdef.eps)>::load(iter->second);
  10559. }
  10560. }
  10561. {
  10562. auto&& iter = state.find("normalized_dim");
  10563. if (iter != state.end()) {
  10564. opdef.normalized_dim = serialization<decltype(opdef.normalized_dim)>::load(iter->second);
  10565. }
  10566. }
  10567. {
  10568. auto&& iter = state.find("normalized_size");
  10569. if (iter != state.end()) {
  10570. opdef.normalized_size = serialization<decltype(opdef.normalized_size)>::load(iter->second);
  10571. }
  10572. }
  10573. Py_RETURN_NONE;
  10574. }
  10575. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10576. // };
  10577. PyOpDefEnd(LayerNorm)
  10578. int PyOp(LayerNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10579. static const char* kwlist[] = {"affine", "eps", "normalized_dim", "normalized_size", "scope", NULL};
  10580. PyObject *affine = NULL, *eps = NULL, *normalized_dim = NULL, *normalized_size = NULL, *scope = NULL;
  10581. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &affine, &eps, &normalized_dim, &normalized_size, &scope))
  10582. return -1;
  10583. if (affine) {
  10584. try {
  10585. // TODO: remove this guard which is used for pybind11 implicit conversion
  10586. py::detail::loader_life_support guard{};
  10587. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().affine =
  10588. py::cast<decltype(LayerNorm::affine)>(py::handle(affine));
  10589. } CATCH_ALL(-1)
  10590. }
  10591. if (eps) {
  10592. try {
  10593. // TODO: remove this guard which is used for pybind11 implicit conversion
  10594. py::detail::loader_life_support guard{};
  10595. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().eps =
  10596. py::cast<decltype(LayerNorm::eps)>(py::handle(eps));
  10597. } CATCH_ALL(-1)
  10598. }
  10599. if (normalized_dim) {
  10600. try {
  10601. // TODO: remove this guard which is used for pybind11 implicit conversion
  10602. py::detail::loader_life_support guard{};
  10603. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().normalized_dim =
  10604. py::cast<decltype(LayerNorm::normalized_dim)>(py::handle(normalized_dim));
  10605. } CATCH_ALL(-1)
  10606. }
  10607. if (normalized_size) {
  10608. try {
  10609. // TODO: remove this guard which is used for pybind11 implicit conversion
  10610. py::detail::loader_life_support guard{};
  10611. reinterpret_cast<PyOp(LayerNorm)*>(self)->inst().normalized_size =
  10612. py::cast<decltype(LayerNorm::normalized_size)>(py::handle(normalized_size));
  10613. } CATCH_ALL(-1)
  10614. }
  10615. if (scope) {
  10616. try {
  10617. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10618. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10619. } CATCH_ALL(-1)
  10620. }
  10621. return 0;
  10622. }
  10623. PyGetSetDef PyOp(LayerNorm)::py_getsetters[] = {
  10624. {const_cast<char*>("affine"), py_get_generic(LayerNorm, affine), py_set_generic(LayerNorm, affine), const_cast<char*>("affine"), NULL},
  10625. {const_cast<char*>("eps"), py_get_generic(LayerNorm, eps), py_set_generic(LayerNorm, eps), const_cast<char*>("eps"), NULL},
  10626. {const_cast<char*>("normalized_dim"), py_get_generic(LayerNorm, normalized_dim), py_set_generic(LayerNorm, normalized_dim), const_cast<char*>("normalized_dim"), NULL},
  10627. {const_cast<char*>("normalized_size"), py_get_generic(LayerNorm, normalized_size), py_set_generic(LayerNorm, normalized_size), const_cast<char*>("normalized_size"), NULL},
  10628. {NULL} /* Sentinel */
  10629. };
  10630. PyMethodDef PyOp(LayerNorm)::tp_methods[] = {
  10631. {const_cast<char*>("__getstate__"), PyOp(LayerNorm)::getstate, METH_NOARGS, "LayerNorm getstate"},
  10632. {const_cast<char*>("__setstate__"), PyOp(LayerNorm)::setstate, METH_VARARGS, "LayerNorm setstate"},
  10633. {NULL} /* Sentinel */
  10634. };
  10635. void _init_py_LayerNorm(py::module m) {
  10636. using py_op = PyOp(LayerNorm);
  10637. auto& py_type = PyOpType(LayerNorm);
  10638. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10639. py_type.tp_name = "megengine.core._imperative_rt.ops.LayerNorm";
  10640. py_type.tp_basicsize = sizeof(PyOp(LayerNorm));
  10641. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10642. py_type.tp_doc = "LayerNorm";
  10643. py_type.tp_base = &PyOpType(OpDef);
  10644. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10645. py_type.tp_new = py_new_generic<py_op>;
  10646. py_type.tp_init = py_op::py_init;
  10647. py_type.tp_methods = py_op::tp_methods;
  10648. py_type.tp_getset = py_op::py_getsetters;
  10649. mgb_assert(PyType_Ready(&py_type) >= 0);
  10650. PyType_Modified(&py_type);
  10651. m.add_object("LayerNorm", reinterpret_cast<PyObject*>(&py_type));
  10652. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LayerNorm::typeinfo(), &py_type).second);
  10653. }
  10654. PyOpDefBegin(Linspace) // {
  10655. static PyGetSetDef py_getsetters[];
  10656. static PyMethodDef tp_methods[];
  10657. static PyObject* getstate(PyObject* self, PyObject*) {
  10658. auto& opdef = reinterpret_cast<PyOp(Linspace)*>(self)->inst();
  10659. static_cast<void>(opdef);
  10660. std::unordered_map<std::string, py::object> state {
  10661. {"endpoint", serialization<decltype(opdef.endpoint)>::dump(opdef.endpoint)},
  10662. {"comp_node", serialization<decltype(opdef.comp_node)>::dump(opdef.comp_node)}
  10663. };
  10664. return py::cast(state).release().ptr();
  10665. }
  10666. static PyObject* setstate(PyObject* self, PyObject* args) {
  10667. PyObject* dict = PyTuple_GetItem(args, 0);
  10668. if (!dict) return NULL;
  10669. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10670. auto& opdef = reinterpret_cast<PyOp(Linspace)*>(self)->inst();
  10671. static_cast<void>(opdef);
  10672. {
  10673. auto&& iter = state.find("endpoint");
  10674. if (iter != state.end()) {
  10675. opdef.endpoint = serialization<decltype(opdef.endpoint)>::load(iter->second);
  10676. }
  10677. }
  10678. {
  10679. auto&& iter = state.find("comp_node");
  10680. if (iter != state.end()) {
  10681. opdef.comp_node = serialization<decltype(opdef.comp_node)>::load(iter->second);
  10682. }
  10683. }
  10684. Py_RETURN_NONE;
  10685. }
  10686. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10687. // };
  10688. PyOpDefEnd(Linspace)
  10689. int PyOp(Linspace)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10690. static const char* kwlist[] = {"endpoint", "comp_node", "scope", NULL};
  10691. PyObject *endpoint = NULL, *comp_node = NULL, *scope = NULL;
  10692. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &endpoint, &comp_node, &scope))
  10693. return -1;
  10694. if (endpoint) {
  10695. try {
  10696. // TODO: remove this guard which is used for pybind11 implicit conversion
  10697. py::detail::loader_life_support guard{};
  10698. reinterpret_cast<PyOp(Linspace)*>(self)->inst().endpoint =
  10699. py::cast<decltype(Linspace::endpoint)>(py::handle(endpoint));
  10700. } CATCH_ALL(-1)
  10701. }
  10702. if (comp_node) {
  10703. try {
  10704. // TODO: remove this guard which is used for pybind11 implicit conversion
  10705. py::detail::loader_life_support guard{};
  10706. reinterpret_cast<PyOp(Linspace)*>(self)->inst().comp_node =
  10707. py::cast<decltype(Linspace::comp_node)>(py::handle(comp_node));
  10708. } CATCH_ALL(-1)
  10709. }
  10710. if (scope) {
  10711. try {
  10712. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10713. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10714. } CATCH_ALL(-1)
  10715. }
  10716. return 0;
  10717. }
  10718. PyGetSetDef PyOp(Linspace)::py_getsetters[] = {
  10719. {const_cast<char*>("endpoint"), py_get_generic(Linspace, endpoint), py_set_generic(Linspace, endpoint), const_cast<char*>("endpoint"), NULL},
  10720. {const_cast<char*>("comp_node"), py_get_generic(Linspace, comp_node), py_set_generic(Linspace, comp_node), const_cast<char*>("comp_node"), NULL},
  10721. {NULL} /* Sentinel */
  10722. };
  10723. PyMethodDef PyOp(Linspace)::tp_methods[] = {
  10724. {const_cast<char*>("__getstate__"), PyOp(Linspace)::getstate, METH_NOARGS, "Linspace getstate"},
  10725. {const_cast<char*>("__setstate__"), PyOp(Linspace)::setstate, METH_VARARGS, "Linspace setstate"},
  10726. {NULL} /* Sentinel */
  10727. };
  10728. void _init_py_Linspace(py::module m) {
  10729. using py_op = PyOp(Linspace);
  10730. auto& py_type = PyOpType(Linspace);
  10731. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10732. py_type.tp_name = "megengine.core._imperative_rt.ops.Linspace";
  10733. py_type.tp_basicsize = sizeof(PyOp(Linspace));
  10734. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10735. py_type.tp_doc = "Linspace";
  10736. py_type.tp_base = &PyOpType(OpDef);
  10737. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10738. py_type.tp_new = py_new_generic<py_op>;
  10739. py_type.tp_init = py_op::py_init;
  10740. py_type.tp_methods = py_op::tp_methods;
  10741. py_type.tp_getset = py_op::py_getsetters;
  10742. mgb_assert(PyType_Ready(&py_type) >= 0);
  10743. PyType_Modified(&py_type);
  10744. m.add_object("Linspace", reinterpret_cast<PyObject*>(&py_type));
  10745. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Linspace::typeinfo(), &py_type).second);
  10746. }
  10747. PyOpDefBegin(MagicMindRuntime) // {
  10748. static PyGetSetDef py_getsetters[];
  10749. static PyMethodDef tp_methods[];
  10750. static PyObject* getstate(PyObject* self, PyObject*) {
  10751. auto& opdef = reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst();
  10752. static_cast<void>(opdef);
  10753. std::unordered_map<std::string, py::object> state {
  10754. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  10755. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  10756. };
  10757. return py::cast(state).release().ptr();
  10758. }
  10759. static PyObject* setstate(PyObject* self, PyObject* args) {
  10760. PyObject* dict = PyTuple_GetItem(args, 0);
  10761. if (!dict) return NULL;
  10762. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10763. auto& opdef = reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst();
  10764. static_cast<void>(opdef);
  10765. {
  10766. auto&& iter = state.find("buf");
  10767. if (iter != state.end()) {
  10768. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  10769. }
  10770. }
  10771. {
  10772. auto&& iter = state.find("buf_size");
  10773. if (iter != state.end()) {
  10774. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  10775. }
  10776. }
  10777. Py_RETURN_NONE;
  10778. }
  10779. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10780. // };
  10781. PyOpDefEnd(MagicMindRuntime)
  10782. int PyOp(MagicMindRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10783. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  10784. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  10785. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  10786. return -1;
  10787. if (buf) {
  10788. try {
  10789. // TODO: remove this guard which is used for pybind11 implicit conversion
  10790. py::detail::loader_life_support guard{};
  10791. reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst().buf =
  10792. py::cast<decltype(MagicMindRuntime::buf)>(py::handle(buf));
  10793. } CATCH_ALL(-1)
  10794. }
  10795. if (buf_size) {
  10796. try {
  10797. // TODO: remove this guard which is used for pybind11 implicit conversion
  10798. py::detail::loader_life_support guard{};
  10799. reinterpret_cast<PyOp(MagicMindRuntime)*>(self)->inst().buf_size =
  10800. py::cast<decltype(MagicMindRuntime::buf_size)>(py::handle(buf_size));
  10801. } CATCH_ALL(-1)
  10802. }
  10803. if (scope) {
  10804. try {
  10805. reinterpret_cast<PyOp(OpDef)*>(self)->op
  10806. ->set_scope(py::cast<std::string>(py::handle(scope)));
  10807. } CATCH_ALL(-1)
  10808. }
  10809. return 0;
  10810. }
  10811. PyGetSetDef PyOp(MagicMindRuntime)::py_getsetters[] = {
  10812. {const_cast<char*>("buf"), py_get_generic(MagicMindRuntime, buf), py_set_generic(MagicMindRuntime, buf), const_cast<char*>("buf"), NULL},
  10813. {const_cast<char*>("buf_size"), py_get_generic(MagicMindRuntime, buf_size), py_set_generic(MagicMindRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  10814. {NULL} /* Sentinel */
  10815. };
  10816. PyMethodDef PyOp(MagicMindRuntime)::tp_methods[] = {
  10817. {const_cast<char*>("__getstate__"), PyOp(MagicMindRuntime)::getstate, METH_NOARGS, "MagicMindRuntime getstate"},
  10818. {const_cast<char*>("__setstate__"), PyOp(MagicMindRuntime)::setstate, METH_VARARGS, "MagicMindRuntime setstate"},
  10819. {NULL} /* Sentinel */
  10820. };
  10821. void _init_py_MagicMindRuntime(py::module m) {
  10822. using py_op = PyOp(MagicMindRuntime);
  10823. auto& py_type = PyOpType(MagicMindRuntime);
  10824. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10825. py_type.tp_name = "megengine.core._imperative_rt.ops.MagicMindRuntime";
  10826. py_type.tp_basicsize = sizeof(PyOp(MagicMindRuntime));
  10827. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10828. py_type.tp_doc = "MagicMindRuntime";
  10829. py_type.tp_base = &PyOpType(OpDef);
  10830. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10831. py_type.tp_new = py_new_generic<py_op>;
  10832. py_type.tp_init = py_op::py_init;
  10833. py_type.tp_methods = py_op::tp_methods;
  10834. py_type.tp_getset = py_op::py_getsetters;
  10835. mgb_assert(PyType_Ready(&py_type) >= 0);
  10836. PyType_Modified(&py_type);
  10837. m.add_object("MagicMindRuntime", reinterpret_cast<PyObject*>(&py_type));
  10838. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MagicMindRuntime::typeinfo(), &py_type).second);
  10839. }
  10840. PyOpDefBegin(MatrixInverse) // {
  10841. static PyGetSetDef py_getsetters[];
  10842. static PyMethodDef tp_methods[];
  10843. static PyObject* getstate(PyObject* self, PyObject*) {
  10844. auto& opdef = reinterpret_cast<PyOp(MatrixInverse)*>(self)->inst();
  10845. static_cast<void>(opdef);
  10846. std::unordered_map<std::string, py::object> state {
  10847. };
  10848. return py::cast(state).release().ptr();
  10849. }
  10850. static PyObject* setstate(PyObject* self, PyObject* args) {
  10851. PyObject* dict = PyTuple_GetItem(args, 0);
  10852. if (!dict) return NULL;
  10853. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10854. auto& opdef = reinterpret_cast<PyOp(MatrixInverse)*>(self)->inst();
  10855. static_cast<void>(opdef);
  10856. Py_RETURN_NONE;
  10857. }
  10858. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10859. // };
  10860. PyOpDefEnd(MatrixInverse)
  10861. int PyOp(MatrixInverse)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10862. return 0;
  10863. }
  10864. PyGetSetDef PyOp(MatrixInverse)::py_getsetters[] = {
  10865. {NULL} /* Sentinel */
  10866. };
  10867. PyMethodDef PyOp(MatrixInverse)::tp_methods[] = {
  10868. {const_cast<char*>("__getstate__"), PyOp(MatrixInverse)::getstate, METH_NOARGS, "MatrixInverse getstate"},
  10869. {const_cast<char*>("__setstate__"), PyOp(MatrixInverse)::setstate, METH_VARARGS, "MatrixInverse setstate"},
  10870. {NULL} /* Sentinel */
  10871. };
  10872. void _init_py_MatrixInverse(py::module m) {
  10873. using py_op = PyOp(MatrixInverse);
  10874. auto& py_type = PyOpType(MatrixInverse);
  10875. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  10876. py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixInverse";
  10877. py_type.tp_basicsize = sizeof(PyOp(MatrixInverse));
  10878. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  10879. py_type.tp_doc = "MatrixInverse";
  10880. py_type.tp_base = &PyOpType(OpDef);
  10881. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  10882. py_type.tp_new = py_new_generic<py_op>;
  10883. py_type.tp_init = py_op::py_init;
  10884. py_type.tp_methods = py_op::tp_methods;
  10885. py_type.tp_getset = py_op::py_getsetters;
  10886. mgb_assert(PyType_Ready(&py_type) >= 0);
  10887. PyType_Modified(&py_type);
  10888. m.add_object("MatrixInverse", reinterpret_cast<PyObject*>(&py_type));
  10889. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixInverse::typeinfo(), &py_type).second);
  10890. }
  10891. void _init_py_MatrixMul_ComputeMode(PyTypeObject& py_type) {
  10892. auto& e_type = EnumWrapper<MatrixMul::ComputeMode>::type;
  10893. Py_INCREF(e_type);
  10894. mgb_assert(PyDict_SetItemString(
  10895. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  10896. }
  10897. void _init_py_MatrixMul_Format(PyTypeObject& py_type) {
  10898. auto& e_type = EnumWrapper<MatrixMul::Format>::type;
  10899. Py_INCREF(e_type);
  10900. mgb_assert(PyDict_SetItemString(
  10901. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  10902. }
  10903. void _init_py_MatrixMul_Strategy(PyTypeObject& py_type) {
  10904. auto& e_type = BitCombinedEnumWrapper<MatrixMul::Strategy>::type;
  10905. Py_INCREF(e_type);
  10906. mgb_assert(PyDict_SetItemString(
  10907. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  10908. }
  10909. PyOpDefBegin(MatrixMul) // {
  10910. static PyGetSetDef py_getsetters[];
  10911. static PyMethodDef tp_methods[];
  10912. static PyObject* getstate(PyObject* self, PyObject*) {
  10913. auto& opdef = reinterpret_cast<PyOp(MatrixMul)*>(self)->inst();
  10914. static_cast<void>(opdef);
  10915. std::unordered_map<std::string, py::object> state {
  10916. {"transposeA", serialization<decltype(opdef.transposeA)>::dump(opdef.transposeA)},
  10917. {"transposeB", serialization<decltype(opdef.transposeB)>::dump(opdef.transposeB)},
  10918. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)},
  10919. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  10920. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  10921. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)},
  10922. {"dimA", serialization<decltype(opdef.dimA)>::dump(opdef.dimA)},
  10923. {"dimB", serialization<decltype(opdef.dimB)>::dump(opdef.dimB)}
  10924. };
  10925. return py::cast(state).release().ptr();
  10926. }
  10927. static PyObject* setstate(PyObject* self, PyObject* args) {
  10928. PyObject* dict = PyTuple_GetItem(args, 0);
  10929. if (!dict) return NULL;
  10930. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  10931. auto& opdef = reinterpret_cast<PyOp(MatrixMul)*>(self)->inst();
  10932. static_cast<void>(opdef);
  10933. {
  10934. auto&& iter = state.find("transposeA");
  10935. if (iter != state.end()) {
  10936. opdef.transposeA = serialization<decltype(opdef.transposeA)>::load(iter->second);
  10937. }
  10938. }
  10939. {
  10940. auto&& iter = state.find("transposeB");
  10941. if (iter != state.end()) {
  10942. opdef.transposeB = serialization<decltype(opdef.transposeB)>::load(iter->second);
  10943. }
  10944. }
  10945. {
  10946. auto&& iter = state.find("compute_mode");
  10947. if (iter != state.end()) {
  10948. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  10949. }
  10950. }
  10951. {
  10952. auto&& iter = state.find("format");
  10953. if (iter != state.end()) {
  10954. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  10955. }
  10956. }
  10957. {
  10958. auto&& iter = state.find("strategy");
  10959. if (iter != state.end()) {
  10960. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  10961. }
  10962. }
  10963. {
  10964. auto&& iter = state.find("workspace_limit");
  10965. if (iter != state.end()) {
  10966. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  10967. }
  10968. }
  10969. {
  10970. auto&& iter = state.find("dimA");
  10971. if (iter != state.end()) {
  10972. opdef.dimA = serialization<decltype(opdef.dimA)>::load(iter->second);
  10973. }
  10974. }
  10975. {
  10976. auto&& iter = state.find("dimB");
  10977. if (iter != state.end()) {
  10978. opdef.dimB = serialization<decltype(opdef.dimB)>::load(iter->second);
  10979. }
  10980. }
  10981. Py_RETURN_NONE;
  10982. }
  10983. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  10984. // };
  10985. PyOpDefEnd(MatrixMul)
  10986. int PyOp(MatrixMul)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  10987. static const char* kwlist[] = {"transposeA", "transposeB", "compute_mode", "format", "strategy", "workspace_limit", "dimA", "dimB", "scope", NULL};
  10988. PyObject *transposeA = NULL, *transposeB = NULL, *compute_mode = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *dimA = NULL, *dimB = NULL, *scope = NULL;
  10989. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &transposeA, &transposeB, &compute_mode, &format, &strategy, &workspace_limit, &dimA, &dimB, &scope))
  10990. return -1;
  10991. if (transposeA) {
  10992. try {
  10993. // TODO: remove this guard which is used for pybind11 implicit conversion
  10994. py::detail::loader_life_support guard{};
  10995. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().transposeA =
  10996. py::cast<decltype(MatrixMul::transposeA)>(py::handle(transposeA));
  10997. } CATCH_ALL(-1)
  10998. }
  10999. if (transposeB) {
  11000. try {
  11001. // TODO: remove this guard which is used for pybind11 implicit conversion
  11002. py::detail::loader_life_support guard{};
  11003. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().transposeB =
  11004. py::cast<decltype(MatrixMul::transposeB)>(py::handle(transposeB));
  11005. } CATCH_ALL(-1)
  11006. }
  11007. if (compute_mode) {
  11008. try {
  11009. // TODO: remove this guard which is used for pybind11 implicit conversion
  11010. py::detail::loader_life_support guard{};
  11011. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().compute_mode =
  11012. py::cast<decltype(MatrixMul::compute_mode)>(py::handle(compute_mode));
  11013. } CATCH_ALL(-1)
  11014. }
  11015. if (format) {
  11016. try {
  11017. // TODO: remove this guard which is used for pybind11 implicit conversion
  11018. py::detail::loader_life_support guard{};
  11019. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().format =
  11020. py::cast<decltype(MatrixMul::format)>(py::handle(format));
  11021. } CATCH_ALL(-1)
  11022. }
  11023. if (strategy) {
  11024. try {
  11025. // TODO: remove this guard which is used for pybind11 implicit conversion
  11026. py::detail::loader_life_support guard{};
  11027. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().strategy =
  11028. py::cast<decltype(MatrixMul::strategy)>(py::handle(strategy));
  11029. } CATCH_ALL(-1)
  11030. }
  11031. if (workspace_limit) {
  11032. try {
  11033. // TODO: remove this guard which is used for pybind11 implicit conversion
  11034. py::detail::loader_life_support guard{};
  11035. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().workspace_limit =
  11036. py::cast<decltype(MatrixMul::workspace_limit)>(py::handle(workspace_limit));
  11037. } CATCH_ALL(-1)
  11038. }
  11039. if (dimA) {
  11040. try {
  11041. // TODO: remove this guard which is used for pybind11 implicit conversion
  11042. py::detail::loader_life_support guard{};
  11043. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().dimA =
  11044. py::cast<decltype(MatrixMul::dimA)>(py::handle(dimA));
  11045. } CATCH_ALL(-1)
  11046. }
  11047. if (dimB) {
  11048. try {
  11049. // TODO: remove this guard which is used for pybind11 implicit conversion
  11050. py::detail::loader_life_support guard{};
  11051. reinterpret_cast<PyOp(MatrixMul)*>(self)->inst().dimB =
  11052. py::cast<decltype(MatrixMul::dimB)>(py::handle(dimB));
  11053. } CATCH_ALL(-1)
  11054. }
  11055. if (scope) {
  11056. try {
  11057. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11058. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11059. } CATCH_ALL(-1)
  11060. }
  11061. return 0;
  11062. }
  11063. PyGetSetDef PyOp(MatrixMul)::py_getsetters[] = {
  11064. {const_cast<char*>("transposeA"), py_get_generic(MatrixMul, transposeA), py_set_generic(MatrixMul, transposeA), const_cast<char*>("transposeA"), NULL},
  11065. {const_cast<char*>("transposeB"), py_get_generic(MatrixMul, transposeB), py_set_generic(MatrixMul, transposeB), const_cast<char*>("transposeB"), NULL},
  11066. {const_cast<char*>("compute_mode"), py_get_generic(MatrixMul, compute_mode), py_set_generic(MatrixMul, compute_mode), const_cast<char*>("compute_mode"), NULL},
  11067. {const_cast<char*>("format"), py_get_generic(MatrixMul, format), py_set_generic(MatrixMul, format), const_cast<char*>("format"), NULL},
  11068. {const_cast<char*>("strategy"), py_get_generic(MatrixMul, strategy), py_set_generic(MatrixMul, strategy), const_cast<char*>("strategy"), NULL},
  11069. {const_cast<char*>("workspace_limit"), py_get_generic(MatrixMul, workspace_limit), py_set_generic(MatrixMul, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  11070. {const_cast<char*>("dimA"), py_get_generic(MatrixMul, dimA), py_set_generic(MatrixMul, dimA), const_cast<char*>("dimA"), NULL},
  11071. {const_cast<char*>("dimB"), py_get_generic(MatrixMul, dimB), py_set_generic(MatrixMul, dimB), const_cast<char*>("dimB"), NULL},
  11072. {NULL} /* Sentinel */
  11073. };
  11074. PyMethodDef PyOp(MatrixMul)::tp_methods[] = {
  11075. {const_cast<char*>("__getstate__"), PyOp(MatrixMul)::getstate, METH_NOARGS, "MatrixMul getstate"},
  11076. {const_cast<char*>("__setstate__"), PyOp(MatrixMul)::setstate, METH_VARARGS, "MatrixMul setstate"},
  11077. {NULL} /* Sentinel */
  11078. };
  11079. void _init_py_MatrixMul(py::module m) {
  11080. using py_op = PyOp(MatrixMul);
  11081. auto& py_type = PyOpType(MatrixMul);
  11082. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11083. py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixMul";
  11084. py_type.tp_basicsize = sizeof(PyOp(MatrixMul));
  11085. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11086. py_type.tp_doc = "MatrixMul";
  11087. py_type.tp_base = &PyOpType(OpDef);
  11088. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11089. py_type.tp_new = py_new_generic<py_op>;
  11090. py_type.tp_init = py_op::py_init;
  11091. py_type.tp_methods = py_op::tp_methods;
  11092. py_type.tp_getset = py_op::py_getsetters;
  11093. mgb_assert(PyType_Ready(&py_type) >= 0);
  11094. _init_py_MatrixMul_ComputeMode(py_type);
  11095. _init_py_MatrixMul_Format(py_type);
  11096. _init_py_MatrixMul_Strategy(py_type);
  11097. PyType_Modified(&py_type);
  11098. m.add_object("MatrixMul", reinterpret_cast<PyObject*>(&py_type));
  11099. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixMul::typeinfo(), &py_type).second);
  11100. }
  11101. PyOpDefBegin(MeshGrid) // {
  11102. static PyGetSetDef py_getsetters[];
  11103. static PyMethodDef tp_methods[];
  11104. static PyObject* getstate(PyObject* self, PyObject*) {
  11105. auto& opdef = reinterpret_cast<PyOp(MeshGrid)*>(self)->inst();
  11106. static_cast<void>(opdef);
  11107. std::unordered_map<std::string, py::object> state {
  11108. {"indexing", serialization<decltype(opdef.indexing)>::dump(opdef.indexing)}
  11109. };
  11110. return py::cast(state).release().ptr();
  11111. }
  11112. static PyObject* setstate(PyObject* self, PyObject* args) {
  11113. PyObject* dict = PyTuple_GetItem(args, 0);
  11114. if (!dict) return NULL;
  11115. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11116. auto& opdef = reinterpret_cast<PyOp(MeshGrid)*>(self)->inst();
  11117. static_cast<void>(opdef);
  11118. {
  11119. auto&& iter = state.find("indexing");
  11120. if (iter != state.end()) {
  11121. opdef.indexing = serialization<decltype(opdef.indexing)>::load(iter->second);
  11122. }
  11123. }
  11124. Py_RETURN_NONE;
  11125. }
  11126. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11127. // };
  11128. PyOpDefEnd(MeshGrid)
  11129. int PyOp(MeshGrid)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11130. static const char* kwlist[] = {"indexing", "scope", NULL};
  11131. PyObject *indexing = NULL, *scope = NULL;
  11132. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &indexing, &scope))
  11133. return -1;
  11134. if (indexing) {
  11135. try {
  11136. // TODO: remove this guard which is used for pybind11 implicit conversion
  11137. py::detail::loader_life_support guard{};
  11138. reinterpret_cast<PyOp(MeshGrid)*>(self)->inst().indexing =
  11139. py::cast<decltype(MeshGrid::indexing)>(py::handle(indexing));
  11140. } CATCH_ALL(-1)
  11141. }
  11142. if (scope) {
  11143. try {
  11144. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11145. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11146. } CATCH_ALL(-1)
  11147. }
  11148. return 0;
  11149. }
  11150. PyGetSetDef PyOp(MeshGrid)::py_getsetters[] = {
  11151. {const_cast<char*>("indexing"), py_get_generic(MeshGrid, indexing), py_set_generic(MeshGrid, indexing), const_cast<char*>("indexing"), NULL},
  11152. {NULL} /* Sentinel */
  11153. };
  11154. PyMethodDef PyOp(MeshGrid)::tp_methods[] = {
  11155. {const_cast<char*>("__getstate__"), PyOp(MeshGrid)::getstate, METH_NOARGS, "MeshGrid getstate"},
  11156. {const_cast<char*>("__setstate__"), PyOp(MeshGrid)::setstate, METH_VARARGS, "MeshGrid setstate"},
  11157. {NULL} /* Sentinel */
  11158. };
  11159. void _init_py_MeshGrid(py::module m) {
  11160. using py_op = PyOp(MeshGrid);
  11161. auto& py_type = PyOpType(MeshGrid);
  11162. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11163. py_type.tp_name = "megengine.core._imperative_rt.ops.MeshGrid";
  11164. py_type.tp_basicsize = sizeof(PyOp(MeshGrid));
  11165. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11166. py_type.tp_doc = "MeshGrid";
  11167. py_type.tp_base = &PyOpType(OpDef);
  11168. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11169. py_type.tp_new = py_new_generic<py_op>;
  11170. py_type.tp_init = py_op::py_init;
  11171. py_type.tp_methods = py_op::tp_methods;
  11172. py_type.tp_getset = py_op::py_getsetters;
  11173. mgb_assert(PyType_Ready(&py_type) >= 0);
  11174. PyType_Modified(&py_type);
  11175. m.add_object("MeshGrid", reinterpret_cast<PyObject*>(&py_type));
  11176. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MeshGrid::typeinfo(), &py_type).second);
  11177. }
  11178. PyOpDefBegin(MeshIndexing) // {
  11179. static PyGetSetDef py_getsetters[];
  11180. static PyMethodDef tp_methods[];
  11181. static PyObject* getstate(PyObject* self, PyObject*) {
  11182. auto& opdef = reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst();
  11183. static_cast<void>(opdef);
  11184. std::unordered_map<std::string, py::object> state {
  11185. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  11186. };
  11187. return py::cast(state).release().ptr();
  11188. }
  11189. static PyObject* setstate(PyObject* self, PyObject* args) {
  11190. PyObject* dict = PyTuple_GetItem(args, 0);
  11191. if (!dict) return NULL;
  11192. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11193. auto& opdef = reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst();
  11194. static_cast<void>(opdef);
  11195. {
  11196. auto&& iter = state.find("items");
  11197. if (iter != state.end()) {
  11198. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  11199. }
  11200. }
  11201. Py_RETURN_NONE;
  11202. }
  11203. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11204. // };
  11205. PyOpDefEnd(MeshIndexing)
  11206. int PyOp(MeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11207. static const char* kwlist[] = {"items", "scope", NULL};
  11208. PyObject *items = NULL, *scope = NULL;
  11209. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  11210. return -1;
  11211. if (items) {
  11212. try {
  11213. // TODO: remove this guard which is used for pybind11 implicit conversion
  11214. py::detail::loader_life_support guard{};
  11215. reinterpret_cast<PyOp(MeshIndexing)*>(self)->inst().items =
  11216. py::cast<decltype(MeshIndexing::items)>(py::handle(items));
  11217. } CATCH_ALL(-1)
  11218. }
  11219. if (scope) {
  11220. try {
  11221. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11222. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11223. } CATCH_ALL(-1)
  11224. }
  11225. return 0;
  11226. }
  11227. PyGetSetDef PyOp(MeshIndexing)::py_getsetters[] = {
  11228. {const_cast<char*>("items"), py_get_generic(MeshIndexing, items), py_set_generic(MeshIndexing, items), const_cast<char*>("items"), NULL},
  11229. {NULL} /* Sentinel */
  11230. };
  11231. PyMethodDef PyOp(MeshIndexing)::tp_methods[] = {
  11232. {const_cast<char*>("__getstate__"), PyOp(MeshIndexing)::getstate, METH_NOARGS, "MeshIndexing getstate"},
  11233. {const_cast<char*>("__setstate__"), PyOp(MeshIndexing)::setstate, METH_VARARGS, "MeshIndexing setstate"},
  11234. {NULL} /* Sentinel */
  11235. };
  11236. void _init_py_MeshIndexing(py::module m) {
  11237. using py_op = PyOp(MeshIndexing);
  11238. auto& py_type = PyOpType(MeshIndexing);
  11239. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11240. py_type.tp_name = "megengine.core._imperative_rt.ops.MeshIndexing";
  11241. py_type.tp_basicsize = sizeof(PyOp(MeshIndexing));
  11242. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11243. py_type.tp_doc = "MeshIndexing";
  11244. py_type.tp_base = &PyOpType(OpDef);
  11245. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11246. py_type.tp_new = py_new_generic<py_op>;
  11247. py_type.tp_init = py_op::py_init;
  11248. py_type.tp_methods = py_op::tp_methods;
  11249. py_type.tp_getset = py_op::py_getsetters;
  11250. mgb_assert(PyType_Ready(&py_type) >= 0);
  11251. PyType_Modified(&py_type);
  11252. m.add_object("MeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  11253. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MeshIndexing::typeinfo(), &py_type).second);
  11254. }
  11255. PyOpDefBegin(NMSKeep) // {
  11256. static PyGetSetDef py_getsetters[];
  11257. static PyMethodDef tp_methods[];
  11258. static PyObject* getstate(PyObject* self, PyObject*) {
  11259. auto& opdef = reinterpret_cast<PyOp(NMSKeep)*>(self)->inst();
  11260. static_cast<void>(opdef);
  11261. std::unordered_map<std::string, py::object> state {
  11262. {"iou_thresh", serialization<decltype(opdef.iou_thresh)>::dump(opdef.iou_thresh)},
  11263. {"max_output", serialization<decltype(opdef.max_output)>::dump(opdef.max_output)}
  11264. };
  11265. return py::cast(state).release().ptr();
  11266. }
  11267. static PyObject* setstate(PyObject* self, PyObject* args) {
  11268. PyObject* dict = PyTuple_GetItem(args, 0);
  11269. if (!dict) return NULL;
  11270. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11271. auto& opdef = reinterpret_cast<PyOp(NMSKeep)*>(self)->inst();
  11272. static_cast<void>(opdef);
  11273. {
  11274. auto&& iter = state.find("iou_thresh");
  11275. if (iter != state.end()) {
  11276. opdef.iou_thresh = serialization<decltype(opdef.iou_thresh)>::load(iter->second);
  11277. }
  11278. }
  11279. {
  11280. auto&& iter = state.find("max_output");
  11281. if (iter != state.end()) {
  11282. opdef.max_output = serialization<decltype(opdef.max_output)>::load(iter->second);
  11283. }
  11284. }
  11285. Py_RETURN_NONE;
  11286. }
  11287. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11288. // };
  11289. PyOpDefEnd(NMSKeep)
  11290. int PyOp(NMSKeep)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11291. static const char* kwlist[] = {"iou_thresh", "max_output", "scope", NULL};
  11292. PyObject *iou_thresh = NULL, *max_output = NULL, *scope = NULL;
  11293. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &iou_thresh, &max_output, &scope))
  11294. return -1;
  11295. if (iou_thresh) {
  11296. try {
  11297. // TODO: remove this guard which is used for pybind11 implicit conversion
  11298. py::detail::loader_life_support guard{};
  11299. reinterpret_cast<PyOp(NMSKeep)*>(self)->inst().iou_thresh =
  11300. py::cast<decltype(NMSKeep::iou_thresh)>(py::handle(iou_thresh));
  11301. } CATCH_ALL(-1)
  11302. }
  11303. if (max_output) {
  11304. try {
  11305. // TODO: remove this guard which is used for pybind11 implicit conversion
  11306. py::detail::loader_life_support guard{};
  11307. reinterpret_cast<PyOp(NMSKeep)*>(self)->inst().max_output =
  11308. py::cast<decltype(NMSKeep::max_output)>(py::handle(max_output));
  11309. } CATCH_ALL(-1)
  11310. }
  11311. if (scope) {
  11312. try {
  11313. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11314. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11315. } CATCH_ALL(-1)
  11316. }
  11317. return 0;
  11318. }
  11319. PyGetSetDef PyOp(NMSKeep)::py_getsetters[] = {
  11320. {const_cast<char*>("iou_thresh"), py_get_generic(NMSKeep, iou_thresh), py_set_generic(NMSKeep, iou_thresh), const_cast<char*>("iou_thresh"), NULL},
  11321. {const_cast<char*>("max_output"), py_get_generic(NMSKeep, max_output), py_set_generic(NMSKeep, max_output), const_cast<char*>("max_output"), NULL},
  11322. {NULL} /* Sentinel */
  11323. };
  11324. PyMethodDef PyOp(NMSKeep)::tp_methods[] = {
  11325. {const_cast<char*>("__getstate__"), PyOp(NMSKeep)::getstate, METH_NOARGS, "NMSKeep getstate"},
  11326. {const_cast<char*>("__setstate__"), PyOp(NMSKeep)::setstate, METH_VARARGS, "NMSKeep setstate"},
  11327. {NULL} /* Sentinel */
  11328. };
  11329. void _init_py_NMSKeep(py::module m) {
  11330. using py_op = PyOp(NMSKeep);
  11331. auto& py_type = PyOpType(NMSKeep);
  11332. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11333. py_type.tp_name = "megengine.core._imperative_rt.ops.NMSKeep";
  11334. py_type.tp_basicsize = sizeof(PyOp(NMSKeep));
  11335. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11336. py_type.tp_doc = "NMSKeep";
  11337. py_type.tp_base = &PyOpType(OpDef);
  11338. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11339. py_type.tp_new = py_new_generic<py_op>;
  11340. py_type.tp_init = py_op::py_init;
  11341. py_type.tp_methods = py_op::tp_methods;
  11342. py_type.tp_getset = py_op::py_getsetters;
  11343. mgb_assert(PyType_Ready(&py_type) >= 0);
  11344. PyType_Modified(&py_type);
  11345. m.add_object("NMSKeep", reinterpret_cast<PyObject*>(&py_type));
  11346. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NMSKeep::typeinfo(), &py_type).second);
  11347. }
  11348. PyOpDefBegin(NvOf) // {
  11349. static PyGetSetDef py_getsetters[];
  11350. static PyMethodDef tp_methods[];
  11351. static PyObject* getstate(PyObject* self, PyObject*) {
  11352. auto& opdef = reinterpret_cast<PyOp(NvOf)*>(self)->inst();
  11353. static_cast<void>(opdef);
  11354. std::unordered_map<std::string, py::object> state {
  11355. {"precision", serialization<decltype(opdef.precision)>::dump(opdef.precision)}
  11356. };
  11357. return py::cast(state).release().ptr();
  11358. }
  11359. static PyObject* setstate(PyObject* self, PyObject* args) {
  11360. PyObject* dict = PyTuple_GetItem(args, 0);
  11361. if (!dict) return NULL;
  11362. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11363. auto& opdef = reinterpret_cast<PyOp(NvOf)*>(self)->inst();
  11364. static_cast<void>(opdef);
  11365. {
  11366. auto&& iter = state.find("precision");
  11367. if (iter != state.end()) {
  11368. opdef.precision = serialization<decltype(opdef.precision)>::load(iter->second);
  11369. }
  11370. }
  11371. Py_RETURN_NONE;
  11372. }
  11373. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11374. // };
  11375. PyOpDefEnd(NvOf)
  11376. int PyOp(NvOf)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11377. static const char* kwlist[] = {"precision", "scope", NULL};
  11378. PyObject *precision = NULL, *scope = NULL;
  11379. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &precision, &scope))
  11380. return -1;
  11381. if (precision) {
  11382. try {
  11383. // TODO: remove this guard which is used for pybind11 implicit conversion
  11384. py::detail::loader_life_support guard{};
  11385. reinterpret_cast<PyOp(NvOf)*>(self)->inst().precision =
  11386. py::cast<decltype(NvOf::precision)>(py::handle(precision));
  11387. } CATCH_ALL(-1)
  11388. }
  11389. if (scope) {
  11390. try {
  11391. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11392. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11393. } CATCH_ALL(-1)
  11394. }
  11395. return 0;
  11396. }
  11397. PyGetSetDef PyOp(NvOf)::py_getsetters[] = {
  11398. {const_cast<char*>("precision"), py_get_generic(NvOf, precision), py_set_generic(NvOf, precision), const_cast<char*>("precision"), NULL},
  11399. {NULL} /* Sentinel */
  11400. };
  11401. PyMethodDef PyOp(NvOf)::tp_methods[] = {
  11402. {const_cast<char*>("__getstate__"), PyOp(NvOf)::getstate, METH_NOARGS, "NvOf getstate"},
  11403. {const_cast<char*>("__setstate__"), PyOp(NvOf)::setstate, METH_VARARGS, "NvOf setstate"},
  11404. {NULL} /* Sentinel */
  11405. };
  11406. void _init_py_NvOf(py::module m) {
  11407. using py_op = PyOp(NvOf);
  11408. auto& py_type = PyOpType(NvOf);
  11409. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11410. py_type.tp_name = "megengine.core._imperative_rt.ops.NvOf";
  11411. py_type.tp_basicsize = sizeof(PyOp(NvOf));
  11412. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11413. py_type.tp_doc = "NvOf";
  11414. py_type.tp_base = &PyOpType(OpDef);
  11415. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11416. py_type.tp_new = py_new_generic<py_op>;
  11417. py_type.tp_init = py_op::py_init;
  11418. py_type.tp_methods = py_op::tp_methods;
  11419. py_type.tp_getset = py_op::py_getsetters;
  11420. mgb_assert(PyType_Ready(&py_type) >= 0);
  11421. PyType_Modified(&py_type);
  11422. m.add_object("NvOf", reinterpret_cast<PyObject*>(&py_type));
  11423. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NvOf::typeinfo(), &py_type).second);
  11424. }
  11425. template<> struct EnumTrait<Padding::PaddingMode> {
  11426. static constexpr const char *name = "Padding.PaddingMode";
  11427. static constexpr std::underlying_type_t<Padding::PaddingMode> max = 3 - 1;
  11428. };
  11429. template<> PyTypeObject* EnumWrapper<Padding::PaddingMode>::type = nullptr;
  11430. template<> const char*
  11431. EnumWrapper<Padding::PaddingMode>::members[] = {"REPLICATE", "REFLECT", "CONSTANT"};
  11432. template<> std::unordered_map<std::string, Padding::PaddingMode>
  11433. EnumWrapper<Padding::PaddingMode>::mem2value = {{normalize_enum("REPLICATE"), Padding::PaddingMode::REPLICATE}, {normalize_enum("REFLECT"), Padding::PaddingMode::REFLECT}, {normalize_enum("CONSTANT"), Padding::PaddingMode::CONSTANT}};
  11434. template<> PyObject* EnumWrapper<Padding::PaddingMode>::pyobj_insts[3] = {nullptr};
  11435. void _init_py_Padding_PaddingMode(PyTypeObject& py_type) {
  11436. auto& e_type = EnumWrapper<Padding::PaddingMode>::type;
  11437. static PyMethodDef tp_methods[] = {
  11438. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Padding::PaddingMode>::py_dump, METH_NOARGS, NULL},
  11439. {NULL} /* Sentinel */
  11440. };
  11441. static PyType_Slot slots[] = {
  11442. {Py_tp_repr, (void*)EnumWrapper<Padding::PaddingMode>::py_repr},
  11443. {Py_tp_richcompare, (void*)EnumWrapper<Padding::PaddingMode>::tp_richcompare},
  11444. {Py_tp_methods, tp_methods},
  11445. {0, NULL}
  11446. };
  11447. static PyType_Spec spec = {
  11448. // name
  11449. "megengine.core._imperative_rt.ops.Padding.PaddingMode",
  11450. // basicsize
  11451. sizeof(EnumWrapper<Padding::PaddingMode>),
  11452. // itemsize
  11453. 0,
  11454. // flags
  11455. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  11456. // slots
  11457. slots
  11458. };
  11459. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  11460. mgb_assert(
  11461. e_type->tp_setattro(
  11462. reinterpret_cast<PyObject*>(e_type),
  11463. py::cast("__name__").release().ptr(),
  11464. py::cast("PaddingMode").release().ptr()) >= 0);
  11465. mgb_assert(
  11466. e_type->tp_setattro(
  11467. reinterpret_cast<PyObject*>(e_type),
  11468. py::cast("__module__").release().ptr(),
  11469. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  11470. mgb_assert(
  11471. e_type->tp_setattro(
  11472. reinterpret_cast<PyObject*>(e_type),
  11473. py::cast("__qualname__").release().ptr(),
  11474. py::cast("Padding.PaddingMode").release().ptr()) >= 0);
  11475. {
  11476. PyObject* inst = e_type->tp_alloc(e_type, 0);
  11477. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::REPLICATE;
  11478. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0);
  11479. EnumWrapper<Padding::PaddingMode>::pyobj_insts[0] = inst;
  11480. }{
  11481. PyObject* inst = e_type->tp_alloc(e_type, 0);
  11482. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::REFLECT;
  11483. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0);
  11484. EnumWrapper<Padding::PaddingMode>::pyobj_insts[1] = inst;
  11485. }{
  11486. PyObject* inst = e_type->tp_alloc(e_type, 0);
  11487. reinterpret_cast<EnumWrapper<Padding::PaddingMode>*>(inst)->value = Padding::PaddingMode::CONSTANT;
  11488. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0);
  11489. EnumWrapper<Padding::PaddingMode>::pyobj_insts[2] = inst;
  11490. }
  11491. Py_INCREF(e_type);
  11492. mgb_assert(PyDict_SetItemString(
  11493. py_type.tp_dict, "PaddingMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  11494. }
  11495. PyOpDefBegin(Padding) // {
  11496. static PyGetSetDef py_getsetters[];
  11497. static PyMethodDef tp_methods[];
  11498. static PyObject* getstate(PyObject* self, PyObject*) {
  11499. auto& opdef = reinterpret_cast<PyOp(Padding)*>(self)->inst();
  11500. static_cast<void>(opdef);
  11501. std::unordered_map<std::string, py::object> state {
  11502. {"front_offset_dim0", serialization<decltype(opdef.front_offset_dim0)>::dump(opdef.front_offset_dim0)},
  11503. {"front_offset_dim1", serialization<decltype(opdef.front_offset_dim1)>::dump(opdef.front_offset_dim1)},
  11504. {"front_offset_dim2", serialization<decltype(opdef.front_offset_dim2)>::dump(opdef.front_offset_dim2)},
  11505. {"front_offset_dim3", serialization<decltype(opdef.front_offset_dim3)>::dump(opdef.front_offset_dim3)},
  11506. {"front_offset_dim4", serialization<decltype(opdef.front_offset_dim4)>::dump(opdef.front_offset_dim4)},
  11507. {"front_offset_dim5", serialization<decltype(opdef.front_offset_dim5)>::dump(opdef.front_offset_dim5)},
  11508. {"front_offset_dim6", serialization<decltype(opdef.front_offset_dim6)>::dump(opdef.front_offset_dim6)},
  11509. {"back_offset_dim0", serialization<decltype(opdef.back_offset_dim0)>::dump(opdef.back_offset_dim0)},
  11510. {"back_offset_dim1", serialization<decltype(opdef.back_offset_dim1)>::dump(opdef.back_offset_dim1)},
  11511. {"back_offset_dim2", serialization<decltype(opdef.back_offset_dim2)>::dump(opdef.back_offset_dim2)},
  11512. {"back_offset_dim3", serialization<decltype(opdef.back_offset_dim3)>::dump(opdef.back_offset_dim3)},
  11513. {"back_offset_dim4", serialization<decltype(opdef.back_offset_dim4)>::dump(opdef.back_offset_dim4)},
  11514. {"back_offset_dim5", serialization<decltype(opdef.back_offset_dim5)>::dump(opdef.back_offset_dim5)},
  11515. {"back_offset_dim6", serialization<decltype(opdef.back_offset_dim6)>::dump(opdef.back_offset_dim6)},
  11516. {"padding_val", serialization<decltype(opdef.padding_val)>::dump(opdef.padding_val)},
  11517. {"padding_mode", serialization<decltype(opdef.padding_mode)>::dump(opdef.padding_mode)}
  11518. };
  11519. return py::cast(state).release().ptr();
  11520. }
  11521. static PyObject* setstate(PyObject* self, PyObject* args) {
  11522. PyObject* dict = PyTuple_GetItem(args, 0);
  11523. if (!dict) return NULL;
  11524. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11525. auto& opdef = reinterpret_cast<PyOp(Padding)*>(self)->inst();
  11526. static_cast<void>(opdef);
  11527. {
  11528. auto&& iter = state.find("front_offset_dim0");
  11529. if (iter != state.end()) {
  11530. opdef.front_offset_dim0 = serialization<decltype(opdef.front_offset_dim0)>::load(iter->second);
  11531. }
  11532. }
  11533. {
  11534. auto&& iter = state.find("front_offset_dim1");
  11535. if (iter != state.end()) {
  11536. opdef.front_offset_dim1 = serialization<decltype(opdef.front_offset_dim1)>::load(iter->second);
  11537. }
  11538. }
  11539. {
  11540. auto&& iter = state.find("front_offset_dim2");
  11541. if (iter != state.end()) {
  11542. opdef.front_offset_dim2 = serialization<decltype(opdef.front_offset_dim2)>::load(iter->second);
  11543. }
  11544. }
  11545. {
  11546. auto&& iter = state.find("front_offset_dim3");
  11547. if (iter != state.end()) {
  11548. opdef.front_offset_dim3 = serialization<decltype(opdef.front_offset_dim3)>::load(iter->second);
  11549. }
  11550. }
  11551. {
  11552. auto&& iter = state.find("front_offset_dim4");
  11553. if (iter != state.end()) {
  11554. opdef.front_offset_dim4 = serialization<decltype(opdef.front_offset_dim4)>::load(iter->second);
  11555. }
  11556. }
  11557. {
  11558. auto&& iter = state.find("front_offset_dim5");
  11559. if (iter != state.end()) {
  11560. opdef.front_offset_dim5 = serialization<decltype(opdef.front_offset_dim5)>::load(iter->second);
  11561. }
  11562. }
  11563. {
  11564. auto&& iter = state.find("front_offset_dim6");
  11565. if (iter != state.end()) {
  11566. opdef.front_offset_dim6 = serialization<decltype(opdef.front_offset_dim6)>::load(iter->second);
  11567. }
  11568. }
  11569. {
  11570. auto&& iter = state.find("back_offset_dim0");
  11571. if (iter != state.end()) {
  11572. opdef.back_offset_dim0 = serialization<decltype(opdef.back_offset_dim0)>::load(iter->second);
  11573. }
  11574. }
  11575. {
  11576. auto&& iter = state.find("back_offset_dim1");
  11577. if (iter != state.end()) {
  11578. opdef.back_offset_dim1 = serialization<decltype(opdef.back_offset_dim1)>::load(iter->second);
  11579. }
  11580. }
  11581. {
  11582. auto&& iter = state.find("back_offset_dim2");
  11583. if (iter != state.end()) {
  11584. opdef.back_offset_dim2 = serialization<decltype(opdef.back_offset_dim2)>::load(iter->second);
  11585. }
  11586. }
  11587. {
  11588. auto&& iter = state.find("back_offset_dim3");
  11589. if (iter != state.end()) {
  11590. opdef.back_offset_dim3 = serialization<decltype(opdef.back_offset_dim3)>::load(iter->second);
  11591. }
  11592. }
  11593. {
  11594. auto&& iter = state.find("back_offset_dim4");
  11595. if (iter != state.end()) {
  11596. opdef.back_offset_dim4 = serialization<decltype(opdef.back_offset_dim4)>::load(iter->second);
  11597. }
  11598. }
  11599. {
  11600. auto&& iter = state.find("back_offset_dim5");
  11601. if (iter != state.end()) {
  11602. opdef.back_offset_dim5 = serialization<decltype(opdef.back_offset_dim5)>::load(iter->second);
  11603. }
  11604. }
  11605. {
  11606. auto&& iter = state.find("back_offset_dim6");
  11607. if (iter != state.end()) {
  11608. opdef.back_offset_dim6 = serialization<decltype(opdef.back_offset_dim6)>::load(iter->second);
  11609. }
  11610. }
  11611. {
  11612. auto&& iter = state.find("padding_val");
  11613. if (iter != state.end()) {
  11614. opdef.padding_val = serialization<decltype(opdef.padding_val)>::load(iter->second);
  11615. }
  11616. }
  11617. {
  11618. auto&& iter = state.find("padding_mode");
  11619. if (iter != state.end()) {
  11620. opdef.padding_mode = serialization<decltype(opdef.padding_mode)>::load(iter->second);
  11621. }
  11622. }
  11623. Py_RETURN_NONE;
  11624. }
  11625. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11626. // };
  11627. PyOpDefEnd(Padding)
  11628. int PyOp(Padding)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11629. 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};
  11630. 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;
  11631. 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))
  11632. return -1;
  11633. if (front_offset_dim0) {
  11634. try {
  11635. // TODO: remove this guard which is used for pybind11 implicit conversion
  11636. py::detail::loader_life_support guard{};
  11637. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim0 =
  11638. py::cast<decltype(Padding::front_offset_dim0)>(py::handle(front_offset_dim0));
  11639. } CATCH_ALL(-1)
  11640. }
  11641. if (front_offset_dim1) {
  11642. try {
  11643. // TODO: remove this guard which is used for pybind11 implicit conversion
  11644. py::detail::loader_life_support guard{};
  11645. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim1 =
  11646. py::cast<decltype(Padding::front_offset_dim1)>(py::handle(front_offset_dim1));
  11647. } CATCH_ALL(-1)
  11648. }
  11649. if (front_offset_dim2) {
  11650. try {
  11651. // TODO: remove this guard which is used for pybind11 implicit conversion
  11652. py::detail::loader_life_support guard{};
  11653. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim2 =
  11654. py::cast<decltype(Padding::front_offset_dim2)>(py::handle(front_offset_dim2));
  11655. } CATCH_ALL(-1)
  11656. }
  11657. if (front_offset_dim3) {
  11658. try {
  11659. // TODO: remove this guard which is used for pybind11 implicit conversion
  11660. py::detail::loader_life_support guard{};
  11661. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim3 =
  11662. py::cast<decltype(Padding::front_offset_dim3)>(py::handle(front_offset_dim3));
  11663. } CATCH_ALL(-1)
  11664. }
  11665. if (front_offset_dim4) {
  11666. try {
  11667. // TODO: remove this guard which is used for pybind11 implicit conversion
  11668. py::detail::loader_life_support guard{};
  11669. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim4 =
  11670. py::cast<decltype(Padding::front_offset_dim4)>(py::handle(front_offset_dim4));
  11671. } CATCH_ALL(-1)
  11672. }
  11673. if (front_offset_dim5) {
  11674. try {
  11675. // TODO: remove this guard which is used for pybind11 implicit conversion
  11676. py::detail::loader_life_support guard{};
  11677. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim5 =
  11678. py::cast<decltype(Padding::front_offset_dim5)>(py::handle(front_offset_dim5));
  11679. } CATCH_ALL(-1)
  11680. }
  11681. if (front_offset_dim6) {
  11682. try {
  11683. // TODO: remove this guard which is used for pybind11 implicit conversion
  11684. py::detail::loader_life_support guard{};
  11685. reinterpret_cast<PyOp(Padding)*>(self)->inst().front_offset_dim6 =
  11686. py::cast<decltype(Padding::front_offset_dim6)>(py::handle(front_offset_dim6));
  11687. } CATCH_ALL(-1)
  11688. }
  11689. if (back_offset_dim0) {
  11690. try {
  11691. // TODO: remove this guard which is used for pybind11 implicit conversion
  11692. py::detail::loader_life_support guard{};
  11693. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim0 =
  11694. py::cast<decltype(Padding::back_offset_dim0)>(py::handle(back_offset_dim0));
  11695. } CATCH_ALL(-1)
  11696. }
  11697. if (back_offset_dim1) {
  11698. try {
  11699. // TODO: remove this guard which is used for pybind11 implicit conversion
  11700. py::detail::loader_life_support guard{};
  11701. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim1 =
  11702. py::cast<decltype(Padding::back_offset_dim1)>(py::handle(back_offset_dim1));
  11703. } CATCH_ALL(-1)
  11704. }
  11705. if (back_offset_dim2) {
  11706. try {
  11707. // TODO: remove this guard which is used for pybind11 implicit conversion
  11708. py::detail::loader_life_support guard{};
  11709. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim2 =
  11710. py::cast<decltype(Padding::back_offset_dim2)>(py::handle(back_offset_dim2));
  11711. } CATCH_ALL(-1)
  11712. }
  11713. if (back_offset_dim3) {
  11714. try {
  11715. // TODO: remove this guard which is used for pybind11 implicit conversion
  11716. py::detail::loader_life_support guard{};
  11717. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim3 =
  11718. py::cast<decltype(Padding::back_offset_dim3)>(py::handle(back_offset_dim3));
  11719. } CATCH_ALL(-1)
  11720. }
  11721. if (back_offset_dim4) {
  11722. try {
  11723. // TODO: remove this guard which is used for pybind11 implicit conversion
  11724. py::detail::loader_life_support guard{};
  11725. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim4 =
  11726. py::cast<decltype(Padding::back_offset_dim4)>(py::handle(back_offset_dim4));
  11727. } CATCH_ALL(-1)
  11728. }
  11729. if (back_offset_dim5) {
  11730. try {
  11731. // TODO: remove this guard which is used for pybind11 implicit conversion
  11732. py::detail::loader_life_support guard{};
  11733. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim5 =
  11734. py::cast<decltype(Padding::back_offset_dim5)>(py::handle(back_offset_dim5));
  11735. } CATCH_ALL(-1)
  11736. }
  11737. if (back_offset_dim6) {
  11738. try {
  11739. // TODO: remove this guard which is used for pybind11 implicit conversion
  11740. py::detail::loader_life_support guard{};
  11741. reinterpret_cast<PyOp(Padding)*>(self)->inst().back_offset_dim6 =
  11742. py::cast<decltype(Padding::back_offset_dim6)>(py::handle(back_offset_dim6));
  11743. } CATCH_ALL(-1)
  11744. }
  11745. if (padding_val) {
  11746. try {
  11747. // TODO: remove this guard which is used for pybind11 implicit conversion
  11748. py::detail::loader_life_support guard{};
  11749. reinterpret_cast<PyOp(Padding)*>(self)->inst().padding_val =
  11750. py::cast<decltype(Padding::padding_val)>(py::handle(padding_val));
  11751. } CATCH_ALL(-1)
  11752. }
  11753. if (padding_mode) {
  11754. try {
  11755. // TODO: remove this guard which is used for pybind11 implicit conversion
  11756. py::detail::loader_life_support guard{};
  11757. reinterpret_cast<PyOp(Padding)*>(self)->inst().padding_mode =
  11758. py::cast<decltype(Padding::padding_mode)>(py::handle(padding_mode));
  11759. } CATCH_ALL(-1)
  11760. }
  11761. if (scope) {
  11762. try {
  11763. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11764. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11765. } CATCH_ALL(-1)
  11766. }
  11767. return 0;
  11768. }
  11769. PyGetSetDef PyOp(Padding)::py_getsetters[] = {
  11770. {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},
  11771. {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},
  11772. {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},
  11773. {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},
  11774. {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},
  11775. {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},
  11776. {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},
  11777. {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},
  11778. {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},
  11779. {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},
  11780. {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},
  11781. {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},
  11782. {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},
  11783. {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},
  11784. {const_cast<char*>("padding_val"), py_get_generic(Padding, padding_val), py_set_generic(Padding, padding_val), const_cast<char*>("padding_val"), NULL},
  11785. {const_cast<char*>("padding_mode"), py_get_generic(Padding, padding_mode), py_set_generic(Padding, padding_mode), const_cast<char*>("padding_mode"), NULL},
  11786. {NULL} /* Sentinel */
  11787. };
  11788. PyMethodDef PyOp(Padding)::tp_methods[] = {
  11789. {const_cast<char*>("__getstate__"), PyOp(Padding)::getstate, METH_NOARGS, "Padding getstate"},
  11790. {const_cast<char*>("__setstate__"), PyOp(Padding)::setstate, METH_VARARGS, "Padding setstate"},
  11791. {NULL} /* Sentinel */
  11792. };
  11793. void _init_py_Padding(py::module m) {
  11794. using py_op = PyOp(Padding);
  11795. auto& py_type = PyOpType(Padding);
  11796. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11797. py_type.tp_name = "megengine.core._imperative_rt.ops.Padding";
  11798. py_type.tp_basicsize = sizeof(PyOp(Padding));
  11799. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11800. py_type.tp_doc = "Padding";
  11801. py_type.tp_base = &PyOpType(OpDef);
  11802. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11803. py_type.tp_new = py_new_generic<py_op>;
  11804. py_type.tp_init = py_op::py_init;
  11805. py_type.tp_methods = py_op::tp_methods;
  11806. py_type.tp_getset = py_op::py_getsetters;
  11807. mgb_assert(PyType_Ready(&py_type) >= 0);
  11808. _init_py_Padding_PaddingMode(py_type);
  11809. PyType_Modified(&py_type);
  11810. m.add_object("Padding", reinterpret_cast<PyObject*>(&py_type));
  11811. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Padding::typeinfo(), &py_type).second);
  11812. }
  11813. PyOpDefBegin(ParamPackConcat) // {
  11814. static PyGetSetDef py_getsetters[];
  11815. static PyMethodDef tp_methods[];
  11816. static PyObject* getstate(PyObject* self, PyObject*) {
  11817. auto& opdef = reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst();
  11818. static_cast<void>(opdef);
  11819. std::unordered_map<std::string, py::object> state {
  11820. {"offsets", serialization<decltype(opdef.offsets)>::dump(opdef.offsets)}
  11821. };
  11822. return py::cast(state).release().ptr();
  11823. }
  11824. static PyObject* setstate(PyObject* self, PyObject* args) {
  11825. PyObject* dict = PyTuple_GetItem(args, 0);
  11826. if (!dict) return NULL;
  11827. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11828. auto& opdef = reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst();
  11829. static_cast<void>(opdef);
  11830. {
  11831. auto&& iter = state.find("offsets");
  11832. if (iter != state.end()) {
  11833. opdef.offsets = serialization<decltype(opdef.offsets)>::load(iter->second);
  11834. }
  11835. }
  11836. Py_RETURN_NONE;
  11837. }
  11838. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11839. // };
  11840. PyOpDefEnd(ParamPackConcat)
  11841. int PyOp(ParamPackConcat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11842. static const char* kwlist[] = {"offsets", "scope", NULL};
  11843. PyObject *offsets = NULL, *scope = NULL;
  11844. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &offsets, &scope))
  11845. return -1;
  11846. if (offsets) {
  11847. try {
  11848. // TODO: remove this guard which is used for pybind11 implicit conversion
  11849. py::detail::loader_life_support guard{};
  11850. reinterpret_cast<PyOp(ParamPackConcat)*>(self)->inst().offsets =
  11851. py::cast<decltype(ParamPackConcat::offsets)>(py::handle(offsets));
  11852. } CATCH_ALL(-1)
  11853. }
  11854. if (scope) {
  11855. try {
  11856. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11857. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11858. } CATCH_ALL(-1)
  11859. }
  11860. return 0;
  11861. }
  11862. PyGetSetDef PyOp(ParamPackConcat)::py_getsetters[] = {
  11863. {const_cast<char*>("offsets"), py_get_generic(ParamPackConcat, offsets), py_set_generic(ParamPackConcat, offsets), const_cast<char*>("offsets"), NULL},
  11864. {NULL} /* Sentinel */
  11865. };
  11866. PyMethodDef PyOp(ParamPackConcat)::tp_methods[] = {
  11867. {const_cast<char*>("__getstate__"), PyOp(ParamPackConcat)::getstate, METH_NOARGS, "ParamPackConcat getstate"},
  11868. {const_cast<char*>("__setstate__"), PyOp(ParamPackConcat)::setstate, METH_VARARGS, "ParamPackConcat setstate"},
  11869. {NULL} /* Sentinel */
  11870. };
  11871. void _init_py_ParamPackConcat(py::module m) {
  11872. using py_op = PyOp(ParamPackConcat);
  11873. auto& py_type = PyOpType(ParamPackConcat);
  11874. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11875. py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackConcat";
  11876. py_type.tp_basicsize = sizeof(PyOp(ParamPackConcat));
  11877. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11878. py_type.tp_doc = "ParamPackConcat";
  11879. py_type.tp_base = &PyOpType(OpDef);
  11880. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11881. py_type.tp_new = py_new_generic<py_op>;
  11882. py_type.tp_init = py_op::py_init;
  11883. py_type.tp_methods = py_op::tp_methods;
  11884. py_type.tp_getset = py_op::py_getsetters;
  11885. mgb_assert(PyType_Ready(&py_type) >= 0);
  11886. PyType_Modified(&py_type);
  11887. m.add_object("ParamPackConcat", reinterpret_cast<PyObject*>(&py_type));
  11888. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackConcat::typeinfo(), &py_type).second);
  11889. }
  11890. PyOpDefBegin(ParamPackSplit) // {
  11891. static PyGetSetDef py_getsetters[];
  11892. static PyMethodDef tp_methods[];
  11893. static PyObject* getstate(PyObject* self, PyObject*) {
  11894. auto& opdef = reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst();
  11895. static_cast<void>(opdef);
  11896. std::unordered_map<std::string, py::object> state {
  11897. {"offsets", serialization<decltype(opdef.offsets)>::dump(opdef.offsets)},
  11898. {"shapes", serialization<decltype(opdef.shapes)>::dump(opdef.shapes)}
  11899. };
  11900. return py::cast(state).release().ptr();
  11901. }
  11902. static PyObject* setstate(PyObject* self, PyObject* args) {
  11903. PyObject* dict = PyTuple_GetItem(args, 0);
  11904. if (!dict) return NULL;
  11905. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  11906. auto& opdef = reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst();
  11907. static_cast<void>(opdef);
  11908. {
  11909. auto&& iter = state.find("offsets");
  11910. if (iter != state.end()) {
  11911. opdef.offsets = serialization<decltype(opdef.offsets)>::load(iter->second);
  11912. }
  11913. }
  11914. {
  11915. auto&& iter = state.find("shapes");
  11916. if (iter != state.end()) {
  11917. opdef.shapes = serialization<decltype(opdef.shapes)>::load(iter->second);
  11918. }
  11919. }
  11920. Py_RETURN_NONE;
  11921. }
  11922. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  11923. // };
  11924. PyOpDefEnd(ParamPackSplit)
  11925. int PyOp(ParamPackSplit)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  11926. static const char* kwlist[] = {"offsets", "shapes", "scope", NULL};
  11927. PyObject *offsets = NULL, *shapes = NULL, *scope = NULL;
  11928. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &offsets, &shapes, &scope))
  11929. return -1;
  11930. if (offsets) {
  11931. try {
  11932. // TODO: remove this guard which is used for pybind11 implicit conversion
  11933. py::detail::loader_life_support guard{};
  11934. reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst().offsets =
  11935. py::cast<decltype(ParamPackSplit::offsets)>(py::handle(offsets));
  11936. } CATCH_ALL(-1)
  11937. }
  11938. if (shapes) {
  11939. try {
  11940. // TODO: remove this guard which is used for pybind11 implicit conversion
  11941. py::detail::loader_life_support guard{};
  11942. reinterpret_cast<PyOp(ParamPackSplit)*>(self)->inst().shapes =
  11943. py::cast<decltype(ParamPackSplit::shapes)>(py::handle(shapes));
  11944. } CATCH_ALL(-1)
  11945. }
  11946. if (scope) {
  11947. try {
  11948. reinterpret_cast<PyOp(OpDef)*>(self)->op
  11949. ->set_scope(py::cast<std::string>(py::handle(scope)));
  11950. } CATCH_ALL(-1)
  11951. }
  11952. return 0;
  11953. }
  11954. PyGetSetDef PyOp(ParamPackSplit)::py_getsetters[] = {
  11955. {const_cast<char*>("offsets"), py_get_generic(ParamPackSplit, offsets), py_set_generic(ParamPackSplit, offsets), const_cast<char*>("offsets"), NULL},
  11956. {const_cast<char*>("shapes"), py_get_generic(ParamPackSplit, shapes), py_set_generic(ParamPackSplit, shapes), const_cast<char*>("shapes"), NULL},
  11957. {NULL} /* Sentinel */
  11958. };
  11959. PyMethodDef PyOp(ParamPackSplit)::tp_methods[] = {
  11960. {const_cast<char*>("__getstate__"), PyOp(ParamPackSplit)::getstate, METH_NOARGS, "ParamPackSplit getstate"},
  11961. {const_cast<char*>("__setstate__"), PyOp(ParamPackSplit)::setstate, METH_VARARGS, "ParamPackSplit setstate"},
  11962. {NULL} /* Sentinel */
  11963. };
  11964. void _init_py_ParamPackSplit(py::module m) {
  11965. using py_op = PyOp(ParamPackSplit);
  11966. auto& py_type = PyOpType(ParamPackSplit);
  11967. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  11968. py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackSplit";
  11969. py_type.tp_basicsize = sizeof(PyOp(ParamPackSplit));
  11970. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  11971. py_type.tp_doc = "ParamPackSplit";
  11972. py_type.tp_base = &PyOpType(OpDef);
  11973. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  11974. py_type.tp_new = py_new_generic<py_op>;
  11975. py_type.tp_init = py_op::py_init;
  11976. py_type.tp_methods = py_op::tp_methods;
  11977. py_type.tp_getset = py_op::py_getsetters;
  11978. mgb_assert(PyType_Ready(&py_type) >= 0);
  11979. PyType_Modified(&py_type);
  11980. m.add_object("ParamPackSplit", reinterpret_cast<PyObject*>(&py_type));
  11981. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackSplit::typeinfo(), &py_type).second);
  11982. }
  11983. PyOpDefBegin(PermutationRNG) // {
  11984. static PyGetSetDef py_getsetters[];
  11985. static PyMethodDef tp_methods[];
  11986. static PyObject* getstate(PyObject* self, PyObject*) {
  11987. auto& opdef = reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst();
  11988. static_cast<void>(opdef);
  11989. std::unordered_map<std::string, py::object> state {
  11990. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  11991. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  11992. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  11993. };
  11994. return py::cast(state).release().ptr();
  11995. }
  11996. static PyObject* setstate(PyObject* self, PyObject* args) {
  11997. PyObject* dict = PyTuple_GetItem(args, 0);
  11998. if (!dict) return NULL;
  11999. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12000. auto& opdef = reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst();
  12001. static_cast<void>(opdef);
  12002. {
  12003. auto&& iter = state.find("seed");
  12004. if (iter != state.end()) {
  12005. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  12006. }
  12007. }
  12008. {
  12009. auto&& iter = state.find("dtype");
  12010. if (iter != state.end()) {
  12011. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  12012. }
  12013. }
  12014. {
  12015. auto&& iter = state.find("handle");
  12016. if (iter != state.end()) {
  12017. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  12018. }
  12019. }
  12020. Py_RETURN_NONE;
  12021. }
  12022. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12023. // };
  12024. PyOpDefEnd(PermutationRNG)
  12025. int PyOp(PermutationRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12026. static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL};
  12027. PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  12028. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &seed, &dtype, &handle, &scope))
  12029. return -1;
  12030. if (seed) {
  12031. try {
  12032. // TODO: remove this guard which is used for pybind11 implicit conversion
  12033. py::detail::loader_life_support guard{};
  12034. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().seed =
  12035. py::cast<decltype(PermutationRNG::seed)>(py::handle(seed));
  12036. } CATCH_ALL(-1)
  12037. }
  12038. if (dtype) {
  12039. try {
  12040. // TODO: remove this guard which is used for pybind11 implicit conversion
  12041. py::detail::loader_life_support guard{};
  12042. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().dtype =
  12043. py::cast<decltype(PermutationRNG::dtype)>(py::handle(dtype));
  12044. } CATCH_ALL(-1)
  12045. }
  12046. if (handle) {
  12047. try {
  12048. // TODO: remove this guard which is used for pybind11 implicit conversion
  12049. py::detail::loader_life_support guard{};
  12050. reinterpret_cast<PyOp(PermutationRNG)*>(self)->inst().handle =
  12051. py::cast<decltype(PermutationRNG::handle)>(py::handle(handle));
  12052. } CATCH_ALL(-1)
  12053. }
  12054. if (scope) {
  12055. try {
  12056. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12057. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12058. } CATCH_ALL(-1)
  12059. }
  12060. return 0;
  12061. }
  12062. PyGetSetDef PyOp(PermutationRNG)::py_getsetters[] = {
  12063. {const_cast<char*>("seed"), py_get_generic(PermutationRNG, seed), py_set_generic(PermutationRNG, seed), const_cast<char*>("seed"), NULL},
  12064. {const_cast<char*>("dtype"), py_get_generic(PermutationRNG, dtype), py_set_generic(PermutationRNG, dtype), const_cast<char*>("dtype"), NULL},
  12065. {const_cast<char*>("handle"), py_get_generic(PermutationRNG, handle), py_set_generic(PermutationRNG, handle), const_cast<char*>("handle"), NULL},
  12066. {NULL} /* Sentinel */
  12067. };
  12068. PyMethodDef PyOp(PermutationRNG)::tp_methods[] = {
  12069. {const_cast<char*>("__getstate__"), PyOp(PermutationRNG)::getstate, METH_NOARGS, "PermutationRNG getstate"},
  12070. {const_cast<char*>("__setstate__"), PyOp(PermutationRNG)::setstate, METH_VARARGS, "PermutationRNG setstate"},
  12071. {NULL} /* Sentinel */
  12072. };
  12073. void _init_py_PermutationRNG(py::module m) {
  12074. using py_op = PyOp(PermutationRNG);
  12075. auto& py_type = PyOpType(PermutationRNG);
  12076. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12077. py_type.tp_name = "megengine.core._imperative_rt.ops.PermutationRNG";
  12078. py_type.tp_basicsize = sizeof(PyOp(PermutationRNG));
  12079. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12080. py_type.tp_doc = "PermutationRNG";
  12081. py_type.tp_base = &PyOpType(OpDef);
  12082. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12083. py_type.tp_new = py_new_generic<py_op>;
  12084. py_type.tp_init = py_op::py_init;
  12085. py_type.tp_methods = py_op::tp_methods;
  12086. py_type.tp_getset = py_op::py_getsetters;
  12087. mgb_assert(PyType_Ready(&py_type) >= 0);
  12088. PyType_Modified(&py_type);
  12089. m.add_object("PermutationRNG", reinterpret_cast<PyObject*>(&py_type));
  12090. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PermutationRNG::typeinfo(), &py_type).second);
  12091. }
  12092. PyOpDefBegin(PixelShuffle) // {
  12093. static PyGetSetDef py_getsetters[];
  12094. static PyMethodDef tp_methods[];
  12095. static PyObject* getstate(PyObject* self, PyObject*) {
  12096. auto& opdef = reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst();
  12097. static_cast<void>(opdef);
  12098. std::unordered_map<std::string, py::object> state {
  12099. {"factor", serialization<decltype(opdef.factor)>::dump(opdef.factor)}
  12100. };
  12101. return py::cast(state).release().ptr();
  12102. }
  12103. static PyObject* setstate(PyObject* self, PyObject* args) {
  12104. PyObject* dict = PyTuple_GetItem(args, 0);
  12105. if (!dict) return NULL;
  12106. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12107. auto& opdef = reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst();
  12108. static_cast<void>(opdef);
  12109. {
  12110. auto&& iter = state.find("factor");
  12111. if (iter != state.end()) {
  12112. opdef.factor = serialization<decltype(opdef.factor)>::load(iter->second);
  12113. }
  12114. }
  12115. Py_RETURN_NONE;
  12116. }
  12117. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12118. // };
  12119. PyOpDefEnd(PixelShuffle)
  12120. int PyOp(PixelShuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12121. static const char* kwlist[] = {"factor", "scope", NULL};
  12122. PyObject *factor = NULL, *scope = NULL;
  12123. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &factor, &scope))
  12124. return -1;
  12125. if (factor) {
  12126. try {
  12127. // TODO: remove this guard which is used for pybind11 implicit conversion
  12128. py::detail::loader_life_support guard{};
  12129. reinterpret_cast<PyOp(PixelShuffle)*>(self)->inst().factor =
  12130. py::cast<decltype(PixelShuffle::factor)>(py::handle(factor));
  12131. } CATCH_ALL(-1)
  12132. }
  12133. if (scope) {
  12134. try {
  12135. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12136. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12137. } CATCH_ALL(-1)
  12138. }
  12139. return 0;
  12140. }
  12141. PyGetSetDef PyOp(PixelShuffle)::py_getsetters[] = {
  12142. {const_cast<char*>("factor"), py_get_generic(PixelShuffle, factor), py_set_generic(PixelShuffle, factor), const_cast<char*>("factor"), NULL},
  12143. {NULL} /* Sentinel */
  12144. };
  12145. PyMethodDef PyOp(PixelShuffle)::tp_methods[] = {
  12146. {const_cast<char*>("__getstate__"), PyOp(PixelShuffle)::getstate, METH_NOARGS, "PixelShuffle getstate"},
  12147. {const_cast<char*>("__setstate__"), PyOp(PixelShuffle)::setstate, METH_VARARGS, "PixelShuffle setstate"},
  12148. {NULL} /* Sentinel */
  12149. };
  12150. void _init_py_PixelShuffle(py::module m) {
  12151. using py_op = PyOp(PixelShuffle);
  12152. auto& py_type = PyOpType(PixelShuffle);
  12153. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12154. py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffle";
  12155. py_type.tp_basicsize = sizeof(PyOp(PixelShuffle));
  12156. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12157. py_type.tp_doc = "PixelShuffle";
  12158. py_type.tp_base = &PyOpType(OpDef);
  12159. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12160. py_type.tp_new = py_new_generic<py_op>;
  12161. py_type.tp_init = py_op::py_init;
  12162. py_type.tp_methods = py_op::tp_methods;
  12163. py_type.tp_getset = py_op::py_getsetters;
  12164. mgb_assert(PyType_Ready(&py_type) >= 0);
  12165. PyType_Modified(&py_type);
  12166. m.add_object("PixelShuffle", reinterpret_cast<PyObject*>(&py_type));
  12167. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffle::typeinfo(), &py_type).second);
  12168. }
  12169. PyOpDefBegin(PixelShuffleBackward) // {
  12170. static PyGetSetDef py_getsetters[];
  12171. static PyMethodDef tp_methods[];
  12172. static PyObject* getstate(PyObject* self, PyObject*) {
  12173. auto& opdef = reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst();
  12174. static_cast<void>(opdef);
  12175. std::unordered_map<std::string, py::object> state {
  12176. {"factor", serialization<decltype(opdef.factor)>::dump(opdef.factor)}
  12177. };
  12178. return py::cast(state).release().ptr();
  12179. }
  12180. static PyObject* setstate(PyObject* self, PyObject* args) {
  12181. PyObject* dict = PyTuple_GetItem(args, 0);
  12182. if (!dict) return NULL;
  12183. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12184. auto& opdef = reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst();
  12185. static_cast<void>(opdef);
  12186. {
  12187. auto&& iter = state.find("factor");
  12188. if (iter != state.end()) {
  12189. opdef.factor = serialization<decltype(opdef.factor)>::load(iter->second);
  12190. }
  12191. }
  12192. Py_RETURN_NONE;
  12193. }
  12194. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12195. // };
  12196. PyOpDefEnd(PixelShuffleBackward)
  12197. int PyOp(PixelShuffleBackward)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12198. static const char* kwlist[] = {"factor", "scope", NULL};
  12199. PyObject *factor = NULL, *scope = NULL;
  12200. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &factor, &scope))
  12201. return -1;
  12202. if (factor) {
  12203. try {
  12204. // TODO: remove this guard which is used for pybind11 implicit conversion
  12205. py::detail::loader_life_support guard{};
  12206. reinterpret_cast<PyOp(PixelShuffleBackward)*>(self)->inst().factor =
  12207. py::cast<decltype(PixelShuffleBackward::factor)>(py::handle(factor));
  12208. } CATCH_ALL(-1)
  12209. }
  12210. if (scope) {
  12211. try {
  12212. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12213. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12214. } CATCH_ALL(-1)
  12215. }
  12216. return 0;
  12217. }
  12218. PyGetSetDef PyOp(PixelShuffleBackward)::py_getsetters[] = {
  12219. {const_cast<char*>("factor"), py_get_generic(PixelShuffleBackward, factor), py_set_generic(PixelShuffleBackward, factor), const_cast<char*>("factor"), NULL},
  12220. {NULL} /* Sentinel */
  12221. };
  12222. PyMethodDef PyOp(PixelShuffleBackward)::tp_methods[] = {
  12223. {const_cast<char*>("__getstate__"), PyOp(PixelShuffleBackward)::getstate, METH_NOARGS, "PixelShuffleBackward getstate"},
  12224. {const_cast<char*>("__setstate__"), PyOp(PixelShuffleBackward)::setstate, METH_VARARGS, "PixelShuffleBackward setstate"},
  12225. {NULL} /* Sentinel */
  12226. };
  12227. void _init_py_PixelShuffleBackward(py::module m) {
  12228. using py_op = PyOp(PixelShuffleBackward);
  12229. auto& py_type = PyOpType(PixelShuffleBackward);
  12230. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12231. py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffleBackward";
  12232. py_type.tp_basicsize = sizeof(PyOp(PixelShuffleBackward));
  12233. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12234. py_type.tp_doc = "PixelShuffleBackward";
  12235. py_type.tp_base = &PyOpType(OpDef);
  12236. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12237. py_type.tp_new = py_new_generic<py_op>;
  12238. py_type.tp_init = py_op::py_init;
  12239. py_type.tp_methods = py_op::tp_methods;
  12240. py_type.tp_getset = py_op::py_getsetters;
  12241. mgb_assert(PyType_Ready(&py_type) >= 0);
  12242. PyType_Modified(&py_type);
  12243. m.add_object("PixelShuffleBackward", reinterpret_cast<PyObject*>(&py_type));
  12244. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffleBackward::typeinfo(), &py_type).second);
  12245. }
  12246. PyOpDefBegin(PoissonRNG) // {
  12247. static PyGetSetDef py_getsetters[];
  12248. static PyMethodDef tp_methods[];
  12249. static PyObject* getstate(PyObject* self, PyObject*) {
  12250. auto& opdef = reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst();
  12251. static_cast<void>(opdef);
  12252. std::unordered_map<std::string, py::object> state {
  12253. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  12254. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  12255. };
  12256. return py::cast(state).release().ptr();
  12257. }
  12258. static PyObject* setstate(PyObject* self, PyObject* args) {
  12259. PyObject* dict = PyTuple_GetItem(args, 0);
  12260. if (!dict) return NULL;
  12261. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12262. auto& opdef = reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst();
  12263. static_cast<void>(opdef);
  12264. {
  12265. auto&& iter = state.find("seed");
  12266. if (iter != state.end()) {
  12267. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  12268. }
  12269. }
  12270. {
  12271. auto&& iter = state.find("handle");
  12272. if (iter != state.end()) {
  12273. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  12274. }
  12275. }
  12276. Py_RETURN_NONE;
  12277. }
  12278. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12279. // };
  12280. PyOpDefEnd(PoissonRNG)
  12281. int PyOp(PoissonRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12282. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  12283. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  12284. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  12285. return -1;
  12286. if (seed) {
  12287. try {
  12288. // TODO: remove this guard which is used for pybind11 implicit conversion
  12289. py::detail::loader_life_support guard{};
  12290. reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst().seed =
  12291. py::cast<decltype(PoissonRNG::seed)>(py::handle(seed));
  12292. } CATCH_ALL(-1)
  12293. }
  12294. if (handle) {
  12295. try {
  12296. // TODO: remove this guard which is used for pybind11 implicit conversion
  12297. py::detail::loader_life_support guard{};
  12298. reinterpret_cast<PyOp(PoissonRNG)*>(self)->inst().handle =
  12299. py::cast<decltype(PoissonRNG::handle)>(py::handle(handle));
  12300. } CATCH_ALL(-1)
  12301. }
  12302. if (scope) {
  12303. try {
  12304. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12305. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12306. } CATCH_ALL(-1)
  12307. }
  12308. return 0;
  12309. }
  12310. PyGetSetDef PyOp(PoissonRNG)::py_getsetters[] = {
  12311. {const_cast<char*>("seed"), py_get_generic(PoissonRNG, seed), py_set_generic(PoissonRNG, seed), const_cast<char*>("seed"), NULL},
  12312. {const_cast<char*>("handle"), py_get_generic(PoissonRNG, handle), py_set_generic(PoissonRNG, handle), const_cast<char*>("handle"), NULL},
  12313. {NULL} /* Sentinel */
  12314. };
  12315. PyMethodDef PyOp(PoissonRNG)::tp_methods[] = {
  12316. {const_cast<char*>("__getstate__"), PyOp(PoissonRNG)::getstate, METH_NOARGS, "PoissonRNG getstate"},
  12317. {const_cast<char*>("__setstate__"), PyOp(PoissonRNG)::setstate, METH_VARARGS, "PoissonRNG setstate"},
  12318. {NULL} /* Sentinel */
  12319. };
  12320. void _init_py_PoissonRNG(py::module m) {
  12321. using py_op = PyOp(PoissonRNG);
  12322. auto& py_type = PyOpType(PoissonRNG);
  12323. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12324. py_type.tp_name = "megengine.core._imperative_rt.ops.PoissonRNG";
  12325. py_type.tp_basicsize = sizeof(PyOp(PoissonRNG));
  12326. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12327. py_type.tp_doc = "PoissonRNG";
  12328. py_type.tp_base = &PyOpType(OpDef);
  12329. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12330. py_type.tp_new = py_new_generic<py_op>;
  12331. py_type.tp_init = py_op::py_init;
  12332. py_type.tp_methods = py_op::tp_methods;
  12333. py_type.tp_getset = py_op::py_getsetters;
  12334. mgb_assert(PyType_Ready(&py_type) >= 0);
  12335. PyType_Modified(&py_type);
  12336. m.add_object("PoissonRNG", reinterpret_cast<PyObject*>(&py_type));
  12337. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PoissonRNG::typeinfo(), &py_type).second);
  12338. }
  12339. void _init_py_Pooling_Mode(PyTypeObject& py_type) {
  12340. auto& e_type = EnumWrapper<Pooling::Mode>::type;
  12341. Py_INCREF(e_type);
  12342. mgb_assert(PyDict_SetItemString(
  12343. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12344. }
  12345. void _init_py_Pooling_Format(PyTypeObject& py_type) {
  12346. auto& e_type = EnumWrapper<Pooling::Format>::type;
  12347. Py_INCREF(e_type);
  12348. mgb_assert(PyDict_SetItemString(
  12349. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12350. }
  12351. void _init_py_Pooling_Strategy(PyTypeObject& py_type) {
  12352. auto& e_type = BitCombinedEnumWrapper<Pooling::Strategy>::type;
  12353. Py_INCREF(e_type);
  12354. mgb_assert(PyDict_SetItemString(
  12355. py_type.tp_dict, "Strategy", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12356. }
  12357. PyOpDefBegin(Pooling) // {
  12358. static PyGetSetDef py_getsetters[];
  12359. static PyMethodDef tp_methods[];
  12360. static PyObject* getstate(PyObject* self, PyObject*) {
  12361. auto& opdef = reinterpret_cast<PyOp(Pooling)*>(self)->inst();
  12362. static_cast<void>(opdef);
  12363. std::unordered_map<std::string, py::object> state {
  12364. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  12365. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  12366. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  12367. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  12368. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  12369. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  12370. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)},
  12371. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  12372. {"strategy", serialization<decltype(opdef.strategy)>::dump(opdef.strategy)},
  12373. {"workspace_limit", serialization<decltype(opdef.workspace_limit)>::dump(opdef.workspace_limit)}
  12374. };
  12375. return py::cast(state).release().ptr();
  12376. }
  12377. static PyObject* setstate(PyObject* self, PyObject* args) {
  12378. PyObject* dict = PyTuple_GetItem(args, 0);
  12379. if (!dict) return NULL;
  12380. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12381. auto& opdef = reinterpret_cast<PyOp(Pooling)*>(self)->inst();
  12382. static_cast<void>(opdef);
  12383. {
  12384. auto&& iter = state.find("mode");
  12385. if (iter != state.end()) {
  12386. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  12387. }
  12388. }
  12389. {
  12390. auto&& iter = state.find("pad_h");
  12391. if (iter != state.end()) {
  12392. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  12393. }
  12394. }
  12395. {
  12396. auto&& iter = state.find("pad_w");
  12397. if (iter != state.end()) {
  12398. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  12399. }
  12400. }
  12401. {
  12402. auto&& iter = state.find("stride_h");
  12403. if (iter != state.end()) {
  12404. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  12405. }
  12406. }
  12407. {
  12408. auto&& iter = state.find("stride_w");
  12409. if (iter != state.end()) {
  12410. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  12411. }
  12412. }
  12413. {
  12414. auto&& iter = state.find("window_h");
  12415. if (iter != state.end()) {
  12416. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  12417. }
  12418. }
  12419. {
  12420. auto&& iter = state.find("window_w");
  12421. if (iter != state.end()) {
  12422. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  12423. }
  12424. }
  12425. {
  12426. auto&& iter = state.find("format");
  12427. if (iter != state.end()) {
  12428. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  12429. }
  12430. }
  12431. {
  12432. auto&& iter = state.find("strategy");
  12433. if (iter != state.end()) {
  12434. opdef.strategy = serialization<decltype(opdef.strategy)>::load(iter->second);
  12435. }
  12436. }
  12437. {
  12438. auto&& iter = state.find("workspace_limit");
  12439. if (iter != state.end()) {
  12440. opdef.workspace_limit = serialization<decltype(opdef.workspace_limit)>::load(iter->second);
  12441. }
  12442. }
  12443. Py_RETURN_NONE;
  12444. }
  12445. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12446. // };
  12447. PyOpDefEnd(Pooling)
  12448. int PyOp(Pooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12449. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "window_h", "window_w", "format", "strategy", "workspace_limit", "scope", NULL};
  12450. 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;
  12451. 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))
  12452. return -1;
  12453. if (mode) {
  12454. try {
  12455. // TODO: remove this guard which is used for pybind11 implicit conversion
  12456. py::detail::loader_life_support guard{};
  12457. reinterpret_cast<PyOp(Pooling)*>(self)->inst().mode =
  12458. py::cast<decltype(Pooling::mode)>(py::handle(mode));
  12459. } CATCH_ALL(-1)
  12460. }
  12461. if (pad_h) {
  12462. try {
  12463. // TODO: remove this guard which is used for pybind11 implicit conversion
  12464. py::detail::loader_life_support guard{};
  12465. reinterpret_cast<PyOp(Pooling)*>(self)->inst().pad_h =
  12466. py::cast<decltype(Pooling::pad_h)>(py::handle(pad_h));
  12467. } CATCH_ALL(-1)
  12468. }
  12469. if (pad_w) {
  12470. try {
  12471. // TODO: remove this guard which is used for pybind11 implicit conversion
  12472. py::detail::loader_life_support guard{};
  12473. reinterpret_cast<PyOp(Pooling)*>(self)->inst().pad_w =
  12474. py::cast<decltype(Pooling::pad_w)>(py::handle(pad_w));
  12475. } CATCH_ALL(-1)
  12476. }
  12477. if (stride_h) {
  12478. try {
  12479. // TODO: remove this guard which is used for pybind11 implicit conversion
  12480. py::detail::loader_life_support guard{};
  12481. reinterpret_cast<PyOp(Pooling)*>(self)->inst().stride_h =
  12482. py::cast<decltype(Pooling::stride_h)>(py::handle(stride_h));
  12483. } CATCH_ALL(-1)
  12484. }
  12485. if (stride_w) {
  12486. try {
  12487. // TODO: remove this guard which is used for pybind11 implicit conversion
  12488. py::detail::loader_life_support guard{};
  12489. reinterpret_cast<PyOp(Pooling)*>(self)->inst().stride_w =
  12490. py::cast<decltype(Pooling::stride_w)>(py::handle(stride_w));
  12491. } CATCH_ALL(-1)
  12492. }
  12493. if (window_h) {
  12494. try {
  12495. // TODO: remove this guard which is used for pybind11 implicit conversion
  12496. py::detail::loader_life_support guard{};
  12497. reinterpret_cast<PyOp(Pooling)*>(self)->inst().window_h =
  12498. py::cast<decltype(Pooling::window_h)>(py::handle(window_h));
  12499. } CATCH_ALL(-1)
  12500. }
  12501. if (window_w) {
  12502. try {
  12503. // TODO: remove this guard which is used for pybind11 implicit conversion
  12504. py::detail::loader_life_support guard{};
  12505. reinterpret_cast<PyOp(Pooling)*>(self)->inst().window_w =
  12506. py::cast<decltype(Pooling::window_w)>(py::handle(window_w));
  12507. } CATCH_ALL(-1)
  12508. }
  12509. if (format) {
  12510. try {
  12511. // TODO: remove this guard which is used for pybind11 implicit conversion
  12512. py::detail::loader_life_support guard{};
  12513. reinterpret_cast<PyOp(Pooling)*>(self)->inst().format =
  12514. py::cast<decltype(Pooling::format)>(py::handle(format));
  12515. } CATCH_ALL(-1)
  12516. }
  12517. if (strategy) {
  12518. try {
  12519. // TODO: remove this guard which is used for pybind11 implicit conversion
  12520. py::detail::loader_life_support guard{};
  12521. reinterpret_cast<PyOp(Pooling)*>(self)->inst().strategy =
  12522. py::cast<decltype(Pooling::strategy)>(py::handle(strategy));
  12523. } CATCH_ALL(-1)
  12524. }
  12525. if (workspace_limit) {
  12526. try {
  12527. // TODO: remove this guard which is used for pybind11 implicit conversion
  12528. py::detail::loader_life_support guard{};
  12529. reinterpret_cast<PyOp(Pooling)*>(self)->inst().workspace_limit =
  12530. py::cast<decltype(Pooling::workspace_limit)>(py::handle(workspace_limit));
  12531. } CATCH_ALL(-1)
  12532. }
  12533. if (scope) {
  12534. try {
  12535. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12536. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12537. } CATCH_ALL(-1)
  12538. }
  12539. return 0;
  12540. }
  12541. PyGetSetDef PyOp(Pooling)::py_getsetters[] = {
  12542. {const_cast<char*>("mode"), py_get_generic(Pooling, mode), py_set_generic(Pooling, mode), const_cast<char*>("mode"), NULL},
  12543. {const_cast<char*>("pad_h"), py_get_generic(Pooling, pad_h), py_set_generic(Pooling, pad_h), const_cast<char*>("pad_h"), NULL},
  12544. {const_cast<char*>("pad_w"), py_get_generic(Pooling, pad_w), py_set_generic(Pooling, pad_w), const_cast<char*>("pad_w"), NULL},
  12545. {const_cast<char*>("stride_h"), py_get_generic(Pooling, stride_h), py_set_generic(Pooling, stride_h), const_cast<char*>("stride_h"), NULL},
  12546. {const_cast<char*>("stride_w"), py_get_generic(Pooling, stride_w), py_set_generic(Pooling, stride_w), const_cast<char*>("stride_w"), NULL},
  12547. {const_cast<char*>("window_h"), py_get_generic(Pooling, window_h), py_set_generic(Pooling, window_h), const_cast<char*>("window_h"), NULL},
  12548. {const_cast<char*>("window_w"), py_get_generic(Pooling, window_w), py_set_generic(Pooling, window_w), const_cast<char*>("window_w"), NULL},
  12549. {const_cast<char*>("format"), py_get_generic(Pooling, format), py_set_generic(Pooling, format), const_cast<char*>("format"), NULL},
  12550. {const_cast<char*>("strategy"), py_get_generic(Pooling, strategy), py_set_generic(Pooling, strategy), const_cast<char*>("strategy"), NULL},
  12551. {const_cast<char*>("workspace_limit"), py_get_generic(Pooling, workspace_limit), py_set_generic(Pooling, workspace_limit), const_cast<char*>("workspace_limit"), NULL},
  12552. {NULL} /* Sentinel */
  12553. };
  12554. PyMethodDef PyOp(Pooling)::tp_methods[] = {
  12555. {const_cast<char*>("__getstate__"), PyOp(Pooling)::getstate, METH_NOARGS, "Pooling getstate"},
  12556. {const_cast<char*>("__setstate__"), PyOp(Pooling)::setstate, METH_VARARGS, "Pooling setstate"},
  12557. {NULL} /* Sentinel */
  12558. };
  12559. void _init_py_Pooling(py::module m) {
  12560. using py_op = PyOp(Pooling);
  12561. auto& py_type = PyOpType(Pooling);
  12562. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12563. py_type.tp_name = "megengine.core._imperative_rt.ops.Pooling";
  12564. py_type.tp_basicsize = sizeof(PyOp(Pooling));
  12565. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12566. py_type.tp_doc = "Pooling";
  12567. py_type.tp_base = &PyOpType(OpDef);
  12568. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12569. py_type.tp_new = py_new_generic<py_op>;
  12570. py_type.tp_init = py_op::py_init;
  12571. py_type.tp_methods = py_op::tp_methods;
  12572. py_type.tp_getset = py_op::py_getsetters;
  12573. mgb_assert(PyType_Ready(&py_type) >= 0);
  12574. _init_py_Pooling_Mode(py_type);
  12575. _init_py_Pooling_Format(py_type);
  12576. _init_py_Pooling_Strategy(py_type);
  12577. PyType_Modified(&py_type);
  12578. m.add_object("Pooling", reinterpret_cast<PyObject*>(&py_type));
  12579. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Pooling::typeinfo(), &py_type).second);
  12580. }
  12581. template<> struct EnumTrait<RNN::NonlineMode> {
  12582. static constexpr const char *name = "RNN.NonlineMode";
  12583. static constexpr std::underlying_type_t<RNN::NonlineMode> max = 3 - 1;
  12584. };
  12585. template<> PyTypeObject* EnumWrapper<RNN::NonlineMode>::type = nullptr;
  12586. template<> const char*
  12587. EnumWrapper<RNN::NonlineMode>::members[] = {"IDENTITY", "RELU", "TANH"};
  12588. template<> std::unordered_map<std::string, RNN::NonlineMode>
  12589. EnumWrapper<RNN::NonlineMode>::mem2value = {{normalize_enum("IDENTITY"), RNN::NonlineMode::IDENTITY}, {normalize_enum("RELU"), RNN::NonlineMode::RELU}, {normalize_enum("TANH"), RNN::NonlineMode::TANH}};
  12590. template<> PyObject* EnumWrapper<RNN::NonlineMode>::pyobj_insts[3] = {nullptr};
  12591. void _init_py_RNN_NonlineMode(PyTypeObject& py_type) {
  12592. auto& e_type = EnumWrapper<RNN::NonlineMode>::type;
  12593. static PyMethodDef tp_methods[] = {
  12594. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<RNN::NonlineMode>::py_dump, METH_NOARGS, NULL},
  12595. {NULL} /* Sentinel */
  12596. };
  12597. static PyType_Slot slots[] = {
  12598. {Py_tp_repr, (void*)EnumWrapper<RNN::NonlineMode>::py_repr},
  12599. {Py_tp_richcompare, (void*)EnumWrapper<RNN::NonlineMode>::tp_richcompare},
  12600. {Py_tp_methods, tp_methods},
  12601. {0, NULL}
  12602. };
  12603. static PyType_Spec spec = {
  12604. // name
  12605. "megengine.core._imperative_rt.ops.RNN.NonlineMode",
  12606. // basicsize
  12607. sizeof(EnumWrapper<RNN::NonlineMode>),
  12608. // itemsize
  12609. 0,
  12610. // flags
  12611. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  12612. // slots
  12613. slots
  12614. };
  12615. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  12616. mgb_assert(
  12617. e_type->tp_setattro(
  12618. reinterpret_cast<PyObject*>(e_type),
  12619. py::cast("__name__").release().ptr(),
  12620. py::cast("NonlineMode").release().ptr()) >= 0);
  12621. mgb_assert(
  12622. e_type->tp_setattro(
  12623. reinterpret_cast<PyObject*>(e_type),
  12624. py::cast("__module__").release().ptr(),
  12625. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  12626. mgb_assert(
  12627. e_type->tp_setattro(
  12628. reinterpret_cast<PyObject*>(e_type),
  12629. py::cast("__qualname__").release().ptr(),
  12630. py::cast("RNN.NonlineMode").release().ptr()) >= 0);
  12631. {
  12632. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12633. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::IDENTITY;
  12634. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "IDENTITY", inst) >= 0);
  12635. EnumWrapper<RNN::NonlineMode>::pyobj_insts[0] = inst;
  12636. }{
  12637. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12638. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::RELU;
  12639. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0);
  12640. EnumWrapper<RNN::NonlineMode>::pyobj_insts[1] = inst;
  12641. }{
  12642. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12643. reinterpret_cast<EnumWrapper<RNN::NonlineMode>*>(inst)->value = RNN::NonlineMode::TANH;
  12644. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0);
  12645. EnumWrapper<RNN::NonlineMode>::pyobj_insts[2] = inst;
  12646. }
  12647. Py_INCREF(e_type);
  12648. mgb_assert(PyDict_SetItemString(
  12649. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12650. }
  12651. void _init_py_RNN_FwdMode(PyTypeObject& py_type) {
  12652. auto& e_type = EnumWrapper<RNN::FwdMode>::type;
  12653. Py_INCREF(e_type);
  12654. mgb_assert(PyDict_SetItemString(
  12655. py_type.tp_dict, "FwdMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12656. }
  12657. PyOpDefBegin(RNN) // {
  12658. static PyGetSetDef py_getsetters[];
  12659. static PyMethodDef tp_methods[];
  12660. static PyObject* getstate(PyObject* self, PyObject*) {
  12661. auto& opdef = reinterpret_cast<PyOp(RNN)*>(self)->inst();
  12662. static_cast<void>(opdef);
  12663. std::unordered_map<std::string, py::object> state {
  12664. {"num_layers", serialization<decltype(opdef.num_layers)>::dump(opdef.num_layers)},
  12665. {"bidirectional", serialization<decltype(opdef.bidirectional)>::dump(opdef.bidirectional)},
  12666. {"bias", serialization<decltype(opdef.bias)>::dump(opdef.bias)},
  12667. {"hidden_size", serialization<decltype(opdef.hidden_size)>::dump(opdef.hidden_size)},
  12668. {"dropout", serialization<decltype(opdef.dropout)>::dump(opdef.dropout)},
  12669. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)},
  12670. {"fwd_mode", serialization<decltype(opdef.fwd_mode)>::dump(opdef.fwd_mode)}
  12671. };
  12672. return py::cast(state).release().ptr();
  12673. }
  12674. static PyObject* setstate(PyObject* self, PyObject* args) {
  12675. PyObject* dict = PyTuple_GetItem(args, 0);
  12676. if (!dict) return NULL;
  12677. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12678. auto& opdef = reinterpret_cast<PyOp(RNN)*>(self)->inst();
  12679. static_cast<void>(opdef);
  12680. {
  12681. auto&& iter = state.find("num_layers");
  12682. if (iter != state.end()) {
  12683. opdef.num_layers = serialization<decltype(opdef.num_layers)>::load(iter->second);
  12684. }
  12685. }
  12686. {
  12687. auto&& iter = state.find("bidirectional");
  12688. if (iter != state.end()) {
  12689. opdef.bidirectional = serialization<decltype(opdef.bidirectional)>::load(iter->second);
  12690. }
  12691. }
  12692. {
  12693. auto&& iter = state.find("bias");
  12694. if (iter != state.end()) {
  12695. opdef.bias = serialization<decltype(opdef.bias)>::load(iter->second);
  12696. }
  12697. }
  12698. {
  12699. auto&& iter = state.find("hidden_size");
  12700. if (iter != state.end()) {
  12701. opdef.hidden_size = serialization<decltype(opdef.hidden_size)>::load(iter->second);
  12702. }
  12703. }
  12704. {
  12705. auto&& iter = state.find("dropout");
  12706. if (iter != state.end()) {
  12707. opdef.dropout = serialization<decltype(opdef.dropout)>::load(iter->second);
  12708. }
  12709. }
  12710. {
  12711. auto&& iter = state.find("nonlineMode");
  12712. if (iter != state.end()) {
  12713. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  12714. }
  12715. }
  12716. {
  12717. auto&& iter = state.find("fwd_mode");
  12718. if (iter != state.end()) {
  12719. opdef.fwd_mode = serialization<decltype(opdef.fwd_mode)>::load(iter->second);
  12720. }
  12721. }
  12722. Py_RETURN_NONE;
  12723. }
  12724. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12725. // };
  12726. PyOpDefEnd(RNN)
  12727. int PyOp(RNN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12728. static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "dropout", "nonlineMode", "fwd_mode", "scope", NULL};
  12729. PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *dropout = NULL, *nonlineMode = NULL, *fwd_mode = NULL, *scope = NULL;
  12730. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast<char**>(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &dropout, &nonlineMode, &fwd_mode, &scope))
  12731. return -1;
  12732. if (num_layers) {
  12733. try {
  12734. // TODO: remove this guard which is used for pybind11 implicit conversion
  12735. py::detail::loader_life_support guard{};
  12736. reinterpret_cast<PyOp(RNN)*>(self)->inst().num_layers =
  12737. py::cast<decltype(RNN::num_layers)>(py::handle(num_layers));
  12738. } CATCH_ALL(-1)
  12739. }
  12740. if (bidirectional) {
  12741. try {
  12742. // TODO: remove this guard which is used for pybind11 implicit conversion
  12743. py::detail::loader_life_support guard{};
  12744. reinterpret_cast<PyOp(RNN)*>(self)->inst().bidirectional =
  12745. py::cast<decltype(RNN::bidirectional)>(py::handle(bidirectional));
  12746. } CATCH_ALL(-1)
  12747. }
  12748. if (bias) {
  12749. try {
  12750. // TODO: remove this guard which is used for pybind11 implicit conversion
  12751. py::detail::loader_life_support guard{};
  12752. reinterpret_cast<PyOp(RNN)*>(self)->inst().bias =
  12753. py::cast<decltype(RNN::bias)>(py::handle(bias));
  12754. } CATCH_ALL(-1)
  12755. }
  12756. if (hidden_size) {
  12757. try {
  12758. // TODO: remove this guard which is used for pybind11 implicit conversion
  12759. py::detail::loader_life_support guard{};
  12760. reinterpret_cast<PyOp(RNN)*>(self)->inst().hidden_size =
  12761. py::cast<decltype(RNN::hidden_size)>(py::handle(hidden_size));
  12762. } CATCH_ALL(-1)
  12763. }
  12764. if (dropout) {
  12765. try {
  12766. // TODO: remove this guard which is used for pybind11 implicit conversion
  12767. py::detail::loader_life_support guard{};
  12768. reinterpret_cast<PyOp(RNN)*>(self)->inst().dropout =
  12769. py::cast<decltype(RNN::dropout)>(py::handle(dropout));
  12770. } CATCH_ALL(-1)
  12771. }
  12772. if (nonlineMode) {
  12773. try {
  12774. // TODO: remove this guard which is used for pybind11 implicit conversion
  12775. py::detail::loader_life_support guard{};
  12776. reinterpret_cast<PyOp(RNN)*>(self)->inst().nonlineMode =
  12777. py::cast<decltype(RNN::nonlineMode)>(py::handle(nonlineMode));
  12778. } CATCH_ALL(-1)
  12779. }
  12780. if (fwd_mode) {
  12781. try {
  12782. // TODO: remove this guard which is used for pybind11 implicit conversion
  12783. py::detail::loader_life_support guard{};
  12784. reinterpret_cast<PyOp(RNN)*>(self)->inst().fwd_mode =
  12785. py::cast<decltype(RNN::fwd_mode)>(py::handle(fwd_mode));
  12786. } CATCH_ALL(-1)
  12787. }
  12788. if (scope) {
  12789. try {
  12790. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12791. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12792. } CATCH_ALL(-1)
  12793. }
  12794. return 0;
  12795. }
  12796. PyGetSetDef PyOp(RNN)::py_getsetters[] = {
  12797. {const_cast<char*>("num_layers"), py_get_generic(RNN, num_layers), py_set_generic(RNN, num_layers), const_cast<char*>("num_layers"), NULL},
  12798. {const_cast<char*>("bidirectional"), py_get_generic(RNN, bidirectional), py_set_generic(RNN, bidirectional), const_cast<char*>("bidirectional"), NULL},
  12799. {const_cast<char*>("bias"), py_get_generic(RNN, bias), py_set_generic(RNN, bias), const_cast<char*>("bias"), NULL},
  12800. {const_cast<char*>("hidden_size"), py_get_generic(RNN, hidden_size), py_set_generic(RNN, hidden_size), const_cast<char*>("hidden_size"), NULL},
  12801. {const_cast<char*>("dropout"), py_get_generic(RNN, dropout), py_set_generic(RNN, dropout), const_cast<char*>("dropout"), NULL},
  12802. {const_cast<char*>("nonlineMode"), py_get_generic(RNN, nonlineMode), py_set_generic(RNN, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  12803. {const_cast<char*>("fwd_mode"), py_get_generic(RNN, fwd_mode), py_set_generic(RNN, fwd_mode), const_cast<char*>("fwd_mode"), NULL},
  12804. {NULL} /* Sentinel */
  12805. };
  12806. PyMethodDef PyOp(RNN)::tp_methods[] = {
  12807. {const_cast<char*>("__getstate__"), PyOp(RNN)::getstate, METH_NOARGS, "RNN getstate"},
  12808. {const_cast<char*>("__setstate__"), PyOp(RNN)::setstate, METH_VARARGS, "RNN setstate"},
  12809. {NULL} /* Sentinel */
  12810. };
  12811. void _init_py_RNN(py::module m) {
  12812. using py_op = PyOp(RNN);
  12813. auto& py_type = PyOpType(RNN);
  12814. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12815. py_type.tp_name = "megengine.core._imperative_rt.ops.RNN";
  12816. py_type.tp_basicsize = sizeof(PyOp(RNN));
  12817. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12818. py_type.tp_doc = "RNN";
  12819. py_type.tp_base = &PyOpType(OpDef);
  12820. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12821. py_type.tp_new = py_new_generic<py_op>;
  12822. py_type.tp_init = py_op::py_init;
  12823. py_type.tp_methods = py_op::tp_methods;
  12824. py_type.tp_getset = py_op::py_getsetters;
  12825. mgb_assert(PyType_Ready(&py_type) >= 0);
  12826. _init_py_RNN_NonlineMode(py_type);
  12827. _init_py_RNN_FwdMode(py_type);
  12828. PyType_Modified(&py_type);
  12829. m.add_object("RNN", reinterpret_cast<PyObject*>(&py_type));
  12830. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNN::typeinfo(), &py_type).second);
  12831. }
  12832. void _init_py_RNNCell_NonlineMode(PyTypeObject& py_type) {
  12833. auto& e_type = EnumWrapper<RNNCell::NonlineMode>::type;
  12834. Py_INCREF(e_type);
  12835. mgb_assert(PyDict_SetItemString(
  12836. py_type.tp_dict, "NonlineMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12837. }
  12838. PyOpDefBegin(RNNCell) // {
  12839. static PyGetSetDef py_getsetters[];
  12840. static PyMethodDef tp_methods[];
  12841. static PyObject* getstate(PyObject* self, PyObject*) {
  12842. auto& opdef = reinterpret_cast<PyOp(RNNCell)*>(self)->inst();
  12843. static_cast<void>(opdef);
  12844. std::unordered_map<std::string, py::object> state {
  12845. {"nonlineMode", serialization<decltype(opdef.nonlineMode)>::dump(opdef.nonlineMode)}
  12846. };
  12847. return py::cast(state).release().ptr();
  12848. }
  12849. static PyObject* setstate(PyObject* self, PyObject* args) {
  12850. PyObject* dict = PyTuple_GetItem(args, 0);
  12851. if (!dict) return NULL;
  12852. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  12853. auto& opdef = reinterpret_cast<PyOp(RNNCell)*>(self)->inst();
  12854. static_cast<void>(opdef);
  12855. {
  12856. auto&& iter = state.find("nonlineMode");
  12857. if (iter != state.end()) {
  12858. opdef.nonlineMode = serialization<decltype(opdef.nonlineMode)>::load(iter->second);
  12859. }
  12860. }
  12861. Py_RETURN_NONE;
  12862. }
  12863. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  12864. // };
  12865. PyOpDefEnd(RNNCell)
  12866. int PyOp(RNNCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  12867. static const char* kwlist[] = {"nonlineMode", "scope", NULL};
  12868. PyObject *nonlineMode = NULL, *scope = NULL;
  12869. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &nonlineMode, &scope))
  12870. return -1;
  12871. if (nonlineMode) {
  12872. try {
  12873. // TODO: remove this guard which is used for pybind11 implicit conversion
  12874. py::detail::loader_life_support guard{};
  12875. reinterpret_cast<PyOp(RNNCell)*>(self)->inst().nonlineMode =
  12876. py::cast<decltype(RNNCell::nonlineMode)>(py::handle(nonlineMode));
  12877. } CATCH_ALL(-1)
  12878. }
  12879. if (scope) {
  12880. try {
  12881. reinterpret_cast<PyOp(OpDef)*>(self)->op
  12882. ->set_scope(py::cast<std::string>(py::handle(scope)));
  12883. } CATCH_ALL(-1)
  12884. }
  12885. return 0;
  12886. }
  12887. PyGetSetDef PyOp(RNNCell)::py_getsetters[] = {
  12888. {const_cast<char*>("nonlineMode"), py_get_generic(RNNCell, nonlineMode), py_set_generic(RNNCell, nonlineMode), const_cast<char*>("nonlineMode"), NULL},
  12889. {NULL} /* Sentinel */
  12890. };
  12891. PyMethodDef PyOp(RNNCell)::tp_methods[] = {
  12892. {const_cast<char*>("__getstate__"), PyOp(RNNCell)::getstate, METH_NOARGS, "RNNCell getstate"},
  12893. {const_cast<char*>("__setstate__"), PyOp(RNNCell)::setstate, METH_VARARGS, "RNNCell setstate"},
  12894. {NULL} /* Sentinel */
  12895. };
  12896. void _init_py_RNNCell(py::module m) {
  12897. using py_op = PyOp(RNNCell);
  12898. auto& py_type = PyOpType(RNNCell);
  12899. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  12900. py_type.tp_name = "megengine.core._imperative_rt.ops.RNNCell";
  12901. py_type.tp_basicsize = sizeof(PyOp(RNNCell));
  12902. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  12903. py_type.tp_doc = "RNNCell";
  12904. py_type.tp_base = &PyOpType(OpDef);
  12905. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  12906. py_type.tp_new = py_new_generic<py_op>;
  12907. py_type.tp_init = py_op::py_init;
  12908. py_type.tp_methods = py_op::tp_methods;
  12909. py_type.tp_getset = py_op::py_getsetters;
  12910. mgb_assert(PyType_Ready(&py_type) >= 0);
  12911. _init_py_RNNCell_NonlineMode(py_type);
  12912. PyType_Modified(&py_type);
  12913. m.add_object("RNNCell", reinterpret_cast<PyObject*>(&py_type));
  12914. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNNCell::typeinfo(), &py_type).second);
  12915. }
  12916. template<> struct EnumTrait<ROIAlign::Mode> {
  12917. static constexpr const char *name = "ROIAlign.Mode";
  12918. static constexpr std::underlying_type_t<ROIAlign::Mode> max = 2 - 1;
  12919. };
  12920. template<> PyTypeObject* EnumWrapper<ROIAlign::Mode>::type = nullptr;
  12921. template<> const char*
  12922. EnumWrapper<ROIAlign::Mode>::members[] = {"MAX", "AVERAGE"};
  12923. template<> std::unordered_map<std::string, ROIAlign::Mode>
  12924. EnumWrapper<ROIAlign::Mode>::mem2value = {{normalize_enum("MAX"), ROIAlign::Mode::MAX}, {normalize_enum("AVERAGE"), ROIAlign::Mode::AVERAGE}};
  12925. template<> PyObject* EnumWrapper<ROIAlign::Mode>::pyobj_insts[2] = {nullptr};
  12926. void _init_py_ROIAlign_Mode(PyTypeObject& py_type) {
  12927. auto& e_type = EnumWrapper<ROIAlign::Mode>::type;
  12928. static PyMethodDef tp_methods[] = {
  12929. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ROIAlign::Mode>::py_dump, METH_NOARGS, NULL},
  12930. {NULL} /* Sentinel */
  12931. };
  12932. static PyType_Slot slots[] = {
  12933. {Py_tp_repr, (void*)EnumWrapper<ROIAlign::Mode>::py_repr},
  12934. {Py_tp_richcompare, (void*)EnumWrapper<ROIAlign::Mode>::tp_richcompare},
  12935. {Py_tp_methods, tp_methods},
  12936. {0, NULL}
  12937. };
  12938. static PyType_Spec spec = {
  12939. // name
  12940. "megengine.core._imperative_rt.ops.ROIAlign.Mode",
  12941. // basicsize
  12942. sizeof(EnumWrapper<ROIAlign::Mode>),
  12943. // itemsize
  12944. 0,
  12945. // flags
  12946. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  12947. // slots
  12948. slots
  12949. };
  12950. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  12951. mgb_assert(
  12952. e_type->tp_setattro(
  12953. reinterpret_cast<PyObject*>(e_type),
  12954. py::cast("__name__").release().ptr(),
  12955. py::cast("Mode").release().ptr()) >= 0);
  12956. mgb_assert(
  12957. e_type->tp_setattro(
  12958. reinterpret_cast<PyObject*>(e_type),
  12959. py::cast("__module__").release().ptr(),
  12960. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  12961. mgb_assert(
  12962. e_type->tp_setattro(
  12963. reinterpret_cast<PyObject*>(e_type),
  12964. py::cast("__qualname__").release().ptr(),
  12965. py::cast("ROIAlign.Mode").release().ptr()) >= 0);
  12966. {
  12967. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12968. reinterpret_cast<EnumWrapper<ROIAlign::Mode>*>(inst)->value = ROIAlign::Mode::MAX;
  12969. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  12970. EnumWrapper<ROIAlign::Mode>::pyobj_insts[0] = inst;
  12971. }{
  12972. PyObject* inst = e_type->tp_alloc(e_type, 0);
  12973. reinterpret_cast<EnumWrapper<ROIAlign::Mode>*>(inst)->value = ROIAlign::Mode::AVERAGE;
  12974. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  12975. EnumWrapper<ROIAlign::Mode>::pyobj_insts[1] = inst;
  12976. }
  12977. Py_INCREF(e_type);
  12978. mgb_assert(PyDict_SetItemString(
  12979. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12980. }
  12981. void _init_py_ROIAlign_Format(PyTypeObject& py_type) {
  12982. auto& e_type = EnumWrapper<ROIAlign::Format>::type;
  12983. Py_INCREF(e_type);
  12984. mgb_assert(PyDict_SetItemString(
  12985. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  12986. }
  12987. PyOpDefBegin(ROIAlign) // {
  12988. static PyGetSetDef py_getsetters[];
  12989. static PyMethodDef tp_methods[];
  12990. static PyObject* getstate(PyObject* self, PyObject*) {
  12991. auto& opdef = reinterpret_cast<PyOp(ROIAlign)*>(self)->inst();
  12992. static_cast<void>(opdef);
  12993. std::unordered_map<std::string, py::object> state {
  12994. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  12995. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  12996. {"spatial_scale", serialization<decltype(opdef.spatial_scale)>::dump(opdef.spatial_scale)},
  12997. {"offset", serialization<decltype(opdef.offset)>::dump(opdef.offset)},
  12998. {"pooled_height", serialization<decltype(opdef.pooled_height)>::dump(opdef.pooled_height)},
  12999. {"pooled_width", serialization<decltype(opdef.pooled_width)>::dump(opdef.pooled_width)},
  13000. {"sample_height", serialization<decltype(opdef.sample_height)>::dump(opdef.sample_height)},
  13001. {"sample_width", serialization<decltype(opdef.sample_width)>::dump(opdef.sample_width)}
  13002. };
  13003. return py::cast(state).release().ptr();
  13004. }
  13005. static PyObject* setstate(PyObject* self, PyObject* args) {
  13006. PyObject* dict = PyTuple_GetItem(args, 0);
  13007. if (!dict) return NULL;
  13008. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13009. auto& opdef = reinterpret_cast<PyOp(ROIAlign)*>(self)->inst();
  13010. static_cast<void>(opdef);
  13011. {
  13012. auto&& iter = state.find("mode");
  13013. if (iter != state.end()) {
  13014. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13015. }
  13016. }
  13017. {
  13018. auto&& iter = state.find("format");
  13019. if (iter != state.end()) {
  13020. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  13021. }
  13022. }
  13023. {
  13024. auto&& iter = state.find("spatial_scale");
  13025. if (iter != state.end()) {
  13026. opdef.spatial_scale = serialization<decltype(opdef.spatial_scale)>::load(iter->second);
  13027. }
  13028. }
  13029. {
  13030. auto&& iter = state.find("offset");
  13031. if (iter != state.end()) {
  13032. opdef.offset = serialization<decltype(opdef.offset)>::load(iter->second);
  13033. }
  13034. }
  13035. {
  13036. auto&& iter = state.find("pooled_height");
  13037. if (iter != state.end()) {
  13038. opdef.pooled_height = serialization<decltype(opdef.pooled_height)>::load(iter->second);
  13039. }
  13040. }
  13041. {
  13042. auto&& iter = state.find("pooled_width");
  13043. if (iter != state.end()) {
  13044. opdef.pooled_width = serialization<decltype(opdef.pooled_width)>::load(iter->second);
  13045. }
  13046. }
  13047. {
  13048. auto&& iter = state.find("sample_height");
  13049. if (iter != state.end()) {
  13050. opdef.sample_height = serialization<decltype(opdef.sample_height)>::load(iter->second);
  13051. }
  13052. }
  13053. {
  13054. auto&& iter = state.find("sample_width");
  13055. if (iter != state.end()) {
  13056. opdef.sample_width = serialization<decltype(opdef.sample_width)>::load(iter->second);
  13057. }
  13058. }
  13059. Py_RETURN_NONE;
  13060. }
  13061. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13062. // };
  13063. PyOpDefEnd(ROIAlign)
  13064. int PyOp(ROIAlign)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13065. static const char* kwlist[] = {"mode", "format", "spatial_scale", "offset", "pooled_height", "pooled_width", "sample_height", "sample_width", "scope", NULL};
  13066. PyObject *mode = NULL, *format = NULL, *spatial_scale = NULL, *offset = NULL, *pooled_height = NULL, *pooled_width = NULL, *sample_height = NULL, *sample_width = NULL, *scope = NULL;
  13067. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &mode, &format, &spatial_scale, &offset, &pooled_height, &pooled_width, &sample_height, &sample_width, &scope))
  13068. return -1;
  13069. if (mode) {
  13070. try {
  13071. // TODO: remove this guard which is used for pybind11 implicit conversion
  13072. py::detail::loader_life_support guard{};
  13073. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().mode =
  13074. py::cast<decltype(ROIAlign::mode)>(py::handle(mode));
  13075. } CATCH_ALL(-1)
  13076. }
  13077. if (format) {
  13078. try {
  13079. // TODO: remove this guard which is used for pybind11 implicit conversion
  13080. py::detail::loader_life_support guard{};
  13081. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().format =
  13082. py::cast<decltype(ROIAlign::format)>(py::handle(format));
  13083. } CATCH_ALL(-1)
  13084. }
  13085. if (spatial_scale) {
  13086. try {
  13087. // TODO: remove this guard which is used for pybind11 implicit conversion
  13088. py::detail::loader_life_support guard{};
  13089. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().spatial_scale =
  13090. py::cast<decltype(ROIAlign::spatial_scale)>(py::handle(spatial_scale));
  13091. } CATCH_ALL(-1)
  13092. }
  13093. if (offset) {
  13094. try {
  13095. // TODO: remove this guard which is used for pybind11 implicit conversion
  13096. py::detail::loader_life_support guard{};
  13097. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().offset =
  13098. py::cast<decltype(ROIAlign::offset)>(py::handle(offset));
  13099. } CATCH_ALL(-1)
  13100. }
  13101. if (pooled_height) {
  13102. try {
  13103. // TODO: remove this guard which is used for pybind11 implicit conversion
  13104. py::detail::loader_life_support guard{};
  13105. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().pooled_height =
  13106. py::cast<decltype(ROIAlign::pooled_height)>(py::handle(pooled_height));
  13107. } CATCH_ALL(-1)
  13108. }
  13109. if (pooled_width) {
  13110. try {
  13111. // TODO: remove this guard which is used for pybind11 implicit conversion
  13112. py::detail::loader_life_support guard{};
  13113. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().pooled_width =
  13114. py::cast<decltype(ROIAlign::pooled_width)>(py::handle(pooled_width));
  13115. } CATCH_ALL(-1)
  13116. }
  13117. if (sample_height) {
  13118. try {
  13119. // TODO: remove this guard which is used for pybind11 implicit conversion
  13120. py::detail::loader_life_support guard{};
  13121. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().sample_height =
  13122. py::cast<decltype(ROIAlign::sample_height)>(py::handle(sample_height));
  13123. } CATCH_ALL(-1)
  13124. }
  13125. if (sample_width) {
  13126. try {
  13127. // TODO: remove this guard which is used for pybind11 implicit conversion
  13128. py::detail::loader_life_support guard{};
  13129. reinterpret_cast<PyOp(ROIAlign)*>(self)->inst().sample_width =
  13130. py::cast<decltype(ROIAlign::sample_width)>(py::handle(sample_width));
  13131. } CATCH_ALL(-1)
  13132. }
  13133. if (scope) {
  13134. try {
  13135. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13136. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13137. } CATCH_ALL(-1)
  13138. }
  13139. return 0;
  13140. }
  13141. PyGetSetDef PyOp(ROIAlign)::py_getsetters[] = {
  13142. {const_cast<char*>("mode"), py_get_generic(ROIAlign, mode), py_set_generic(ROIAlign, mode), const_cast<char*>("mode"), NULL},
  13143. {const_cast<char*>("format"), py_get_generic(ROIAlign, format), py_set_generic(ROIAlign, format), const_cast<char*>("format"), NULL},
  13144. {const_cast<char*>("spatial_scale"), py_get_generic(ROIAlign, spatial_scale), py_set_generic(ROIAlign, spatial_scale), const_cast<char*>("spatial_scale"), NULL},
  13145. {const_cast<char*>("offset"), py_get_generic(ROIAlign, offset), py_set_generic(ROIAlign, offset), const_cast<char*>("offset"), NULL},
  13146. {const_cast<char*>("pooled_height"), py_get_generic(ROIAlign, pooled_height), py_set_generic(ROIAlign, pooled_height), const_cast<char*>("pooled_height"), NULL},
  13147. {const_cast<char*>("pooled_width"), py_get_generic(ROIAlign, pooled_width), py_set_generic(ROIAlign, pooled_width), const_cast<char*>("pooled_width"), NULL},
  13148. {const_cast<char*>("sample_height"), py_get_generic(ROIAlign, sample_height), py_set_generic(ROIAlign, sample_height), const_cast<char*>("sample_height"), NULL},
  13149. {const_cast<char*>("sample_width"), py_get_generic(ROIAlign, sample_width), py_set_generic(ROIAlign, sample_width), const_cast<char*>("sample_width"), NULL},
  13150. {NULL} /* Sentinel */
  13151. };
  13152. PyMethodDef PyOp(ROIAlign)::tp_methods[] = {
  13153. {const_cast<char*>("__getstate__"), PyOp(ROIAlign)::getstate, METH_NOARGS, "ROIAlign getstate"},
  13154. {const_cast<char*>("__setstate__"), PyOp(ROIAlign)::setstate, METH_VARARGS, "ROIAlign setstate"},
  13155. {NULL} /* Sentinel */
  13156. };
  13157. void _init_py_ROIAlign(py::module m) {
  13158. using py_op = PyOp(ROIAlign);
  13159. auto& py_type = PyOpType(ROIAlign);
  13160. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13161. py_type.tp_name = "megengine.core._imperative_rt.ops.ROIAlign";
  13162. py_type.tp_basicsize = sizeof(PyOp(ROIAlign));
  13163. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13164. py_type.tp_doc = "ROIAlign";
  13165. py_type.tp_base = &PyOpType(OpDef);
  13166. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13167. py_type.tp_new = py_new_generic<py_op>;
  13168. py_type.tp_init = py_op::py_init;
  13169. py_type.tp_methods = py_op::tp_methods;
  13170. py_type.tp_getset = py_op::py_getsetters;
  13171. mgb_assert(PyType_Ready(&py_type) >= 0);
  13172. _init_py_ROIAlign_Mode(py_type);
  13173. _init_py_ROIAlign_Format(py_type);
  13174. PyType_Modified(&py_type);
  13175. m.add_object("ROIAlign", reinterpret_cast<PyObject*>(&py_type));
  13176. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIAlign::typeinfo(), &py_type).second);
  13177. }
  13178. template<> struct EnumTrait<ROIPooling::Mode> {
  13179. static constexpr const char *name = "ROIPooling.Mode";
  13180. static constexpr std::underlying_type_t<ROIPooling::Mode> max = 2 - 1;
  13181. };
  13182. template<> PyTypeObject* EnumWrapper<ROIPooling::Mode>::type = nullptr;
  13183. template<> const char*
  13184. EnumWrapper<ROIPooling::Mode>::members[] = {"MAX", "AVERAGE"};
  13185. template<> std::unordered_map<std::string, ROIPooling::Mode>
  13186. EnumWrapper<ROIPooling::Mode>::mem2value = {{normalize_enum("MAX"), ROIPooling::Mode::MAX}, {normalize_enum("AVERAGE"), ROIPooling::Mode::AVERAGE}};
  13187. template<> PyObject* EnumWrapper<ROIPooling::Mode>::pyobj_insts[2] = {nullptr};
  13188. void _init_py_ROIPooling_Mode(PyTypeObject& py_type) {
  13189. auto& e_type = EnumWrapper<ROIPooling::Mode>::type;
  13190. static PyMethodDef tp_methods[] = {
  13191. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<ROIPooling::Mode>::py_dump, METH_NOARGS, NULL},
  13192. {NULL} /* Sentinel */
  13193. };
  13194. static PyType_Slot slots[] = {
  13195. {Py_tp_repr, (void*)EnumWrapper<ROIPooling::Mode>::py_repr},
  13196. {Py_tp_richcompare, (void*)EnumWrapper<ROIPooling::Mode>::tp_richcompare},
  13197. {Py_tp_methods, tp_methods},
  13198. {0, NULL}
  13199. };
  13200. static PyType_Spec spec = {
  13201. // name
  13202. "megengine.core._imperative_rt.ops.ROIPooling.Mode",
  13203. // basicsize
  13204. sizeof(EnumWrapper<ROIPooling::Mode>),
  13205. // itemsize
  13206. 0,
  13207. // flags
  13208. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13209. // slots
  13210. slots
  13211. };
  13212. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13213. mgb_assert(
  13214. e_type->tp_setattro(
  13215. reinterpret_cast<PyObject*>(e_type),
  13216. py::cast("__name__").release().ptr(),
  13217. py::cast("Mode").release().ptr()) >= 0);
  13218. mgb_assert(
  13219. e_type->tp_setattro(
  13220. reinterpret_cast<PyObject*>(e_type),
  13221. py::cast("__module__").release().ptr(),
  13222. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13223. mgb_assert(
  13224. e_type->tp_setattro(
  13225. reinterpret_cast<PyObject*>(e_type),
  13226. py::cast("__qualname__").release().ptr(),
  13227. py::cast("ROIPooling.Mode").release().ptr()) >= 0);
  13228. {
  13229. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13230. reinterpret_cast<EnumWrapper<ROIPooling::Mode>*>(inst)->value = ROIPooling::Mode::MAX;
  13231. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  13232. EnumWrapper<ROIPooling::Mode>::pyobj_insts[0] = inst;
  13233. }{
  13234. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13235. reinterpret_cast<EnumWrapper<ROIPooling::Mode>*>(inst)->value = ROIPooling::Mode::AVERAGE;
  13236. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0);
  13237. EnumWrapper<ROIPooling::Mode>::pyobj_insts[1] = inst;
  13238. }
  13239. Py_INCREF(e_type);
  13240. mgb_assert(PyDict_SetItemString(
  13241. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13242. }
  13243. PyOpDefBegin(ROIPooling) // {
  13244. static PyGetSetDef py_getsetters[];
  13245. static PyMethodDef tp_methods[];
  13246. static PyObject* getstate(PyObject* self, PyObject*) {
  13247. auto& opdef = reinterpret_cast<PyOp(ROIPooling)*>(self)->inst();
  13248. static_cast<void>(opdef);
  13249. std::unordered_map<std::string, py::object> state {
  13250. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13251. {"scale", serialization<decltype(opdef.scale)>::dump(opdef.scale)}
  13252. };
  13253. return py::cast(state).release().ptr();
  13254. }
  13255. static PyObject* setstate(PyObject* self, PyObject* args) {
  13256. PyObject* dict = PyTuple_GetItem(args, 0);
  13257. if (!dict) return NULL;
  13258. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13259. auto& opdef = reinterpret_cast<PyOp(ROIPooling)*>(self)->inst();
  13260. static_cast<void>(opdef);
  13261. {
  13262. auto&& iter = state.find("mode");
  13263. if (iter != state.end()) {
  13264. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13265. }
  13266. }
  13267. {
  13268. auto&& iter = state.find("scale");
  13269. if (iter != state.end()) {
  13270. opdef.scale = serialization<decltype(opdef.scale)>::load(iter->second);
  13271. }
  13272. }
  13273. Py_RETURN_NONE;
  13274. }
  13275. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13276. // };
  13277. PyOpDefEnd(ROIPooling)
  13278. int PyOp(ROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13279. static const char* kwlist[] = {"mode", "scale", "scope", NULL};
  13280. PyObject *mode = NULL, *scale = NULL, *scope = NULL;
  13281. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &mode, &scale, &scope))
  13282. return -1;
  13283. if (mode) {
  13284. try {
  13285. // TODO: remove this guard which is used for pybind11 implicit conversion
  13286. py::detail::loader_life_support guard{};
  13287. reinterpret_cast<PyOp(ROIPooling)*>(self)->inst().mode =
  13288. py::cast<decltype(ROIPooling::mode)>(py::handle(mode));
  13289. } CATCH_ALL(-1)
  13290. }
  13291. if (scale) {
  13292. try {
  13293. // TODO: remove this guard which is used for pybind11 implicit conversion
  13294. py::detail::loader_life_support guard{};
  13295. reinterpret_cast<PyOp(ROIPooling)*>(self)->inst().scale =
  13296. py::cast<decltype(ROIPooling::scale)>(py::handle(scale));
  13297. } CATCH_ALL(-1)
  13298. }
  13299. if (scope) {
  13300. try {
  13301. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13302. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13303. } CATCH_ALL(-1)
  13304. }
  13305. return 0;
  13306. }
  13307. PyGetSetDef PyOp(ROIPooling)::py_getsetters[] = {
  13308. {const_cast<char*>("mode"), py_get_generic(ROIPooling, mode), py_set_generic(ROIPooling, mode), const_cast<char*>("mode"), NULL},
  13309. {const_cast<char*>("scale"), py_get_generic(ROIPooling, scale), py_set_generic(ROIPooling, scale), const_cast<char*>("scale"), NULL},
  13310. {NULL} /* Sentinel */
  13311. };
  13312. PyMethodDef PyOp(ROIPooling)::tp_methods[] = {
  13313. {const_cast<char*>("__getstate__"), PyOp(ROIPooling)::getstate, METH_NOARGS, "ROIPooling getstate"},
  13314. {const_cast<char*>("__setstate__"), PyOp(ROIPooling)::setstate, METH_VARARGS, "ROIPooling setstate"},
  13315. {NULL} /* Sentinel */
  13316. };
  13317. void _init_py_ROIPooling(py::module m) {
  13318. using py_op = PyOp(ROIPooling);
  13319. auto& py_type = PyOpType(ROIPooling);
  13320. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13321. py_type.tp_name = "megengine.core._imperative_rt.ops.ROIPooling";
  13322. py_type.tp_basicsize = sizeof(PyOp(ROIPooling));
  13323. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13324. py_type.tp_doc = "ROIPooling";
  13325. py_type.tp_base = &PyOpType(OpDef);
  13326. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13327. py_type.tp_new = py_new_generic<py_op>;
  13328. py_type.tp_init = py_op::py_init;
  13329. py_type.tp_methods = py_op::tp_methods;
  13330. py_type.tp_getset = py_op::py_getsetters;
  13331. mgb_assert(PyType_Ready(&py_type) >= 0);
  13332. _init_py_ROIPooling_Mode(py_type);
  13333. PyType_Modified(&py_type);
  13334. m.add_object("ROIPooling", reinterpret_cast<PyObject*>(&py_type));
  13335. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIPooling::typeinfo(), &py_type).second);
  13336. }
  13337. template<> struct EnumTrait<Reduce::Mode> {
  13338. static constexpr const char *name = "Reduce.Mode";
  13339. static constexpr std::underlying_type_t<Reduce::Mode> max = 6 - 1;
  13340. };
  13341. template<> PyTypeObject* EnumWrapper<Reduce::Mode>::type = nullptr;
  13342. template<> const char*
  13343. EnumWrapper<Reduce::Mode>::members[] = {"SUM", "SUM_SQR", "PRODUCT", "MIN", "MAX", "MEAN"};
  13344. template<> std::unordered_map<std::string, Reduce::Mode>
  13345. 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}};
  13346. template<> PyObject* EnumWrapper<Reduce::Mode>::pyobj_insts[6] = {nullptr};
  13347. void _init_py_Reduce_Mode(PyTypeObject& py_type) {
  13348. auto& e_type = EnumWrapper<Reduce::Mode>::type;
  13349. static PyMethodDef tp_methods[] = {
  13350. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Reduce::Mode>::py_dump, METH_NOARGS, NULL},
  13351. {NULL} /* Sentinel */
  13352. };
  13353. static PyType_Slot slots[] = {
  13354. {Py_tp_repr, (void*)EnumWrapper<Reduce::Mode>::py_repr},
  13355. {Py_tp_richcompare, (void*)EnumWrapper<Reduce::Mode>::tp_richcompare},
  13356. {Py_tp_methods, tp_methods},
  13357. {0, NULL}
  13358. };
  13359. static PyType_Spec spec = {
  13360. // name
  13361. "megengine.core._imperative_rt.ops.Reduce.Mode",
  13362. // basicsize
  13363. sizeof(EnumWrapper<Reduce::Mode>),
  13364. // itemsize
  13365. 0,
  13366. // flags
  13367. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13368. // slots
  13369. slots
  13370. };
  13371. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13372. mgb_assert(
  13373. e_type->tp_setattro(
  13374. reinterpret_cast<PyObject*>(e_type),
  13375. py::cast("__name__").release().ptr(),
  13376. py::cast("Mode").release().ptr()) >= 0);
  13377. mgb_assert(
  13378. e_type->tp_setattro(
  13379. reinterpret_cast<PyObject*>(e_type),
  13380. py::cast("__module__").release().ptr(),
  13381. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13382. mgb_assert(
  13383. e_type->tp_setattro(
  13384. reinterpret_cast<PyObject*>(e_type),
  13385. py::cast("__qualname__").release().ptr(),
  13386. py::cast("Reduce.Mode").release().ptr()) >= 0);
  13387. {
  13388. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13389. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::SUM;
  13390. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM", inst) >= 0);
  13391. EnumWrapper<Reduce::Mode>::pyobj_insts[0] = inst;
  13392. }{
  13393. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13394. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::SUM_SQR;
  13395. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM_SQR", inst) >= 0);
  13396. EnumWrapper<Reduce::Mode>::pyobj_insts[1] = inst;
  13397. }{
  13398. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13399. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::PRODUCT;
  13400. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PRODUCT", inst) >= 0);
  13401. EnumWrapper<Reduce::Mode>::pyobj_insts[2] = inst;
  13402. }{
  13403. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13404. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MIN;
  13405. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0);
  13406. EnumWrapper<Reduce::Mode>::pyobj_insts[3] = inst;
  13407. }{
  13408. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13409. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MAX;
  13410. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0);
  13411. EnumWrapper<Reduce::Mode>::pyobj_insts[4] = inst;
  13412. }{
  13413. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13414. reinterpret_cast<EnumWrapper<Reduce::Mode>*>(inst)->value = Reduce::Mode::MEAN;
  13415. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MEAN", inst) >= 0);
  13416. EnumWrapper<Reduce::Mode>::pyobj_insts[5] = inst;
  13417. }
  13418. Py_INCREF(e_type);
  13419. mgb_assert(PyDict_SetItemString(
  13420. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13421. }
  13422. template<> struct EnumTrait<Reduce::DataType> {
  13423. static constexpr const char *name = "Reduce.DataType";
  13424. static constexpr std::underlying_type_t<Reduce::DataType> max = 6 - 1;
  13425. };
  13426. template<> PyTypeObject* EnumWrapper<Reduce::DataType>::type = nullptr;
  13427. template<> const char*
  13428. EnumWrapper<Reduce::DataType>::members[] = {"DEFAULT", "FLOAT_IO16xC32", "FLOAT_O32xC32", "FLOAT_O16xC32", "QUINT_I8xO32", "QINT_I8xO32"};
  13429. template<> std::unordered_map<std::string, Reduce::DataType>
  13430. 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}};
  13431. template<> PyObject* EnumWrapper<Reduce::DataType>::pyobj_insts[6] = {nullptr};
  13432. void _init_py_Reduce_DataType(PyTypeObject& py_type) {
  13433. auto& e_type = EnumWrapper<Reduce::DataType>::type;
  13434. static PyMethodDef tp_methods[] = {
  13435. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Reduce::DataType>::py_dump, METH_NOARGS, NULL},
  13436. {NULL} /* Sentinel */
  13437. };
  13438. static PyType_Slot slots[] = {
  13439. {Py_tp_repr, (void*)EnumWrapper<Reduce::DataType>::py_repr},
  13440. {Py_tp_richcompare, (void*)EnumWrapper<Reduce::DataType>::tp_richcompare},
  13441. {Py_tp_methods, tp_methods},
  13442. {0, NULL}
  13443. };
  13444. static PyType_Spec spec = {
  13445. // name
  13446. "megengine.core._imperative_rt.ops.Reduce.DataType",
  13447. // basicsize
  13448. sizeof(EnumWrapper<Reduce::DataType>),
  13449. // itemsize
  13450. 0,
  13451. // flags
  13452. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  13453. // slots
  13454. slots
  13455. };
  13456. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  13457. mgb_assert(
  13458. e_type->tp_setattro(
  13459. reinterpret_cast<PyObject*>(e_type),
  13460. py::cast("__name__").release().ptr(),
  13461. py::cast("DataType").release().ptr()) >= 0);
  13462. mgb_assert(
  13463. e_type->tp_setattro(
  13464. reinterpret_cast<PyObject*>(e_type),
  13465. py::cast("__module__").release().ptr(),
  13466. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  13467. mgb_assert(
  13468. e_type->tp_setattro(
  13469. reinterpret_cast<PyObject*>(e_type),
  13470. py::cast("__qualname__").release().ptr(),
  13471. py::cast("Reduce.DataType").release().ptr()) >= 0);
  13472. {
  13473. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13474. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::DEFAULT;
  13475. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0);
  13476. EnumWrapper<Reduce::DataType>::pyobj_insts[0] = inst;
  13477. }{
  13478. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13479. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_IO16xC32;
  13480. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_IO16xC32", inst) >= 0);
  13481. EnumWrapper<Reduce::DataType>::pyobj_insts[1] = inst;
  13482. }{
  13483. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13484. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_O32xC32;
  13485. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O32xC32", inst) >= 0);
  13486. EnumWrapper<Reduce::DataType>::pyobj_insts[2] = inst;
  13487. }{
  13488. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13489. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::FLOAT_O16xC32;
  13490. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O16xC32", inst) >= 0);
  13491. EnumWrapper<Reduce::DataType>::pyobj_insts[3] = inst;
  13492. }{
  13493. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13494. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::QUINT_I8xO32;
  13495. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QUINT_I8xO32", inst) >= 0);
  13496. EnumWrapper<Reduce::DataType>::pyobj_insts[4] = inst;
  13497. }{
  13498. PyObject* inst = e_type->tp_alloc(e_type, 0);
  13499. reinterpret_cast<EnumWrapper<Reduce::DataType>*>(inst)->value = Reduce::DataType::QINT_I8xO32;
  13500. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QINT_I8xO32", inst) >= 0);
  13501. EnumWrapper<Reduce::DataType>::pyobj_insts[5] = inst;
  13502. }
  13503. Py_INCREF(e_type);
  13504. mgb_assert(PyDict_SetItemString(
  13505. py_type.tp_dict, "DataType", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13506. }
  13507. PyOpDefBegin(Reduce) // {
  13508. static PyGetSetDef py_getsetters[];
  13509. static PyMethodDef tp_methods[];
  13510. static PyObject* getstate(PyObject* self, PyObject*) {
  13511. auto& opdef = reinterpret_cast<PyOp(Reduce)*>(self)->inst();
  13512. static_cast<void>(opdef);
  13513. std::unordered_map<std::string, py::object> state {
  13514. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13515. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  13516. {"data_type", serialization<decltype(opdef.data_type)>::dump(opdef.data_type)},
  13517. {"keepdim", serialization<decltype(opdef.keepdim)>::dump(opdef.keepdim)}
  13518. };
  13519. return py::cast(state).release().ptr();
  13520. }
  13521. static PyObject* setstate(PyObject* self, PyObject* args) {
  13522. PyObject* dict = PyTuple_GetItem(args, 0);
  13523. if (!dict) return NULL;
  13524. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13525. auto& opdef = reinterpret_cast<PyOp(Reduce)*>(self)->inst();
  13526. static_cast<void>(opdef);
  13527. {
  13528. auto&& iter = state.find("mode");
  13529. if (iter != state.end()) {
  13530. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13531. }
  13532. }
  13533. {
  13534. auto&& iter = state.find("axis");
  13535. if (iter != state.end()) {
  13536. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  13537. }
  13538. }
  13539. {
  13540. auto&& iter = state.find("data_type");
  13541. if (iter != state.end()) {
  13542. opdef.data_type = serialization<decltype(opdef.data_type)>::load(iter->second);
  13543. }
  13544. }
  13545. {
  13546. auto&& iter = state.find("keepdim");
  13547. if (iter != state.end()) {
  13548. opdef.keepdim = serialization<decltype(opdef.keepdim)>::load(iter->second);
  13549. }
  13550. }
  13551. Py_RETURN_NONE;
  13552. }
  13553. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13554. // };
  13555. PyOpDefEnd(Reduce)
  13556. int PyOp(Reduce)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13557. static const char* kwlist[] = {"mode", "axis", "data_type", "keepdim", "scope", NULL};
  13558. PyObject *mode = NULL, *axis = NULL, *data_type = NULL, *keepdim = NULL, *scope = NULL;
  13559. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &mode, &axis, &data_type, &keepdim, &scope))
  13560. return -1;
  13561. if (mode) {
  13562. try {
  13563. // TODO: remove this guard which is used for pybind11 implicit conversion
  13564. py::detail::loader_life_support guard{};
  13565. reinterpret_cast<PyOp(Reduce)*>(self)->inst().mode =
  13566. py::cast<decltype(Reduce::mode)>(py::handle(mode));
  13567. } CATCH_ALL(-1)
  13568. }
  13569. if (axis) {
  13570. try {
  13571. // TODO: remove this guard which is used for pybind11 implicit conversion
  13572. py::detail::loader_life_support guard{};
  13573. reinterpret_cast<PyOp(Reduce)*>(self)->inst().axis =
  13574. py::cast<decltype(Reduce::axis)>(py::handle(axis));
  13575. } CATCH_ALL(-1)
  13576. }
  13577. if (data_type) {
  13578. try {
  13579. // TODO: remove this guard which is used for pybind11 implicit conversion
  13580. py::detail::loader_life_support guard{};
  13581. reinterpret_cast<PyOp(Reduce)*>(self)->inst().data_type =
  13582. py::cast<decltype(Reduce::data_type)>(py::handle(data_type));
  13583. } CATCH_ALL(-1)
  13584. }
  13585. if (keepdim) {
  13586. try {
  13587. // TODO: remove this guard which is used for pybind11 implicit conversion
  13588. py::detail::loader_life_support guard{};
  13589. reinterpret_cast<PyOp(Reduce)*>(self)->inst().keepdim =
  13590. py::cast<decltype(Reduce::keepdim)>(py::handle(keepdim));
  13591. } CATCH_ALL(-1)
  13592. }
  13593. if (scope) {
  13594. try {
  13595. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13596. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13597. } CATCH_ALL(-1)
  13598. }
  13599. return 0;
  13600. }
  13601. PyGetSetDef PyOp(Reduce)::py_getsetters[] = {
  13602. {const_cast<char*>("mode"), py_get_generic(Reduce, mode), py_set_generic(Reduce, mode), const_cast<char*>("mode"), NULL},
  13603. {const_cast<char*>("axis"), py_get_generic(Reduce, axis), py_set_generic(Reduce, axis), const_cast<char*>("axis"), NULL},
  13604. {const_cast<char*>("data_type"), py_get_generic(Reduce, data_type), py_set_generic(Reduce, data_type), const_cast<char*>("data_type"), NULL},
  13605. {const_cast<char*>("keepdim"), py_get_generic(Reduce, keepdim), py_set_generic(Reduce, keepdim), const_cast<char*>("keepdim"), NULL},
  13606. {NULL} /* Sentinel */
  13607. };
  13608. PyMethodDef PyOp(Reduce)::tp_methods[] = {
  13609. {const_cast<char*>("__getstate__"), PyOp(Reduce)::getstate, METH_NOARGS, "Reduce getstate"},
  13610. {const_cast<char*>("__setstate__"), PyOp(Reduce)::setstate, METH_VARARGS, "Reduce setstate"},
  13611. {NULL} /* Sentinel */
  13612. };
  13613. void _init_py_Reduce(py::module m) {
  13614. using py_op = PyOp(Reduce);
  13615. auto& py_type = PyOpType(Reduce);
  13616. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13617. py_type.tp_name = "megengine.core._imperative_rt.ops.Reduce";
  13618. py_type.tp_basicsize = sizeof(PyOp(Reduce));
  13619. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13620. py_type.tp_doc = "Reduce";
  13621. py_type.tp_base = &PyOpType(OpDef);
  13622. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13623. py_type.tp_new = py_new_generic<py_op>;
  13624. py_type.tp_init = py_op::py_init;
  13625. py_type.tp_methods = py_op::tp_methods;
  13626. py_type.tp_getset = py_op::py_getsetters;
  13627. mgb_assert(PyType_Ready(&py_type) >= 0);
  13628. _init_py_Reduce_Mode(py_type);
  13629. _init_py_Reduce_DataType(py_type);
  13630. PyType_Modified(&py_type);
  13631. m.add_object("Reduce", reinterpret_cast<PyObject*>(&py_type));
  13632. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reduce::typeinfo(), &py_type).second);
  13633. }
  13634. void _init_py_RegionRestrictedConvolution_Mode(PyTypeObject& py_type) {
  13635. auto& e_type = EnumWrapper<RegionRestrictedConvolution::Mode>::type;
  13636. Py_INCREF(e_type);
  13637. mgb_assert(PyDict_SetItemString(
  13638. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13639. }
  13640. void _init_py_RegionRestrictedConvolution_Sparse(PyTypeObject& py_type) {
  13641. auto& e_type = EnumWrapper<RegionRestrictedConvolution::Sparse>::type;
  13642. Py_INCREF(e_type);
  13643. mgb_assert(PyDict_SetItemString(
  13644. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13645. }
  13646. void _init_py_RegionRestrictedConvolution_Format(PyTypeObject& py_type) {
  13647. auto& e_type = EnumWrapper<RegionRestrictedConvolution::Format>::type;
  13648. Py_INCREF(e_type);
  13649. mgb_assert(PyDict_SetItemString(
  13650. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13651. }
  13652. void _init_py_RegionRestrictedConvolution_ComputeMode(PyTypeObject& py_type) {
  13653. auto& e_type = EnumWrapper<RegionRestrictedConvolution::ComputeMode>::type;
  13654. Py_INCREF(e_type);
  13655. mgb_assert(PyDict_SetItemString(
  13656. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13657. }
  13658. PyOpDefBegin(RegionRestrictedConvolution) // {
  13659. static PyGetSetDef py_getsetters[];
  13660. static PyMethodDef tp_methods[];
  13661. static PyObject* getstate(PyObject* self, PyObject*) {
  13662. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst();
  13663. static_cast<void>(opdef);
  13664. std::unordered_map<std::string, py::object> state {
  13665. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13666. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  13667. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  13668. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  13669. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  13670. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  13671. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  13672. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  13673. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  13674. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)}
  13675. };
  13676. return py::cast(state).release().ptr();
  13677. }
  13678. static PyObject* setstate(PyObject* self, PyObject* args) {
  13679. PyObject* dict = PyTuple_GetItem(args, 0);
  13680. if (!dict) return NULL;
  13681. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13682. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst();
  13683. static_cast<void>(opdef);
  13684. {
  13685. auto&& iter = state.find("mode");
  13686. if (iter != state.end()) {
  13687. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13688. }
  13689. }
  13690. {
  13691. auto&& iter = state.find("pad_h");
  13692. if (iter != state.end()) {
  13693. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  13694. }
  13695. }
  13696. {
  13697. auto&& iter = state.find("pad_w");
  13698. if (iter != state.end()) {
  13699. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  13700. }
  13701. }
  13702. {
  13703. auto&& iter = state.find("stride_h");
  13704. if (iter != state.end()) {
  13705. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  13706. }
  13707. }
  13708. {
  13709. auto&& iter = state.find("stride_w");
  13710. if (iter != state.end()) {
  13711. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  13712. }
  13713. }
  13714. {
  13715. auto&& iter = state.find("dilate_h");
  13716. if (iter != state.end()) {
  13717. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  13718. }
  13719. }
  13720. {
  13721. auto&& iter = state.find("dilate_w");
  13722. if (iter != state.end()) {
  13723. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  13724. }
  13725. }
  13726. {
  13727. auto&& iter = state.find("sparse");
  13728. if (iter != state.end()) {
  13729. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  13730. }
  13731. }
  13732. {
  13733. auto&& iter = state.find("format");
  13734. if (iter != state.end()) {
  13735. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  13736. }
  13737. }
  13738. {
  13739. auto&& iter = state.find("compute_mode");
  13740. if (iter != state.end()) {
  13741. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  13742. }
  13743. }
  13744. Py_RETURN_NONE;
  13745. }
  13746. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13747. // };
  13748. PyOpDefEnd(RegionRestrictedConvolution)
  13749. int PyOp(RegionRestrictedConvolution)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13750. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL};
  13751. 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;
  13752. 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))
  13753. return -1;
  13754. if (mode) {
  13755. try {
  13756. // TODO: remove this guard which is used for pybind11 implicit conversion
  13757. py::detail::loader_life_support guard{};
  13758. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().mode =
  13759. py::cast<decltype(RegionRestrictedConvolution::mode)>(py::handle(mode));
  13760. } CATCH_ALL(-1)
  13761. }
  13762. if (pad_h) {
  13763. try {
  13764. // TODO: remove this guard which is used for pybind11 implicit conversion
  13765. py::detail::loader_life_support guard{};
  13766. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().pad_h =
  13767. py::cast<decltype(RegionRestrictedConvolution::pad_h)>(py::handle(pad_h));
  13768. } CATCH_ALL(-1)
  13769. }
  13770. if (pad_w) {
  13771. try {
  13772. // TODO: remove this guard which is used for pybind11 implicit conversion
  13773. py::detail::loader_life_support guard{};
  13774. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().pad_w =
  13775. py::cast<decltype(RegionRestrictedConvolution::pad_w)>(py::handle(pad_w));
  13776. } CATCH_ALL(-1)
  13777. }
  13778. if (stride_h) {
  13779. try {
  13780. // TODO: remove this guard which is used for pybind11 implicit conversion
  13781. py::detail::loader_life_support guard{};
  13782. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().stride_h =
  13783. py::cast<decltype(RegionRestrictedConvolution::stride_h)>(py::handle(stride_h));
  13784. } CATCH_ALL(-1)
  13785. }
  13786. if (stride_w) {
  13787. try {
  13788. // TODO: remove this guard which is used for pybind11 implicit conversion
  13789. py::detail::loader_life_support guard{};
  13790. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().stride_w =
  13791. py::cast<decltype(RegionRestrictedConvolution::stride_w)>(py::handle(stride_w));
  13792. } CATCH_ALL(-1)
  13793. }
  13794. if (dilate_h) {
  13795. try {
  13796. // TODO: remove this guard which is used for pybind11 implicit conversion
  13797. py::detail::loader_life_support guard{};
  13798. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().dilate_h =
  13799. py::cast<decltype(RegionRestrictedConvolution::dilate_h)>(py::handle(dilate_h));
  13800. } CATCH_ALL(-1)
  13801. }
  13802. if (dilate_w) {
  13803. try {
  13804. // TODO: remove this guard which is used for pybind11 implicit conversion
  13805. py::detail::loader_life_support guard{};
  13806. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().dilate_w =
  13807. py::cast<decltype(RegionRestrictedConvolution::dilate_w)>(py::handle(dilate_w));
  13808. } CATCH_ALL(-1)
  13809. }
  13810. if (sparse) {
  13811. try {
  13812. // TODO: remove this guard which is used for pybind11 implicit conversion
  13813. py::detail::loader_life_support guard{};
  13814. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().sparse =
  13815. py::cast<decltype(RegionRestrictedConvolution::sparse)>(py::handle(sparse));
  13816. } CATCH_ALL(-1)
  13817. }
  13818. if (format) {
  13819. try {
  13820. // TODO: remove this guard which is used for pybind11 implicit conversion
  13821. py::detail::loader_life_support guard{};
  13822. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().format =
  13823. py::cast<decltype(RegionRestrictedConvolution::format)>(py::handle(format));
  13824. } CATCH_ALL(-1)
  13825. }
  13826. if (compute_mode) {
  13827. try {
  13828. // TODO: remove this guard which is used for pybind11 implicit conversion
  13829. py::detail::loader_life_support guard{};
  13830. reinterpret_cast<PyOp(RegionRestrictedConvolution)*>(self)->inst().compute_mode =
  13831. py::cast<decltype(RegionRestrictedConvolution::compute_mode)>(py::handle(compute_mode));
  13832. } CATCH_ALL(-1)
  13833. }
  13834. if (scope) {
  13835. try {
  13836. reinterpret_cast<PyOp(OpDef)*>(self)->op
  13837. ->set_scope(py::cast<std::string>(py::handle(scope)));
  13838. } CATCH_ALL(-1)
  13839. }
  13840. return 0;
  13841. }
  13842. PyGetSetDef PyOp(RegionRestrictedConvolution)::py_getsetters[] = {
  13843. {const_cast<char*>("mode"), py_get_generic(RegionRestrictedConvolution, mode), py_set_generic(RegionRestrictedConvolution, mode), const_cast<char*>("mode"), NULL},
  13844. {const_cast<char*>("pad_h"), py_get_generic(RegionRestrictedConvolution, pad_h), py_set_generic(RegionRestrictedConvolution, pad_h), const_cast<char*>("pad_h"), NULL},
  13845. {const_cast<char*>("pad_w"), py_get_generic(RegionRestrictedConvolution, pad_w), py_set_generic(RegionRestrictedConvolution, pad_w), const_cast<char*>("pad_w"), NULL},
  13846. {const_cast<char*>("stride_h"), py_get_generic(RegionRestrictedConvolution, stride_h), py_set_generic(RegionRestrictedConvolution, stride_h), const_cast<char*>("stride_h"), NULL},
  13847. {const_cast<char*>("stride_w"), py_get_generic(RegionRestrictedConvolution, stride_w), py_set_generic(RegionRestrictedConvolution, stride_w), const_cast<char*>("stride_w"), NULL},
  13848. {const_cast<char*>("dilate_h"), py_get_generic(RegionRestrictedConvolution, dilate_h), py_set_generic(RegionRestrictedConvolution, dilate_h), const_cast<char*>("dilate_h"), NULL},
  13849. {const_cast<char*>("dilate_w"), py_get_generic(RegionRestrictedConvolution, dilate_w), py_set_generic(RegionRestrictedConvolution, dilate_w), const_cast<char*>("dilate_w"), NULL},
  13850. {const_cast<char*>("sparse"), py_get_generic(RegionRestrictedConvolution, sparse), py_set_generic(RegionRestrictedConvolution, sparse), const_cast<char*>("sparse"), NULL},
  13851. {const_cast<char*>("format"), py_get_generic(RegionRestrictedConvolution, format), py_set_generic(RegionRestrictedConvolution, format), const_cast<char*>("format"), NULL},
  13852. {const_cast<char*>("compute_mode"), py_get_generic(RegionRestrictedConvolution, compute_mode), py_set_generic(RegionRestrictedConvolution, compute_mode), const_cast<char*>("compute_mode"), NULL},
  13853. {NULL} /* Sentinel */
  13854. };
  13855. PyMethodDef PyOp(RegionRestrictedConvolution)::tp_methods[] = {
  13856. {const_cast<char*>("__getstate__"), PyOp(RegionRestrictedConvolution)::getstate, METH_NOARGS, "RegionRestrictedConvolution getstate"},
  13857. {const_cast<char*>("__setstate__"), PyOp(RegionRestrictedConvolution)::setstate, METH_VARARGS, "RegionRestrictedConvolution setstate"},
  13858. {NULL} /* Sentinel */
  13859. };
  13860. void _init_py_RegionRestrictedConvolution(py::module m) {
  13861. using py_op = PyOp(RegionRestrictedConvolution);
  13862. auto& py_type = PyOpType(RegionRestrictedConvolution);
  13863. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  13864. py_type.tp_name = "megengine.core._imperative_rt.ops.RegionRestrictedConvolution";
  13865. py_type.tp_basicsize = sizeof(PyOp(RegionRestrictedConvolution));
  13866. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  13867. py_type.tp_doc = "RegionRestrictedConvolution";
  13868. py_type.tp_base = &PyOpType(OpDef);
  13869. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  13870. py_type.tp_new = py_new_generic<py_op>;
  13871. py_type.tp_init = py_op::py_init;
  13872. py_type.tp_methods = py_op::tp_methods;
  13873. py_type.tp_getset = py_op::py_getsetters;
  13874. mgb_assert(PyType_Ready(&py_type) >= 0);
  13875. _init_py_RegionRestrictedConvolution_Mode(py_type);
  13876. _init_py_RegionRestrictedConvolution_Sparse(py_type);
  13877. _init_py_RegionRestrictedConvolution_Format(py_type);
  13878. _init_py_RegionRestrictedConvolution_ComputeMode(py_type);
  13879. PyType_Modified(&py_type);
  13880. m.add_object("RegionRestrictedConvolution", reinterpret_cast<PyObject*>(&py_type));
  13881. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RegionRestrictedConvolution::typeinfo(), &py_type).second);
  13882. }
  13883. void _init_py_RegionRestrictedConvolutionBackwardData_Mode(PyTypeObject& py_type) {
  13884. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::Mode>::type;
  13885. Py_INCREF(e_type);
  13886. mgb_assert(PyDict_SetItemString(
  13887. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13888. }
  13889. void _init_py_RegionRestrictedConvolutionBackwardData_Sparse(PyTypeObject& py_type) {
  13890. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::Sparse>::type;
  13891. Py_INCREF(e_type);
  13892. mgb_assert(PyDict_SetItemString(
  13893. py_type.tp_dict, "Sparse", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13894. }
  13895. void _init_py_RegionRestrictedConvolutionBackwardData_Format(PyTypeObject& py_type) {
  13896. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::Format>::type;
  13897. Py_INCREF(e_type);
  13898. mgb_assert(PyDict_SetItemString(
  13899. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13900. }
  13901. void _init_py_RegionRestrictedConvolutionBackwardData_ComputeMode(PyTypeObject& py_type) {
  13902. auto& e_type = EnumWrapper<RegionRestrictedConvolutionBackwardData::ComputeMode>::type;
  13903. Py_INCREF(e_type);
  13904. mgb_assert(PyDict_SetItemString(
  13905. py_type.tp_dict, "ComputeMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  13906. }
  13907. PyOpDefBegin(RegionRestrictedConvolutionBackwardData) // {
  13908. static PyGetSetDef py_getsetters[];
  13909. static PyMethodDef tp_methods[];
  13910. static PyObject* getstate(PyObject* self, PyObject*) {
  13911. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst();
  13912. static_cast<void>(opdef);
  13913. std::unordered_map<std::string, py::object> state {
  13914. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)},
  13915. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  13916. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  13917. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  13918. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  13919. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  13920. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  13921. {"sparse", serialization<decltype(opdef.sparse)>::dump(opdef.sparse)},
  13922. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  13923. {"compute_mode", serialization<decltype(opdef.compute_mode)>::dump(opdef.compute_mode)}
  13924. };
  13925. return py::cast(state).release().ptr();
  13926. }
  13927. static PyObject* setstate(PyObject* self, PyObject* args) {
  13928. PyObject* dict = PyTuple_GetItem(args, 0);
  13929. if (!dict) return NULL;
  13930. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  13931. auto& opdef = reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst();
  13932. static_cast<void>(opdef);
  13933. {
  13934. auto&& iter = state.find("mode");
  13935. if (iter != state.end()) {
  13936. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  13937. }
  13938. }
  13939. {
  13940. auto&& iter = state.find("pad_h");
  13941. if (iter != state.end()) {
  13942. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  13943. }
  13944. }
  13945. {
  13946. auto&& iter = state.find("pad_w");
  13947. if (iter != state.end()) {
  13948. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  13949. }
  13950. }
  13951. {
  13952. auto&& iter = state.find("stride_h");
  13953. if (iter != state.end()) {
  13954. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  13955. }
  13956. }
  13957. {
  13958. auto&& iter = state.find("stride_w");
  13959. if (iter != state.end()) {
  13960. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  13961. }
  13962. }
  13963. {
  13964. auto&& iter = state.find("dilate_h");
  13965. if (iter != state.end()) {
  13966. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  13967. }
  13968. }
  13969. {
  13970. auto&& iter = state.find("dilate_w");
  13971. if (iter != state.end()) {
  13972. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  13973. }
  13974. }
  13975. {
  13976. auto&& iter = state.find("sparse");
  13977. if (iter != state.end()) {
  13978. opdef.sparse = serialization<decltype(opdef.sparse)>::load(iter->second);
  13979. }
  13980. }
  13981. {
  13982. auto&& iter = state.find("format");
  13983. if (iter != state.end()) {
  13984. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  13985. }
  13986. }
  13987. {
  13988. auto&& iter = state.find("compute_mode");
  13989. if (iter != state.end()) {
  13990. opdef.compute_mode = serialization<decltype(opdef.compute_mode)>::load(iter->second);
  13991. }
  13992. }
  13993. Py_RETURN_NONE;
  13994. }
  13995. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  13996. // };
  13997. PyOpDefEnd(RegionRestrictedConvolutionBackwardData)
  13998. int PyOp(RegionRestrictedConvolutionBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  13999. static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL};
  14000. 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;
  14001. 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))
  14002. return -1;
  14003. if (mode) {
  14004. try {
  14005. // TODO: remove this guard which is used for pybind11 implicit conversion
  14006. py::detail::loader_life_support guard{};
  14007. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().mode =
  14008. py::cast<decltype(RegionRestrictedConvolutionBackwardData::mode)>(py::handle(mode));
  14009. } CATCH_ALL(-1)
  14010. }
  14011. if (pad_h) {
  14012. try {
  14013. // TODO: remove this guard which is used for pybind11 implicit conversion
  14014. py::detail::loader_life_support guard{};
  14015. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().pad_h =
  14016. py::cast<decltype(RegionRestrictedConvolutionBackwardData::pad_h)>(py::handle(pad_h));
  14017. } CATCH_ALL(-1)
  14018. }
  14019. if (pad_w) {
  14020. try {
  14021. // TODO: remove this guard which is used for pybind11 implicit conversion
  14022. py::detail::loader_life_support guard{};
  14023. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().pad_w =
  14024. py::cast<decltype(RegionRestrictedConvolutionBackwardData::pad_w)>(py::handle(pad_w));
  14025. } CATCH_ALL(-1)
  14026. }
  14027. if (stride_h) {
  14028. try {
  14029. // TODO: remove this guard which is used for pybind11 implicit conversion
  14030. py::detail::loader_life_support guard{};
  14031. reinterpret_cast<PyOp(RegionRestrictedConvolutionBackwardData)*>(self)->inst().stride_h =
  14032. py::cast<decltype(RegionRestrictedConvolutionBackwardData::stride_h)>(py::handle(stride_h));
  14033. } CATCH_ALL(-1)
  14034. }
  14035. if (stride_w) {
  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(RegionRestrictedConvolutionBackwardData)*>(self)->inst().stride_w =
  14040. py::cast<decltype(RegionRestrictedConvolutionBackwardData::stride_w)>(py::handle(stride_w));
  14041. } CATCH_ALL(-1)
  14042. }
  14043. if (dilate_h) {
  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(RegionRestrictedConvolutionBackwardData)*>(self)->inst().dilate_h =
  14048. py::cast<decltype(RegionRestrictedConvolutionBackwardData::dilate_h)>(py::handle(dilate_h));
  14049. } CATCH_ALL(-1)
  14050. }
  14051. if (dilate_w) {
  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(RegionRestrictedConvolutionBackwardData)*>(self)->inst().dilate_w =
  14056. py::cast<decltype(RegionRestrictedConvolutionBackwardData::dilate_w)>(py::handle(dilate_w));
  14057. } CATCH_ALL(-1)
  14058. }
  14059. if (sparse) {
  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(RegionRestrictedConvolutionBackwardData)*>(self)->inst().sparse =
  14064. py::cast<decltype(RegionRestrictedConvolutionBackwardData::sparse)>(py::handle(sparse));
  14065. } CATCH_ALL(-1)
  14066. }
  14067. if (format) {
  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(RegionRestrictedConvolutionBackwardData)*>(self)->inst().format =
  14072. py::cast<decltype(RegionRestrictedConvolutionBackwardData::format)>(py::handle(format));
  14073. } CATCH_ALL(-1)
  14074. }
  14075. if (compute_mode) {
  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(RegionRestrictedConvolutionBackwardData)*>(self)->inst().compute_mode =
  14080. py::cast<decltype(RegionRestrictedConvolutionBackwardData::compute_mode)>(py::handle(compute_mode));
  14081. } CATCH_ALL(-1)
  14082. }
  14083. if (scope) {
  14084. try {
  14085. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14086. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14087. } CATCH_ALL(-1)
  14088. }
  14089. return 0;
  14090. }
  14091. PyGetSetDef PyOp(RegionRestrictedConvolutionBackwardData)::py_getsetters[] = {
  14092. {const_cast<char*>("mode"), py_get_generic(RegionRestrictedConvolutionBackwardData, mode), py_set_generic(RegionRestrictedConvolutionBackwardData, mode), const_cast<char*>("mode"), NULL},
  14093. {const_cast<char*>("pad_h"), py_get_generic(RegionRestrictedConvolutionBackwardData, pad_h), py_set_generic(RegionRestrictedConvolutionBackwardData, pad_h), const_cast<char*>("pad_h"), NULL},
  14094. {const_cast<char*>("pad_w"), py_get_generic(RegionRestrictedConvolutionBackwardData, pad_w), py_set_generic(RegionRestrictedConvolutionBackwardData, pad_w), const_cast<char*>("pad_w"), NULL},
  14095. {const_cast<char*>("stride_h"), py_get_generic(RegionRestrictedConvolutionBackwardData, stride_h), py_set_generic(RegionRestrictedConvolutionBackwardData, stride_h), const_cast<char*>("stride_h"), NULL},
  14096. {const_cast<char*>("stride_w"), py_get_generic(RegionRestrictedConvolutionBackwardData, stride_w), py_set_generic(RegionRestrictedConvolutionBackwardData, stride_w), const_cast<char*>("stride_w"), NULL},
  14097. {const_cast<char*>("dilate_h"), py_get_generic(RegionRestrictedConvolutionBackwardData, dilate_h), py_set_generic(RegionRestrictedConvolutionBackwardData, dilate_h), const_cast<char*>("dilate_h"), NULL},
  14098. {const_cast<char*>("dilate_w"), py_get_generic(RegionRestrictedConvolutionBackwardData, dilate_w), py_set_generic(RegionRestrictedConvolutionBackwardData, dilate_w), const_cast<char*>("dilate_w"), NULL},
  14099. {const_cast<char*>("sparse"), py_get_generic(RegionRestrictedConvolutionBackwardData, sparse), py_set_generic(RegionRestrictedConvolutionBackwardData, sparse), const_cast<char*>("sparse"), NULL},
  14100. {const_cast<char*>("format"), py_get_generic(RegionRestrictedConvolutionBackwardData, format), py_set_generic(RegionRestrictedConvolutionBackwardData, format), const_cast<char*>("format"), NULL},
  14101. {const_cast<char*>("compute_mode"), py_get_generic(RegionRestrictedConvolutionBackwardData, compute_mode), py_set_generic(RegionRestrictedConvolutionBackwardData, compute_mode), const_cast<char*>("compute_mode"), NULL},
  14102. {NULL} /* Sentinel */
  14103. };
  14104. PyMethodDef PyOp(RegionRestrictedConvolutionBackwardData)::tp_methods[] = {
  14105. {const_cast<char*>("__getstate__"), PyOp(RegionRestrictedConvolutionBackwardData)::getstate, METH_NOARGS, "RegionRestrictedConvolutionBackwardData getstate"},
  14106. {const_cast<char*>("__setstate__"), PyOp(RegionRestrictedConvolutionBackwardData)::setstate, METH_VARARGS, "RegionRestrictedConvolutionBackwardData setstate"},
  14107. {NULL} /* Sentinel */
  14108. };
  14109. void _init_py_RegionRestrictedConvolutionBackwardData(py::module m) {
  14110. using py_op = PyOp(RegionRestrictedConvolutionBackwardData);
  14111. auto& py_type = PyOpType(RegionRestrictedConvolutionBackwardData);
  14112. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14113. py_type.tp_name = "megengine.core._imperative_rt.ops.RegionRestrictedConvolutionBackwardData";
  14114. py_type.tp_basicsize = sizeof(PyOp(RegionRestrictedConvolutionBackwardData));
  14115. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14116. py_type.tp_doc = "RegionRestrictedConvolutionBackwardData";
  14117. py_type.tp_base = &PyOpType(OpDef);
  14118. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14119. py_type.tp_new = py_new_generic<py_op>;
  14120. py_type.tp_init = py_op::py_init;
  14121. py_type.tp_methods = py_op::tp_methods;
  14122. py_type.tp_getset = py_op::py_getsetters;
  14123. mgb_assert(PyType_Ready(&py_type) >= 0);
  14124. _init_py_RegionRestrictedConvolutionBackwardData_Mode(py_type);
  14125. _init_py_RegionRestrictedConvolutionBackwardData_Sparse(py_type);
  14126. _init_py_RegionRestrictedConvolutionBackwardData_Format(py_type);
  14127. _init_py_RegionRestrictedConvolutionBackwardData_ComputeMode(py_type);
  14128. PyType_Modified(&py_type);
  14129. m.add_object("RegionRestrictedConvolutionBackwardData", reinterpret_cast<PyObject*>(&py_type));
  14130. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RegionRestrictedConvolutionBackwardData::typeinfo(), &py_type).second);
  14131. }
  14132. template<> struct EnumTrait<Remap::InterpolationMode> {
  14133. static constexpr const char *name = "Remap.InterpolationMode";
  14134. static constexpr std::underlying_type_t<Remap::InterpolationMode> max = 5 - 1;
  14135. };
  14136. template<> PyTypeObject* EnumWrapper<Remap::InterpolationMode>::type = nullptr;
  14137. template<> const char*
  14138. EnumWrapper<Remap::InterpolationMode>::members[] = {"NEAREST", "LINEAR", "AREA", "CUBIC", "LANCZOS4"};
  14139. template<> std::unordered_map<std::string, Remap::InterpolationMode>
  14140. 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}};
  14141. template<> PyObject* EnumWrapper<Remap::InterpolationMode>::pyobj_insts[5] = {nullptr};
  14142. void _init_py_Remap_InterpolationMode(PyTypeObject& py_type) {
  14143. auto& e_type = EnumWrapper<Remap::InterpolationMode>::type;
  14144. static PyMethodDef tp_methods[] = {
  14145. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Remap::InterpolationMode>::py_dump, METH_NOARGS, NULL},
  14146. {NULL} /* Sentinel */
  14147. };
  14148. static PyType_Slot slots[] = {
  14149. {Py_tp_repr, (void*)EnumWrapper<Remap::InterpolationMode>::py_repr},
  14150. {Py_tp_richcompare, (void*)EnumWrapper<Remap::InterpolationMode>::tp_richcompare},
  14151. {Py_tp_methods, tp_methods},
  14152. {0, NULL}
  14153. };
  14154. static PyType_Spec spec = {
  14155. // name
  14156. "megengine.core._imperative_rt.ops.Remap.InterpolationMode",
  14157. // basicsize
  14158. sizeof(EnumWrapper<Remap::InterpolationMode>),
  14159. // itemsize
  14160. 0,
  14161. // flags
  14162. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  14163. // slots
  14164. slots
  14165. };
  14166. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  14167. mgb_assert(
  14168. e_type->tp_setattro(
  14169. reinterpret_cast<PyObject*>(e_type),
  14170. py::cast("__name__").release().ptr(),
  14171. py::cast("InterpolationMode").release().ptr()) >= 0);
  14172. mgb_assert(
  14173. e_type->tp_setattro(
  14174. reinterpret_cast<PyObject*>(e_type),
  14175. py::cast("__module__").release().ptr(),
  14176. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  14177. mgb_assert(
  14178. e_type->tp_setattro(
  14179. reinterpret_cast<PyObject*>(e_type),
  14180. py::cast("__qualname__").release().ptr(),
  14181. py::cast("Remap.InterpolationMode").release().ptr()) >= 0);
  14182. {
  14183. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14184. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::NEAREST;
  14185. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEAREST", inst) >= 0);
  14186. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[0] = inst;
  14187. }{
  14188. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14189. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::LINEAR;
  14190. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LINEAR", inst) >= 0);
  14191. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[1] = inst;
  14192. }{
  14193. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14194. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::AREA;
  14195. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AREA", inst) >= 0);
  14196. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[2] = inst;
  14197. }{
  14198. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14199. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::CUBIC;
  14200. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CUBIC", inst) >= 0);
  14201. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[3] = inst;
  14202. }{
  14203. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14204. reinterpret_cast<EnumWrapper<Remap::InterpolationMode>*>(inst)->value = Remap::InterpolationMode::LANCZOS4;
  14205. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LANCZOS4", inst) >= 0);
  14206. EnumWrapper<Remap::InterpolationMode>::pyobj_insts[4] = inst;
  14207. }
  14208. Py_INCREF(e_type);
  14209. mgb_assert(PyDict_SetItemString(
  14210. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14211. }
  14212. template<> struct EnumTrait<Remap::BorderMode> {
  14213. static constexpr const char *name = "Remap.BorderMode";
  14214. static constexpr std::underlying_type_t<Remap::BorderMode> max = 7 - 1;
  14215. };
  14216. template<> PyTypeObject* EnumWrapper<Remap::BorderMode>::type = nullptr;
  14217. template<> const char*
  14218. EnumWrapper<Remap::BorderMode>::members[] = {"REPLICATE", "REFLECT", "REFLECT_101", "WRAP", "CONSTANT", "TRANSPARENT", "ISOLATED"};
  14219. template<> std::unordered_map<std::string, Remap::BorderMode>
  14220. 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}};
  14221. template<> PyObject* EnumWrapper<Remap::BorderMode>::pyobj_insts[7] = {nullptr};
  14222. void _init_py_Remap_BorderMode(PyTypeObject& py_type) {
  14223. auto& e_type = EnumWrapper<Remap::BorderMode>::type;
  14224. static PyMethodDef tp_methods[] = {
  14225. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<Remap::BorderMode>::py_dump, METH_NOARGS, NULL},
  14226. {NULL} /* Sentinel */
  14227. };
  14228. static PyType_Slot slots[] = {
  14229. {Py_tp_repr, (void*)EnumWrapper<Remap::BorderMode>::py_repr},
  14230. {Py_tp_richcompare, (void*)EnumWrapper<Remap::BorderMode>::tp_richcompare},
  14231. {Py_tp_methods, tp_methods},
  14232. {0, NULL}
  14233. };
  14234. static PyType_Spec spec = {
  14235. // name
  14236. "megengine.core._imperative_rt.ops.Remap.BorderMode",
  14237. // basicsize
  14238. sizeof(EnumWrapper<Remap::BorderMode>),
  14239. // itemsize
  14240. 0,
  14241. // flags
  14242. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  14243. // slots
  14244. slots
  14245. };
  14246. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  14247. mgb_assert(
  14248. e_type->tp_setattro(
  14249. reinterpret_cast<PyObject*>(e_type),
  14250. py::cast("__name__").release().ptr(),
  14251. py::cast("BorderMode").release().ptr()) >= 0);
  14252. mgb_assert(
  14253. e_type->tp_setattro(
  14254. reinterpret_cast<PyObject*>(e_type),
  14255. py::cast("__module__").release().ptr(),
  14256. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  14257. mgb_assert(
  14258. e_type->tp_setattro(
  14259. reinterpret_cast<PyObject*>(e_type),
  14260. py::cast("__qualname__").release().ptr(),
  14261. py::cast("Remap.BorderMode").release().ptr()) >= 0);
  14262. {
  14263. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14264. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REPLICATE;
  14265. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0);
  14266. EnumWrapper<Remap::BorderMode>::pyobj_insts[0] = inst;
  14267. }{
  14268. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14269. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REFLECT;
  14270. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0);
  14271. EnumWrapper<Remap::BorderMode>::pyobj_insts[1] = inst;
  14272. }{
  14273. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14274. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::REFLECT_101;
  14275. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT_101", inst) >= 0);
  14276. EnumWrapper<Remap::BorderMode>::pyobj_insts[2] = inst;
  14277. }{
  14278. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14279. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::WRAP;
  14280. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "WRAP", inst) >= 0);
  14281. EnumWrapper<Remap::BorderMode>::pyobj_insts[3] = inst;
  14282. }{
  14283. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14284. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::CONSTANT;
  14285. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0);
  14286. EnumWrapper<Remap::BorderMode>::pyobj_insts[4] = inst;
  14287. }{
  14288. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14289. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::TRANSPARENT;
  14290. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRANSPARENT", inst) >= 0);
  14291. EnumWrapper<Remap::BorderMode>::pyobj_insts[5] = inst;
  14292. }{
  14293. PyObject* inst = e_type->tp_alloc(e_type, 0);
  14294. reinterpret_cast<EnumWrapper<Remap::BorderMode>*>(inst)->value = Remap::BorderMode::ISOLATED;
  14295. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISOLATED", inst) >= 0);
  14296. EnumWrapper<Remap::BorderMode>::pyobj_insts[6] = inst;
  14297. }
  14298. Py_INCREF(e_type);
  14299. mgb_assert(PyDict_SetItemString(
  14300. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14301. }
  14302. void _init_py_Remap_Format(PyTypeObject& py_type) {
  14303. auto& e_type = EnumWrapper<Remap::Format>::type;
  14304. Py_INCREF(e_type);
  14305. mgb_assert(PyDict_SetItemString(
  14306. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14307. }
  14308. PyOpDefBegin(Remap) // {
  14309. static PyGetSetDef py_getsetters[];
  14310. static PyMethodDef tp_methods[];
  14311. static PyObject* getstate(PyObject* self, PyObject*) {
  14312. auto& opdef = reinterpret_cast<PyOp(Remap)*>(self)->inst();
  14313. static_cast<void>(opdef);
  14314. std::unordered_map<std::string, py::object> state {
  14315. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  14316. {"border_type", serialization<decltype(opdef.border_type)>::dump(opdef.border_type)},
  14317. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  14318. {"scalar", serialization<decltype(opdef.scalar)>::dump(opdef.scalar)}
  14319. };
  14320. return py::cast(state).release().ptr();
  14321. }
  14322. static PyObject* setstate(PyObject* self, PyObject* args) {
  14323. PyObject* dict = PyTuple_GetItem(args, 0);
  14324. if (!dict) return NULL;
  14325. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14326. auto& opdef = reinterpret_cast<PyOp(Remap)*>(self)->inst();
  14327. static_cast<void>(opdef);
  14328. {
  14329. auto&& iter = state.find("imode");
  14330. if (iter != state.end()) {
  14331. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  14332. }
  14333. }
  14334. {
  14335. auto&& iter = state.find("border_type");
  14336. if (iter != state.end()) {
  14337. opdef.border_type = serialization<decltype(opdef.border_type)>::load(iter->second);
  14338. }
  14339. }
  14340. {
  14341. auto&& iter = state.find("format");
  14342. if (iter != state.end()) {
  14343. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  14344. }
  14345. }
  14346. {
  14347. auto&& iter = state.find("scalar");
  14348. if (iter != state.end()) {
  14349. opdef.scalar = serialization<decltype(opdef.scalar)>::load(iter->second);
  14350. }
  14351. }
  14352. Py_RETURN_NONE;
  14353. }
  14354. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14355. // };
  14356. PyOpDefEnd(Remap)
  14357. int PyOp(Remap)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14358. static const char* kwlist[] = {"imode", "border_type", "format", "scalar", "scope", NULL};
  14359. PyObject *imode = NULL, *border_type = NULL, *format = NULL, *scalar = NULL, *scope = NULL;
  14360. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &border_type, &format, &scalar, &scope))
  14361. return -1;
  14362. if (imode) {
  14363. try {
  14364. // TODO: remove this guard which is used for pybind11 implicit conversion
  14365. py::detail::loader_life_support guard{};
  14366. reinterpret_cast<PyOp(Remap)*>(self)->inst().imode =
  14367. py::cast<decltype(Remap::imode)>(py::handle(imode));
  14368. } CATCH_ALL(-1)
  14369. }
  14370. if (border_type) {
  14371. try {
  14372. // TODO: remove this guard which is used for pybind11 implicit conversion
  14373. py::detail::loader_life_support guard{};
  14374. reinterpret_cast<PyOp(Remap)*>(self)->inst().border_type =
  14375. py::cast<decltype(Remap::border_type)>(py::handle(border_type));
  14376. } CATCH_ALL(-1)
  14377. }
  14378. if (format) {
  14379. try {
  14380. // TODO: remove this guard which is used for pybind11 implicit conversion
  14381. py::detail::loader_life_support guard{};
  14382. reinterpret_cast<PyOp(Remap)*>(self)->inst().format =
  14383. py::cast<decltype(Remap::format)>(py::handle(format));
  14384. } CATCH_ALL(-1)
  14385. }
  14386. if (scalar) {
  14387. try {
  14388. // TODO: remove this guard which is used for pybind11 implicit conversion
  14389. py::detail::loader_life_support guard{};
  14390. reinterpret_cast<PyOp(Remap)*>(self)->inst().scalar =
  14391. py::cast<decltype(Remap::scalar)>(py::handle(scalar));
  14392. } CATCH_ALL(-1)
  14393. }
  14394. if (scope) {
  14395. try {
  14396. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14397. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14398. } CATCH_ALL(-1)
  14399. }
  14400. return 0;
  14401. }
  14402. PyGetSetDef PyOp(Remap)::py_getsetters[] = {
  14403. {const_cast<char*>("imode"), py_get_generic(Remap, imode), py_set_generic(Remap, imode), const_cast<char*>("imode"), NULL},
  14404. {const_cast<char*>("border_type"), py_get_generic(Remap, border_type), py_set_generic(Remap, border_type), const_cast<char*>("border_type"), NULL},
  14405. {const_cast<char*>("format"), py_get_generic(Remap, format), py_set_generic(Remap, format), const_cast<char*>("format"), NULL},
  14406. {const_cast<char*>("scalar"), py_get_generic(Remap, scalar), py_set_generic(Remap, scalar), const_cast<char*>("scalar"), NULL},
  14407. {NULL} /* Sentinel */
  14408. };
  14409. PyMethodDef PyOp(Remap)::tp_methods[] = {
  14410. {const_cast<char*>("__getstate__"), PyOp(Remap)::getstate, METH_NOARGS, "Remap getstate"},
  14411. {const_cast<char*>("__setstate__"), PyOp(Remap)::setstate, METH_VARARGS, "Remap setstate"},
  14412. {NULL} /* Sentinel */
  14413. };
  14414. void _init_py_Remap(py::module m) {
  14415. using py_op = PyOp(Remap);
  14416. auto& py_type = PyOpType(Remap);
  14417. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14418. py_type.tp_name = "megengine.core._imperative_rt.ops.Remap";
  14419. py_type.tp_basicsize = sizeof(PyOp(Remap));
  14420. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14421. py_type.tp_doc = "Remap";
  14422. py_type.tp_base = &PyOpType(OpDef);
  14423. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14424. py_type.tp_new = py_new_generic<py_op>;
  14425. py_type.tp_init = py_op::py_init;
  14426. py_type.tp_methods = py_op::tp_methods;
  14427. py_type.tp_getset = py_op::py_getsetters;
  14428. mgb_assert(PyType_Ready(&py_type) >= 0);
  14429. _init_py_Remap_InterpolationMode(py_type);
  14430. _init_py_Remap_BorderMode(py_type);
  14431. _init_py_Remap_Format(py_type);
  14432. PyType_Modified(&py_type);
  14433. m.add_object("Remap", reinterpret_cast<PyObject*>(&py_type));
  14434. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Remap::typeinfo(), &py_type).second);
  14435. }
  14436. PyOpDefBegin(RemoteRecv) // {
  14437. static PyGetSetDef py_getsetters[];
  14438. static PyMethodDef tp_methods[];
  14439. static PyObject* getstate(PyObject* self, PyObject*) {
  14440. auto& opdef = reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst();
  14441. static_cast<void>(opdef);
  14442. std::unordered_map<std::string, py::object> state {
  14443. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  14444. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  14445. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  14446. {"rank_from", serialization<decltype(opdef.rank_from)>::dump(opdef.rank_from)},
  14447. {"cn", serialization<decltype(opdef.cn)>::dump(opdef.cn)},
  14448. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)},
  14449. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  14450. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)}
  14451. };
  14452. return py::cast(state).release().ptr();
  14453. }
  14454. static PyObject* setstate(PyObject* self, PyObject* args) {
  14455. PyObject* dict = PyTuple_GetItem(args, 0);
  14456. if (!dict) return NULL;
  14457. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14458. auto& opdef = reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst();
  14459. static_cast<void>(opdef);
  14460. {
  14461. auto&& iter = state.find("key");
  14462. if (iter != state.end()) {
  14463. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  14464. }
  14465. }
  14466. {
  14467. auto&& iter = state.find("addr");
  14468. if (iter != state.end()) {
  14469. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  14470. }
  14471. }
  14472. {
  14473. auto&& iter = state.find("port");
  14474. if (iter != state.end()) {
  14475. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  14476. }
  14477. }
  14478. {
  14479. auto&& iter = state.find("rank_from");
  14480. if (iter != state.end()) {
  14481. opdef.rank_from = serialization<decltype(opdef.rank_from)>::load(iter->second);
  14482. }
  14483. }
  14484. {
  14485. auto&& iter = state.find("cn");
  14486. if (iter != state.end()) {
  14487. opdef.cn = serialization<decltype(opdef.cn)>::load(iter->second);
  14488. }
  14489. }
  14490. {
  14491. auto&& iter = state.find("shape");
  14492. if (iter != state.end()) {
  14493. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  14494. }
  14495. }
  14496. {
  14497. auto&& iter = state.find("dtype");
  14498. if (iter != state.end()) {
  14499. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  14500. }
  14501. }
  14502. {
  14503. auto&& iter = state.find("backend");
  14504. if (iter != state.end()) {
  14505. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  14506. }
  14507. }
  14508. Py_RETURN_NONE;
  14509. }
  14510. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14511. // };
  14512. PyOpDefEnd(RemoteRecv)
  14513. int PyOp(RemoteRecv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14514. static const char* kwlist[] = {"key", "addr", "port", "rank_from", "cn", "shape", "dtype", "backend", "scope", NULL};
  14515. PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_from = NULL, *cn = NULL, *shape = NULL, *dtype = NULL, *backend = NULL, *scope = NULL;
  14516. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast<char**>(kwlist), &key, &addr, &port, &rank_from, &cn, &shape, &dtype, &backend, &scope))
  14517. return -1;
  14518. if (key) {
  14519. try {
  14520. // TODO: remove this guard which is used for pybind11 implicit conversion
  14521. py::detail::loader_life_support guard{};
  14522. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().key =
  14523. py::cast<decltype(RemoteRecv::key)>(py::handle(key));
  14524. } CATCH_ALL(-1)
  14525. }
  14526. if (addr) {
  14527. try {
  14528. // TODO: remove this guard which is used for pybind11 implicit conversion
  14529. py::detail::loader_life_support guard{};
  14530. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().addr =
  14531. py::cast<decltype(RemoteRecv::addr)>(py::handle(addr));
  14532. } CATCH_ALL(-1)
  14533. }
  14534. if (port) {
  14535. try {
  14536. // TODO: remove this guard which is used for pybind11 implicit conversion
  14537. py::detail::loader_life_support guard{};
  14538. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().port =
  14539. py::cast<decltype(RemoteRecv::port)>(py::handle(port));
  14540. } CATCH_ALL(-1)
  14541. }
  14542. if (rank_from) {
  14543. try {
  14544. // TODO: remove this guard which is used for pybind11 implicit conversion
  14545. py::detail::loader_life_support guard{};
  14546. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().rank_from =
  14547. py::cast<decltype(RemoteRecv::rank_from)>(py::handle(rank_from));
  14548. } CATCH_ALL(-1)
  14549. }
  14550. if (cn) {
  14551. try {
  14552. // TODO: remove this guard which is used for pybind11 implicit conversion
  14553. py::detail::loader_life_support guard{};
  14554. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().cn =
  14555. py::cast<decltype(RemoteRecv::cn)>(py::handle(cn));
  14556. } CATCH_ALL(-1)
  14557. }
  14558. if (shape) {
  14559. try {
  14560. // TODO: remove this guard which is used for pybind11 implicit conversion
  14561. py::detail::loader_life_support guard{};
  14562. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().shape =
  14563. py::cast<decltype(RemoteRecv::shape)>(py::handle(shape));
  14564. } CATCH_ALL(-1)
  14565. }
  14566. if (dtype) {
  14567. try {
  14568. // TODO: remove this guard which is used for pybind11 implicit conversion
  14569. py::detail::loader_life_support guard{};
  14570. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().dtype =
  14571. py::cast<decltype(RemoteRecv::dtype)>(py::handle(dtype));
  14572. } CATCH_ALL(-1)
  14573. }
  14574. if (backend) {
  14575. try {
  14576. // TODO: remove this guard which is used for pybind11 implicit conversion
  14577. py::detail::loader_life_support guard{};
  14578. reinterpret_cast<PyOp(RemoteRecv)*>(self)->inst().backend =
  14579. py::cast<decltype(RemoteRecv::backend)>(py::handle(backend));
  14580. } CATCH_ALL(-1)
  14581. }
  14582. if (scope) {
  14583. try {
  14584. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14585. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14586. } CATCH_ALL(-1)
  14587. }
  14588. return 0;
  14589. }
  14590. PyGetSetDef PyOp(RemoteRecv)::py_getsetters[] = {
  14591. {const_cast<char*>("key"), py_get_generic(RemoteRecv, key), py_set_generic(RemoteRecv, key), const_cast<char*>("key"), NULL},
  14592. {const_cast<char*>("addr"), py_get_generic(RemoteRecv, addr), py_set_generic(RemoteRecv, addr), const_cast<char*>("addr"), NULL},
  14593. {const_cast<char*>("port"), py_get_generic(RemoteRecv, port), py_set_generic(RemoteRecv, port), const_cast<char*>("port"), NULL},
  14594. {const_cast<char*>("rank_from"), py_get_generic(RemoteRecv, rank_from), py_set_generic(RemoteRecv, rank_from), const_cast<char*>("rank_from"), NULL},
  14595. {const_cast<char*>("cn"), py_get_generic(RemoteRecv, cn), py_set_generic(RemoteRecv, cn), const_cast<char*>("cn"), NULL},
  14596. {const_cast<char*>("shape"), py_get_generic(RemoteRecv, shape), py_set_generic(RemoteRecv, shape), const_cast<char*>("shape"), NULL},
  14597. {const_cast<char*>("dtype"), py_get_generic(RemoteRecv, dtype), py_set_generic(RemoteRecv, dtype), const_cast<char*>("dtype"), NULL},
  14598. {const_cast<char*>("backend"), py_get_generic(RemoteRecv, backend), py_set_generic(RemoteRecv, backend), const_cast<char*>("backend"), NULL},
  14599. {NULL} /* Sentinel */
  14600. };
  14601. PyMethodDef PyOp(RemoteRecv)::tp_methods[] = {
  14602. {const_cast<char*>("__getstate__"), PyOp(RemoteRecv)::getstate, METH_NOARGS, "RemoteRecv getstate"},
  14603. {const_cast<char*>("__setstate__"), PyOp(RemoteRecv)::setstate, METH_VARARGS, "RemoteRecv setstate"},
  14604. {NULL} /* Sentinel */
  14605. };
  14606. void _init_py_RemoteRecv(py::module m) {
  14607. using py_op = PyOp(RemoteRecv);
  14608. auto& py_type = PyOpType(RemoteRecv);
  14609. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14610. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteRecv";
  14611. py_type.tp_basicsize = sizeof(PyOp(RemoteRecv));
  14612. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14613. py_type.tp_doc = "RemoteRecv";
  14614. py_type.tp_base = &PyOpType(OpDef);
  14615. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14616. py_type.tp_new = py_new_generic<py_op>;
  14617. py_type.tp_init = py_op::py_init;
  14618. py_type.tp_methods = py_op::tp_methods;
  14619. py_type.tp_getset = py_op::py_getsetters;
  14620. mgb_assert(PyType_Ready(&py_type) >= 0);
  14621. PyType_Modified(&py_type);
  14622. m.add_object("RemoteRecv", reinterpret_cast<PyObject*>(&py_type));
  14623. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteRecv::typeinfo(), &py_type).second);
  14624. }
  14625. PyOpDefBegin(RemoteSend) // {
  14626. static PyGetSetDef py_getsetters[];
  14627. static PyMethodDef tp_methods[];
  14628. static PyObject* getstate(PyObject* self, PyObject*) {
  14629. auto& opdef = reinterpret_cast<PyOp(RemoteSend)*>(self)->inst();
  14630. static_cast<void>(opdef);
  14631. std::unordered_map<std::string, py::object> state {
  14632. {"key", serialization<decltype(opdef.key)>::dump(opdef.key)},
  14633. {"addr", serialization<decltype(opdef.addr)>::dump(opdef.addr)},
  14634. {"port", serialization<decltype(opdef.port)>::dump(opdef.port)},
  14635. {"rank_to", serialization<decltype(opdef.rank_to)>::dump(opdef.rank_to)},
  14636. {"backend", serialization<decltype(opdef.backend)>::dump(opdef.backend)}
  14637. };
  14638. return py::cast(state).release().ptr();
  14639. }
  14640. static PyObject* setstate(PyObject* self, PyObject* args) {
  14641. PyObject* dict = PyTuple_GetItem(args, 0);
  14642. if (!dict) return NULL;
  14643. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14644. auto& opdef = reinterpret_cast<PyOp(RemoteSend)*>(self)->inst();
  14645. static_cast<void>(opdef);
  14646. {
  14647. auto&& iter = state.find("key");
  14648. if (iter != state.end()) {
  14649. opdef.key = serialization<decltype(opdef.key)>::load(iter->second);
  14650. }
  14651. }
  14652. {
  14653. auto&& iter = state.find("addr");
  14654. if (iter != state.end()) {
  14655. opdef.addr = serialization<decltype(opdef.addr)>::load(iter->second);
  14656. }
  14657. }
  14658. {
  14659. auto&& iter = state.find("port");
  14660. if (iter != state.end()) {
  14661. opdef.port = serialization<decltype(opdef.port)>::load(iter->second);
  14662. }
  14663. }
  14664. {
  14665. auto&& iter = state.find("rank_to");
  14666. if (iter != state.end()) {
  14667. opdef.rank_to = serialization<decltype(opdef.rank_to)>::load(iter->second);
  14668. }
  14669. }
  14670. {
  14671. auto&& iter = state.find("backend");
  14672. if (iter != state.end()) {
  14673. opdef.backend = serialization<decltype(opdef.backend)>::load(iter->second);
  14674. }
  14675. }
  14676. Py_RETURN_NONE;
  14677. }
  14678. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14679. // };
  14680. PyOpDefEnd(RemoteSend)
  14681. int PyOp(RemoteSend)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14682. static const char* kwlist[] = {"key", "addr", "port", "rank_to", "backend", "scope", NULL};
  14683. PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_to = NULL, *backend = NULL, *scope = NULL;
  14684. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast<char**>(kwlist), &key, &addr, &port, &rank_to, &backend, &scope))
  14685. return -1;
  14686. if (key) {
  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(RemoteSend)*>(self)->inst().key =
  14691. py::cast<decltype(RemoteSend::key)>(py::handle(key));
  14692. } CATCH_ALL(-1)
  14693. }
  14694. if (addr) {
  14695. try {
  14696. // TODO: remove this guard which is used for pybind11 implicit conversion
  14697. py::detail::loader_life_support guard{};
  14698. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().addr =
  14699. py::cast<decltype(RemoteSend::addr)>(py::handle(addr));
  14700. } CATCH_ALL(-1)
  14701. }
  14702. if (port) {
  14703. try {
  14704. // TODO: remove this guard which is used for pybind11 implicit conversion
  14705. py::detail::loader_life_support guard{};
  14706. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().port =
  14707. py::cast<decltype(RemoteSend::port)>(py::handle(port));
  14708. } CATCH_ALL(-1)
  14709. }
  14710. if (rank_to) {
  14711. try {
  14712. // TODO: remove this guard which is used for pybind11 implicit conversion
  14713. py::detail::loader_life_support guard{};
  14714. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().rank_to =
  14715. py::cast<decltype(RemoteSend::rank_to)>(py::handle(rank_to));
  14716. } CATCH_ALL(-1)
  14717. }
  14718. if (backend) {
  14719. try {
  14720. // TODO: remove this guard which is used for pybind11 implicit conversion
  14721. py::detail::loader_life_support guard{};
  14722. reinterpret_cast<PyOp(RemoteSend)*>(self)->inst().backend =
  14723. py::cast<decltype(RemoteSend::backend)>(py::handle(backend));
  14724. } CATCH_ALL(-1)
  14725. }
  14726. if (scope) {
  14727. try {
  14728. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14729. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14730. } CATCH_ALL(-1)
  14731. }
  14732. return 0;
  14733. }
  14734. PyGetSetDef PyOp(RemoteSend)::py_getsetters[] = {
  14735. {const_cast<char*>("key"), py_get_generic(RemoteSend, key), py_set_generic(RemoteSend, key), const_cast<char*>("key"), NULL},
  14736. {const_cast<char*>("addr"), py_get_generic(RemoteSend, addr), py_set_generic(RemoteSend, addr), const_cast<char*>("addr"), NULL},
  14737. {const_cast<char*>("port"), py_get_generic(RemoteSend, port), py_set_generic(RemoteSend, port), const_cast<char*>("port"), NULL},
  14738. {const_cast<char*>("rank_to"), py_get_generic(RemoteSend, rank_to), py_set_generic(RemoteSend, rank_to), const_cast<char*>("rank_to"), NULL},
  14739. {const_cast<char*>("backend"), py_get_generic(RemoteSend, backend), py_set_generic(RemoteSend, backend), const_cast<char*>("backend"), NULL},
  14740. {NULL} /* Sentinel */
  14741. };
  14742. PyMethodDef PyOp(RemoteSend)::tp_methods[] = {
  14743. {const_cast<char*>("__getstate__"), PyOp(RemoteSend)::getstate, METH_NOARGS, "RemoteSend getstate"},
  14744. {const_cast<char*>("__setstate__"), PyOp(RemoteSend)::setstate, METH_VARARGS, "RemoteSend setstate"},
  14745. {NULL} /* Sentinel */
  14746. };
  14747. void _init_py_RemoteSend(py::module m) {
  14748. using py_op = PyOp(RemoteSend);
  14749. auto& py_type = PyOpType(RemoteSend);
  14750. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14751. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteSend";
  14752. py_type.tp_basicsize = sizeof(PyOp(RemoteSend));
  14753. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14754. py_type.tp_doc = "RemoteSend";
  14755. py_type.tp_base = &PyOpType(OpDef);
  14756. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14757. py_type.tp_new = py_new_generic<py_op>;
  14758. py_type.tp_init = py_op::py_init;
  14759. py_type.tp_methods = py_op::tp_methods;
  14760. py_type.tp_getset = py_op::py_getsetters;
  14761. mgb_assert(PyType_Ready(&py_type) >= 0);
  14762. PyType_Modified(&py_type);
  14763. m.add_object("RemoteSend", reinterpret_cast<PyObject*>(&py_type));
  14764. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteSend::typeinfo(), &py_type).second);
  14765. }
  14766. PyOpDefBegin(RemoveAxis) // {
  14767. static PyGetSetDef py_getsetters[];
  14768. static PyMethodDef tp_methods[];
  14769. static PyObject* getstate(PyObject* self, PyObject*) {
  14770. auto& opdef = reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst();
  14771. static_cast<void>(opdef);
  14772. std::unordered_map<std::string, py::object> state {
  14773. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  14774. };
  14775. return py::cast(state).release().ptr();
  14776. }
  14777. static PyObject* setstate(PyObject* self, PyObject* args) {
  14778. PyObject* dict = PyTuple_GetItem(args, 0);
  14779. if (!dict) return NULL;
  14780. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14781. auto& opdef = reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst();
  14782. static_cast<void>(opdef);
  14783. {
  14784. auto&& iter = state.find("axis");
  14785. if (iter != state.end()) {
  14786. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  14787. }
  14788. }
  14789. Py_RETURN_NONE;
  14790. }
  14791. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14792. // };
  14793. PyOpDefEnd(RemoveAxis)
  14794. int PyOp(RemoveAxis)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14795. static const char* kwlist[] = {"axis", "scope", NULL};
  14796. PyObject *axis = NULL, *scope = NULL;
  14797. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  14798. return -1;
  14799. if (axis) {
  14800. try {
  14801. // TODO: remove this guard which is used for pybind11 implicit conversion
  14802. py::detail::loader_life_support guard{};
  14803. reinterpret_cast<PyOp(RemoveAxis)*>(self)->inst().axis =
  14804. py::cast<decltype(RemoveAxis::axis)>(py::handle(axis));
  14805. } CATCH_ALL(-1)
  14806. }
  14807. if (scope) {
  14808. try {
  14809. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14810. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14811. } CATCH_ALL(-1)
  14812. }
  14813. return 0;
  14814. }
  14815. PyGetSetDef PyOp(RemoveAxis)::py_getsetters[] = {
  14816. {const_cast<char*>("axis"), py_get_generic(RemoveAxis, axis), py_set_generic(RemoveAxis, axis), const_cast<char*>("axis"), NULL},
  14817. {NULL} /* Sentinel */
  14818. };
  14819. PyMethodDef PyOp(RemoveAxis)::tp_methods[] = {
  14820. {const_cast<char*>("__getstate__"), PyOp(RemoveAxis)::getstate, METH_NOARGS, "RemoveAxis getstate"},
  14821. {const_cast<char*>("__setstate__"), PyOp(RemoveAxis)::setstate, METH_VARARGS, "RemoveAxis setstate"},
  14822. {NULL} /* Sentinel */
  14823. };
  14824. void _init_py_RemoveAxis(py::module m) {
  14825. using py_op = PyOp(RemoveAxis);
  14826. auto& py_type = PyOpType(RemoveAxis);
  14827. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14828. py_type.tp_name = "megengine.core._imperative_rt.ops.RemoveAxis";
  14829. py_type.tp_basicsize = sizeof(PyOp(RemoveAxis));
  14830. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14831. py_type.tp_doc = "RemoveAxis";
  14832. py_type.tp_base = &PyOpType(OpDef);
  14833. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14834. py_type.tp_new = py_new_generic<py_op>;
  14835. py_type.tp_init = py_op::py_init;
  14836. py_type.tp_methods = py_op::tp_methods;
  14837. py_type.tp_getset = py_op::py_getsetters;
  14838. mgb_assert(PyType_Ready(&py_type) >= 0);
  14839. PyType_Modified(&py_type);
  14840. m.add_object("RemoveAxis", reinterpret_cast<PyObject*>(&py_type));
  14841. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoveAxis::typeinfo(), &py_type).second);
  14842. }
  14843. PyOpDefBegin(Reshape) // {
  14844. static PyGetSetDef py_getsetters[];
  14845. static PyMethodDef tp_methods[];
  14846. static PyObject* getstate(PyObject* self, PyObject*) {
  14847. auto& opdef = reinterpret_cast<PyOp(Reshape)*>(self)->inst();
  14848. static_cast<void>(opdef);
  14849. std::unordered_map<std::string, py::object> state {
  14850. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  14851. {"shape", serialization<decltype(opdef.shape)>::dump(opdef.shape)}
  14852. };
  14853. return py::cast(state).release().ptr();
  14854. }
  14855. static PyObject* setstate(PyObject* self, PyObject* args) {
  14856. PyObject* dict = PyTuple_GetItem(args, 0);
  14857. if (!dict) return NULL;
  14858. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14859. auto& opdef = reinterpret_cast<PyOp(Reshape)*>(self)->inst();
  14860. static_cast<void>(opdef);
  14861. {
  14862. auto&& iter = state.find("axis");
  14863. if (iter != state.end()) {
  14864. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  14865. }
  14866. }
  14867. {
  14868. auto&& iter = state.find("shape");
  14869. if (iter != state.end()) {
  14870. opdef.shape = serialization<decltype(opdef.shape)>::load(iter->second);
  14871. }
  14872. }
  14873. Py_RETURN_NONE;
  14874. }
  14875. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14876. // };
  14877. PyOpDefEnd(Reshape)
  14878. int PyOp(Reshape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14879. static const char* kwlist[] = {"axis", "shape", "scope", NULL};
  14880. PyObject *axis = NULL, *shape = NULL, *scope = NULL;
  14881. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &shape, &scope))
  14882. return -1;
  14883. if (axis) {
  14884. try {
  14885. // TODO: remove this guard which is used for pybind11 implicit conversion
  14886. py::detail::loader_life_support guard{};
  14887. reinterpret_cast<PyOp(Reshape)*>(self)->inst().axis =
  14888. py::cast<decltype(Reshape::axis)>(py::handle(axis));
  14889. } CATCH_ALL(-1)
  14890. }
  14891. if (shape) {
  14892. try {
  14893. // TODO: remove this guard which is used for pybind11 implicit conversion
  14894. py::detail::loader_life_support guard{};
  14895. reinterpret_cast<PyOp(Reshape)*>(self)->inst().shape =
  14896. py::cast<decltype(Reshape::shape)>(py::handle(shape));
  14897. } CATCH_ALL(-1)
  14898. }
  14899. if (scope) {
  14900. try {
  14901. reinterpret_cast<PyOp(OpDef)*>(self)->op
  14902. ->set_scope(py::cast<std::string>(py::handle(scope)));
  14903. } CATCH_ALL(-1)
  14904. }
  14905. return 0;
  14906. }
  14907. PyGetSetDef PyOp(Reshape)::py_getsetters[] = {
  14908. {const_cast<char*>("axis"), py_get_generic(Reshape, axis), py_set_generic(Reshape, axis), const_cast<char*>("axis"), NULL},
  14909. {const_cast<char*>("shape"), py_get_generic(Reshape, shape), py_set_generic(Reshape, shape), const_cast<char*>("shape"), NULL},
  14910. {NULL} /* Sentinel */
  14911. };
  14912. PyMethodDef PyOp(Reshape)::tp_methods[] = {
  14913. {const_cast<char*>("__getstate__"), PyOp(Reshape)::getstate, METH_NOARGS, "Reshape getstate"},
  14914. {const_cast<char*>("__setstate__"), PyOp(Reshape)::setstate, METH_VARARGS, "Reshape setstate"},
  14915. {NULL} /* Sentinel */
  14916. };
  14917. void _init_py_Reshape(py::module m) {
  14918. using py_op = PyOp(Reshape);
  14919. auto& py_type = PyOpType(Reshape);
  14920. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  14921. py_type.tp_name = "megengine.core._imperative_rt.ops.Reshape";
  14922. py_type.tp_basicsize = sizeof(PyOp(Reshape));
  14923. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  14924. py_type.tp_doc = "Reshape";
  14925. py_type.tp_base = &PyOpType(OpDef);
  14926. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  14927. py_type.tp_new = py_new_generic<py_op>;
  14928. py_type.tp_init = py_op::py_init;
  14929. py_type.tp_methods = py_op::tp_methods;
  14930. py_type.tp_getset = py_op::py_getsetters;
  14931. mgb_assert(PyType_Ready(&py_type) >= 0);
  14932. PyType_Modified(&py_type);
  14933. m.add_object("Reshape", reinterpret_cast<PyObject*>(&py_type));
  14934. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reshape::typeinfo(), &py_type).second);
  14935. }
  14936. void _init_py_Resize_InterpolationMode(PyTypeObject& py_type) {
  14937. auto& e_type = EnumWrapper<Resize::InterpolationMode>::type;
  14938. Py_INCREF(e_type);
  14939. mgb_assert(PyDict_SetItemString(
  14940. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14941. }
  14942. void _init_py_Resize_Format(PyTypeObject& py_type) {
  14943. auto& e_type = EnumWrapper<Resize::Format>::type;
  14944. Py_INCREF(e_type);
  14945. mgb_assert(PyDict_SetItemString(
  14946. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  14947. }
  14948. PyOpDefBegin(Resize) // {
  14949. static PyGetSetDef py_getsetters[];
  14950. static PyMethodDef tp_methods[];
  14951. static PyObject* getstate(PyObject* self, PyObject*) {
  14952. auto& opdef = reinterpret_cast<PyOp(Resize)*>(self)->inst();
  14953. static_cast<void>(opdef);
  14954. std::unordered_map<std::string, py::object> state {
  14955. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  14956. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  14957. };
  14958. return py::cast(state).release().ptr();
  14959. }
  14960. static PyObject* setstate(PyObject* self, PyObject* args) {
  14961. PyObject* dict = PyTuple_GetItem(args, 0);
  14962. if (!dict) return NULL;
  14963. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  14964. auto& opdef = reinterpret_cast<PyOp(Resize)*>(self)->inst();
  14965. static_cast<void>(opdef);
  14966. {
  14967. auto&& iter = state.find("imode");
  14968. if (iter != state.end()) {
  14969. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  14970. }
  14971. }
  14972. {
  14973. auto&& iter = state.find("format");
  14974. if (iter != state.end()) {
  14975. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  14976. }
  14977. }
  14978. Py_RETURN_NONE;
  14979. }
  14980. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  14981. // };
  14982. PyOpDefEnd(Resize)
  14983. int PyOp(Resize)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  14984. static const char* kwlist[] = {"imode", "format", "scope", NULL};
  14985. PyObject *imode = NULL, *format = NULL, *scope = NULL;
  14986. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &imode, &format, &scope))
  14987. return -1;
  14988. if (imode) {
  14989. try {
  14990. // TODO: remove this guard which is used for pybind11 implicit conversion
  14991. py::detail::loader_life_support guard{};
  14992. reinterpret_cast<PyOp(Resize)*>(self)->inst().imode =
  14993. py::cast<decltype(Resize::imode)>(py::handle(imode));
  14994. } CATCH_ALL(-1)
  14995. }
  14996. if (format) {
  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(Resize)*>(self)->inst().format =
  15001. py::cast<decltype(Resize::format)>(py::handle(format));
  15002. } CATCH_ALL(-1)
  15003. }
  15004. if (scope) {
  15005. try {
  15006. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15007. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15008. } CATCH_ALL(-1)
  15009. }
  15010. return 0;
  15011. }
  15012. PyGetSetDef PyOp(Resize)::py_getsetters[] = {
  15013. {const_cast<char*>("imode"), py_get_generic(Resize, imode), py_set_generic(Resize, imode), const_cast<char*>("imode"), NULL},
  15014. {const_cast<char*>("format"), py_get_generic(Resize, format), py_set_generic(Resize, format), const_cast<char*>("format"), NULL},
  15015. {NULL} /* Sentinel */
  15016. };
  15017. PyMethodDef PyOp(Resize)::tp_methods[] = {
  15018. {const_cast<char*>("__getstate__"), PyOp(Resize)::getstate, METH_NOARGS, "Resize getstate"},
  15019. {const_cast<char*>("__setstate__"), PyOp(Resize)::setstate, METH_VARARGS, "Resize setstate"},
  15020. {NULL} /* Sentinel */
  15021. };
  15022. void _init_py_Resize(py::module m) {
  15023. using py_op = PyOp(Resize);
  15024. auto& py_type = PyOpType(Resize);
  15025. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15026. py_type.tp_name = "megengine.core._imperative_rt.ops.Resize";
  15027. py_type.tp_basicsize = sizeof(PyOp(Resize));
  15028. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15029. py_type.tp_doc = "Resize";
  15030. py_type.tp_base = &PyOpType(OpDef);
  15031. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15032. py_type.tp_new = py_new_generic<py_op>;
  15033. py_type.tp_init = py_op::py_init;
  15034. py_type.tp_methods = py_op::tp_methods;
  15035. py_type.tp_getset = py_op::py_getsetters;
  15036. mgb_assert(PyType_Ready(&py_type) >= 0);
  15037. _init_py_Resize_InterpolationMode(py_type);
  15038. _init_py_Resize_Format(py_type);
  15039. PyType_Modified(&py_type);
  15040. m.add_object("Resize", reinterpret_cast<PyObject*>(&py_type));
  15041. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Resize::typeinfo(), &py_type).second);
  15042. }
  15043. PyOpDefBegin(SVD) // {
  15044. static PyGetSetDef py_getsetters[];
  15045. static PyMethodDef tp_methods[];
  15046. static PyObject* getstate(PyObject* self, PyObject*) {
  15047. auto& opdef = reinterpret_cast<PyOp(SVD)*>(self)->inst();
  15048. static_cast<void>(opdef);
  15049. std::unordered_map<std::string, py::object> state {
  15050. {"full_matrices", serialization<decltype(opdef.full_matrices)>::dump(opdef.full_matrices)},
  15051. {"compute_uv", serialization<decltype(opdef.compute_uv)>::dump(opdef.compute_uv)}
  15052. };
  15053. return py::cast(state).release().ptr();
  15054. }
  15055. static PyObject* setstate(PyObject* self, PyObject* args) {
  15056. PyObject* dict = PyTuple_GetItem(args, 0);
  15057. if (!dict) return NULL;
  15058. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15059. auto& opdef = reinterpret_cast<PyOp(SVD)*>(self)->inst();
  15060. static_cast<void>(opdef);
  15061. {
  15062. auto&& iter = state.find("full_matrices");
  15063. if (iter != state.end()) {
  15064. opdef.full_matrices = serialization<decltype(opdef.full_matrices)>::load(iter->second);
  15065. }
  15066. }
  15067. {
  15068. auto&& iter = state.find("compute_uv");
  15069. if (iter != state.end()) {
  15070. opdef.compute_uv = serialization<decltype(opdef.compute_uv)>::load(iter->second);
  15071. }
  15072. }
  15073. Py_RETURN_NONE;
  15074. }
  15075. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15076. // };
  15077. PyOpDefEnd(SVD)
  15078. int PyOp(SVD)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15079. static const char* kwlist[] = {"full_matrices", "compute_uv", "scope", NULL};
  15080. PyObject *full_matrices = NULL, *compute_uv = NULL, *scope = NULL;
  15081. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &full_matrices, &compute_uv, &scope))
  15082. return -1;
  15083. if (full_matrices) {
  15084. try {
  15085. // TODO: remove this guard which is used for pybind11 implicit conversion
  15086. py::detail::loader_life_support guard{};
  15087. reinterpret_cast<PyOp(SVD)*>(self)->inst().full_matrices =
  15088. py::cast<decltype(SVD::full_matrices)>(py::handle(full_matrices));
  15089. } CATCH_ALL(-1)
  15090. }
  15091. if (compute_uv) {
  15092. try {
  15093. // TODO: remove this guard which is used for pybind11 implicit conversion
  15094. py::detail::loader_life_support guard{};
  15095. reinterpret_cast<PyOp(SVD)*>(self)->inst().compute_uv =
  15096. py::cast<decltype(SVD::compute_uv)>(py::handle(compute_uv));
  15097. } CATCH_ALL(-1)
  15098. }
  15099. if (scope) {
  15100. try {
  15101. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15102. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15103. } CATCH_ALL(-1)
  15104. }
  15105. return 0;
  15106. }
  15107. PyGetSetDef PyOp(SVD)::py_getsetters[] = {
  15108. {const_cast<char*>("full_matrices"), py_get_generic(SVD, full_matrices), py_set_generic(SVD, full_matrices), const_cast<char*>("full_matrices"), NULL},
  15109. {const_cast<char*>("compute_uv"), py_get_generic(SVD, compute_uv), py_set_generic(SVD, compute_uv), const_cast<char*>("compute_uv"), NULL},
  15110. {NULL} /* Sentinel */
  15111. };
  15112. PyMethodDef PyOp(SVD)::tp_methods[] = {
  15113. {const_cast<char*>("__getstate__"), PyOp(SVD)::getstate, METH_NOARGS, "SVD getstate"},
  15114. {const_cast<char*>("__setstate__"), PyOp(SVD)::setstate, METH_VARARGS, "SVD setstate"},
  15115. {NULL} /* Sentinel */
  15116. };
  15117. void _init_py_SVD(py::module m) {
  15118. using py_op = PyOp(SVD);
  15119. auto& py_type = PyOpType(SVD);
  15120. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15121. py_type.tp_name = "megengine.core._imperative_rt.ops.SVD";
  15122. py_type.tp_basicsize = sizeof(PyOp(SVD));
  15123. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15124. py_type.tp_doc = "SVD";
  15125. py_type.tp_base = &PyOpType(OpDef);
  15126. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15127. py_type.tp_new = py_new_generic<py_op>;
  15128. py_type.tp_init = py_op::py_init;
  15129. py_type.tp_methods = py_op::tp_methods;
  15130. py_type.tp_getset = py_op::py_getsetters;
  15131. mgb_assert(PyType_Ready(&py_type) >= 0);
  15132. PyType_Modified(&py_type);
  15133. m.add_object("SVD", reinterpret_cast<PyObject*>(&py_type));
  15134. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SVD::typeinfo(), &py_type).second);
  15135. }
  15136. PyOpDefBegin(SetMeshIndexing) // {
  15137. static PyGetSetDef py_getsetters[];
  15138. static PyMethodDef tp_methods[];
  15139. static PyObject* getstate(PyObject* self, PyObject*) {
  15140. auto& opdef = reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst();
  15141. static_cast<void>(opdef);
  15142. std::unordered_map<std::string, py::object> state {
  15143. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  15144. };
  15145. return py::cast(state).release().ptr();
  15146. }
  15147. static PyObject* setstate(PyObject* self, PyObject* args) {
  15148. PyObject* dict = PyTuple_GetItem(args, 0);
  15149. if (!dict) return NULL;
  15150. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15151. auto& opdef = reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst();
  15152. static_cast<void>(opdef);
  15153. {
  15154. auto&& iter = state.find("items");
  15155. if (iter != state.end()) {
  15156. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  15157. }
  15158. }
  15159. Py_RETURN_NONE;
  15160. }
  15161. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15162. // };
  15163. PyOpDefEnd(SetMeshIndexing)
  15164. int PyOp(SetMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15165. static const char* kwlist[] = {"items", "scope", NULL};
  15166. PyObject *items = NULL, *scope = NULL;
  15167. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  15168. return -1;
  15169. if (items) {
  15170. try {
  15171. // TODO: remove this guard which is used for pybind11 implicit conversion
  15172. py::detail::loader_life_support guard{};
  15173. reinterpret_cast<PyOp(SetMeshIndexing)*>(self)->inst().items =
  15174. py::cast<decltype(SetMeshIndexing::items)>(py::handle(items));
  15175. } CATCH_ALL(-1)
  15176. }
  15177. if (scope) {
  15178. try {
  15179. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15180. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15181. } CATCH_ALL(-1)
  15182. }
  15183. return 0;
  15184. }
  15185. PyGetSetDef PyOp(SetMeshIndexing)::py_getsetters[] = {
  15186. {const_cast<char*>("items"), py_get_generic(SetMeshIndexing, items), py_set_generic(SetMeshIndexing, items), const_cast<char*>("items"), NULL},
  15187. {NULL} /* Sentinel */
  15188. };
  15189. PyMethodDef PyOp(SetMeshIndexing)::tp_methods[] = {
  15190. {const_cast<char*>("__getstate__"), PyOp(SetMeshIndexing)::getstate, METH_NOARGS, "SetMeshIndexing getstate"},
  15191. {const_cast<char*>("__setstate__"), PyOp(SetMeshIndexing)::setstate, METH_VARARGS, "SetMeshIndexing setstate"},
  15192. {NULL} /* Sentinel */
  15193. };
  15194. void _init_py_SetMeshIndexing(py::module m) {
  15195. using py_op = PyOp(SetMeshIndexing);
  15196. auto& py_type = PyOpType(SetMeshIndexing);
  15197. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15198. py_type.tp_name = "megengine.core._imperative_rt.ops.SetMeshIndexing";
  15199. py_type.tp_basicsize = sizeof(PyOp(SetMeshIndexing));
  15200. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15201. py_type.tp_doc = "SetMeshIndexing";
  15202. py_type.tp_base = &PyOpType(OpDef);
  15203. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15204. py_type.tp_new = py_new_generic<py_op>;
  15205. py_type.tp_init = py_op::py_init;
  15206. py_type.tp_methods = py_op::tp_methods;
  15207. py_type.tp_getset = py_op::py_getsetters;
  15208. mgb_assert(PyType_Ready(&py_type) >= 0);
  15209. PyType_Modified(&py_type);
  15210. m.add_object("SetMeshIndexing", reinterpret_cast<PyObject*>(&py_type));
  15211. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetMeshIndexing::typeinfo(), &py_type).second);
  15212. }
  15213. PyOpDefBegin(SetSubtensor) // {
  15214. static PyGetSetDef py_getsetters[];
  15215. static PyMethodDef tp_methods[];
  15216. static PyObject* getstate(PyObject* self, PyObject*) {
  15217. auto& opdef = reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst();
  15218. static_cast<void>(opdef);
  15219. std::unordered_map<std::string, py::object> state {
  15220. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  15221. };
  15222. return py::cast(state).release().ptr();
  15223. }
  15224. static PyObject* setstate(PyObject* self, PyObject* args) {
  15225. PyObject* dict = PyTuple_GetItem(args, 0);
  15226. if (!dict) return NULL;
  15227. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15228. auto& opdef = reinterpret_cast<PyOp(SetSubtensor)*>(self)->inst();
  15229. static_cast<void>(opdef);
  15230. {
  15231. auto&& iter = state.find("items");
  15232. if (iter != state.end()) {
  15233. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  15234. }
  15235. }
  15236. Py_RETURN_NONE;
  15237. }
  15238. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15239. // };
  15240. PyOpDefEnd(SetSubtensor)
  15241. int PyOp(SetSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15242. static const char* kwlist[] = {"items", "scope", NULL};
  15243. PyObject *items = NULL, *scope = NULL;
  15244. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  15245. return -1;
  15246. if (items) {
  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(SetSubtensor)*>(self)->inst().items =
  15251. py::cast<decltype(SetSubtensor::items)>(py::handle(items));
  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(SetSubtensor)::py_getsetters[] = {
  15263. {const_cast<char*>("items"), py_get_generic(SetSubtensor, items), py_set_generic(SetSubtensor, items), const_cast<char*>("items"), NULL},
  15264. {NULL} /* Sentinel */
  15265. };
  15266. PyMethodDef PyOp(SetSubtensor)::tp_methods[] = {
  15267. {const_cast<char*>("__getstate__"), PyOp(SetSubtensor)::getstate, METH_NOARGS, "SetSubtensor getstate"},
  15268. {const_cast<char*>("__setstate__"), PyOp(SetSubtensor)::setstate, METH_VARARGS, "SetSubtensor setstate"},
  15269. {NULL} /* Sentinel */
  15270. };
  15271. void _init_py_SetSubtensor(py::module m) {
  15272. using py_op = PyOp(SetSubtensor);
  15273. auto& py_type = PyOpType(SetSubtensor);
  15274. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15275. py_type.tp_name = "megengine.core._imperative_rt.ops.SetSubtensor";
  15276. py_type.tp_basicsize = sizeof(PyOp(SetSubtensor));
  15277. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15278. py_type.tp_doc = "SetSubtensor";
  15279. py_type.tp_base = &PyOpType(OpDef);
  15280. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15281. py_type.tp_new = py_new_generic<py_op>;
  15282. py_type.tp_init = py_op::py_init;
  15283. py_type.tp_methods = py_op::tp_methods;
  15284. py_type.tp_getset = py_op::py_getsetters;
  15285. mgb_assert(PyType_Ready(&py_type) >= 0);
  15286. PyType_Modified(&py_type);
  15287. m.add_object("SetSubtensor", reinterpret_cast<PyObject*>(&py_type));
  15288. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetSubtensor::typeinfo(), &py_type).second);
  15289. }
  15290. PyOpDefBegin(ShuffleRNG) // {
  15291. static PyGetSetDef py_getsetters[];
  15292. static PyMethodDef tp_methods[];
  15293. static PyObject* getstate(PyObject* self, PyObject*) {
  15294. auto& opdef = reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst();
  15295. static_cast<void>(opdef);
  15296. std::unordered_map<std::string, py::object> state {
  15297. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  15298. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  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(ShuffleRNG)*>(self)->inst();
  15307. static_cast<void>(opdef);
  15308. {
  15309. auto&& iter = state.find("seed");
  15310. if (iter != state.end()) {
  15311. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  15312. }
  15313. }
  15314. {
  15315. auto&& iter = state.find("handle");
  15316. if (iter != state.end()) {
  15317. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  15318. }
  15319. }
  15320. Py_RETURN_NONE;
  15321. }
  15322. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15323. // };
  15324. PyOpDefEnd(ShuffleRNG)
  15325. int PyOp(ShuffleRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15326. static const char* kwlist[] = {"seed", "handle", "scope", NULL};
  15327. PyObject *seed = NULL, *handle = NULL, *scope = NULL;
  15328. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &seed, &handle, &scope))
  15329. return -1;
  15330. if (seed) {
  15331. try {
  15332. // TODO: remove this guard which is used for pybind11 implicit conversion
  15333. py::detail::loader_life_support guard{};
  15334. reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst().seed =
  15335. py::cast<decltype(ShuffleRNG::seed)>(py::handle(seed));
  15336. } CATCH_ALL(-1)
  15337. }
  15338. if (handle) {
  15339. try {
  15340. // TODO: remove this guard which is used for pybind11 implicit conversion
  15341. py::detail::loader_life_support guard{};
  15342. reinterpret_cast<PyOp(ShuffleRNG)*>(self)->inst().handle =
  15343. py::cast<decltype(ShuffleRNG::handle)>(py::handle(handle));
  15344. } CATCH_ALL(-1)
  15345. }
  15346. if (scope) {
  15347. try {
  15348. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15349. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15350. } CATCH_ALL(-1)
  15351. }
  15352. return 0;
  15353. }
  15354. PyGetSetDef PyOp(ShuffleRNG)::py_getsetters[] = {
  15355. {const_cast<char*>("seed"), py_get_generic(ShuffleRNG, seed), py_set_generic(ShuffleRNG, seed), const_cast<char*>("seed"), NULL},
  15356. {const_cast<char*>("handle"), py_get_generic(ShuffleRNG, handle), py_set_generic(ShuffleRNG, handle), const_cast<char*>("handle"), NULL},
  15357. {NULL} /* Sentinel */
  15358. };
  15359. PyMethodDef PyOp(ShuffleRNG)::tp_methods[] = {
  15360. {const_cast<char*>("__getstate__"), PyOp(ShuffleRNG)::getstate, METH_NOARGS, "ShuffleRNG getstate"},
  15361. {const_cast<char*>("__setstate__"), PyOp(ShuffleRNG)::setstate, METH_VARARGS, "ShuffleRNG setstate"},
  15362. {NULL} /* Sentinel */
  15363. };
  15364. void _init_py_ShuffleRNG(py::module m) {
  15365. using py_op = PyOp(ShuffleRNG);
  15366. auto& py_type = PyOpType(ShuffleRNG);
  15367. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15368. py_type.tp_name = "megengine.core._imperative_rt.ops.ShuffleRNG";
  15369. py_type.tp_basicsize = sizeof(PyOp(ShuffleRNG));
  15370. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15371. py_type.tp_doc = "ShuffleRNG";
  15372. py_type.tp_base = &PyOpType(OpDef);
  15373. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15374. py_type.tp_new = py_new_generic<py_op>;
  15375. py_type.tp_init = py_op::py_init;
  15376. py_type.tp_methods = py_op::tp_methods;
  15377. py_type.tp_getset = py_op::py_getsetters;
  15378. mgb_assert(PyType_Ready(&py_type) >= 0);
  15379. PyType_Modified(&py_type);
  15380. m.add_object("ShuffleRNG", reinterpret_cast<PyObject*>(&py_type));
  15381. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ShuffleRNG::typeinfo(), &py_type).second);
  15382. }
  15383. PyOpDefBegin(SlidingWindowTranspose) // {
  15384. static PyGetSetDef py_getsetters[];
  15385. static PyMethodDef tp_methods[];
  15386. static PyObject* getstate(PyObject* self, PyObject*) {
  15387. auto& opdef = reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst();
  15388. static_cast<void>(opdef);
  15389. std::unordered_map<std::string, py::object> state {
  15390. {"out_h", serialization<decltype(opdef.out_h)>::dump(opdef.out_h)},
  15391. {"out_w", serialization<decltype(opdef.out_w)>::dump(opdef.out_w)},
  15392. {"pad_h", serialization<decltype(opdef.pad_h)>::dump(opdef.pad_h)},
  15393. {"pad_w", serialization<decltype(opdef.pad_w)>::dump(opdef.pad_w)},
  15394. {"stride_h", serialization<decltype(opdef.stride_h)>::dump(opdef.stride_h)},
  15395. {"stride_w", serialization<decltype(opdef.stride_w)>::dump(opdef.stride_w)},
  15396. {"dilate_h", serialization<decltype(opdef.dilate_h)>::dump(opdef.dilate_h)},
  15397. {"dilate_w", serialization<decltype(opdef.dilate_w)>::dump(opdef.dilate_w)},
  15398. {"window_h", serialization<decltype(opdef.window_h)>::dump(opdef.window_h)},
  15399. {"window_w", serialization<decltype(opdef.window_w)>::dump(opdef.window_w)}
  15400. };
  15401. return py::cast(state).release().ptr();
  15402. }
  15403. static PyObject* setstate(PyObject* self, PyObject* args) {
  15404. PyObject* dict = PyTuple_GetItem(args, 0);
  15405. if (!dict) return NULL;
  15406. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15407. auto& opdef = reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst();
  15408. static_cast<void>(opdef);
  15409. {
  15410. auto&& iter = state.find("out_h");
  15411. if (iter != state.end()) {
  15412. opdef.out_h = serialization<decltype(opdef.out_h)>::load(iter->second);
  15413. }
  15414. }
  15415. {
  15416. auto&& iter = state.find("out_w");
  15417. if (iter != state.end()) {
  15418. opdef.out_w = serialization<decltype(opdef.out_w)>::load(iter->second);
  15419. }
  15420. }
  15421. {
  15422. auto&& iter = state.find("pad_h");
  15423. if (iter != state.end()) {
  15424. opdef.pad_h = serialization<decltype(opdef.pad_h)>::load(iter->second);
  15425. }
  15426. }
  15427. {
  15428. auto&& iter = state.find("pad_w");
  15429. if (iter != state.end()) {
  15430. opdef.pad_w = serialization<decltype(opdef.pad_w)>::load(iter->second);
  15431. }
  15432. }
  15433. {
  15434. auto&& iter = state.find("stride_h");
  15435. if (iter != state.end()) {
  15436. opdef.stride_h = serialization<decltype(opdef.stride_h)>::load(iter->second);
  15437. }
  15438. }
  15439. {
  15440. auto&& iter = state.find("stride_w");
  15441. if (iter != state.end()) {
  15442. opdef.stride_w = serialization<decltype(opdef.stride_w)>::load(iter->second);
  15443. }
  15444. }
  15445. {
  15446. auto&& iter = state.find("dilate_h");
  15447. if (iter != state.end()) {
  15448. opdef.dilate_h = serialization<decltype(opdef.dilate_h)>::load(iter->second);
  15449. }
  15450. }
  15451. {
  15452. auto&& iter = state.find("dilate_w");
  15453. if (iter != state.end()) {
  15454. opdef.dilate_w = serialization<decltype(opdef.dilate_w)>::load(iter->second);
  15455. }
  15456. }
  15457. {
  15458. auto&& iter = state.find("window_h");
  15459. if (iter != state.end()) {
  15460. opdef.window_h = serialization<decltype(opdef.window_h)>::load(iter->second);
  15461. }
  15462. }
  15463. {
  15464. auto&& iter = state.find("window_w");
  15465. if (iter != state.end()) {
  15466. opdef.window_w = serialization<decltype(opdef.window_w)>::load(iter->second);
  15467. }
  15468. }
  15469. Py_RETURN_NONE;
  15470. }
  15471. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15472. // };
  15473. PyOpDefEnd(SlidingWindowTranspose)
  15474. int PyOp(SlidingWindowTranspose)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15475. 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};
  15476. 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;
  15477. 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))
  15478. return -1;
  15479. if (out_h) {
  15480. try {
  15481. // TODO: remove this guard which is used for pybind11 implicit conversion
  15482. py::detail::loader_life_support guard{};
  15483. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().out_h =
  15484. py::cast<decltype(SlidingWindowTranspose::out_h)>(py::handle(out_h));
  15485. } CATCH_ALL(-1)
  15486. }
  15487. if (out_w) {
  15488. try {
  15489. // TODO: remove this guard which is used for pybind11 implicit conversion
  15490. py::detail::loader_life_support guard{};
  15491. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().out_w =
  15492. py::cast<decltype(SlidingWindowTranspose::out_w)>(py::handle(out_w));
  15493. } CATCH_ALL(-1)
  15494. }
  15495. if (pad_h) {
  15496. try {
  15497. // TODO: remove this guard which is used for pybind11 implicit conversion
  15498. py::detail::loader_life_support guard{};
  15499. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().pad_h =
  15500. py::cast<decltype(SlidingWindowTranspose::pad_h)>(py::handle(pad_h));
  15501. } CATCH_ALL(-1)
  15502. }
  15503. if (pad_w) {
  15504. try {
  15505. // TODO: remove this guard which is used for pybind11 implicit conversion
  15506. py::detail::loader_life_support guard{};
  15507. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().pad_w =
  15508. py::cast<decltype(SlidingWindowTranspose::pad_w)>(py::handle(pad_w));
  15509. } CATCH_ALL(-1)
  15510. }
  15511. if (stride_h) {
  15512. try {
  15513. // TODO: remove this guard which is used for pybind11 implicit conversion
  15514. py::detail::loader_life_support guard{};
  15515. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().stride_h =
  15516. py::cast<decltype(SlidingWindowTranspose::stride_h)>(py::handle(stride_h));
  15517. } CATCH_ALL(-1)
  15518. }
  15519. if (stride_w) {
  15520. try {
  15521. // TODO: remove this guard which is used for pybind11 implicit conversion
  15522. py::detail::loader_life_support guard{};
  15523. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().stride_w =
  15524. py::cast<decltype(SlidingWindowTranspose::stride_w)>(py::handle(stride_w));
  15525. } CATCH_ALL(-1)
  15526. }
  15527. if (dilate_h) {
  15528. try {
  15529. // TODO: remove this guard which is used for pybind11 implicit conversion
  15530. py::detail::loader_life_support guard{};
  15531. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().dilate_h =
  15532. py::cast<decltype(SlidingWindowTranspose::dilate_h)>(py::handle(dilate_h));
  15533. } CATCH_ALL(-1)
  15534. }
  15535. if (dilate_w) {
  15536. try {
  15537. // TODO: remove this guard which is used for pybind11 implicit conversion
  15538. py::detail::loader_life_support guard{};
  15539. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().dilate_w =
  15540. py::cast<decltype(SlidingWindowTranspose::dilate_w)>(py::handle(dilate_w));
  15541. } CATCH_ALL(-1)
  15542. }
  15543. if (window_h) {
  15544. try {
  15545. // TODO: remove this guard which is used for pybind11 implicit conversion
  15546. py::detail::loader_life_support guard{};
  15547. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().window_h =
  15548. py::cast<decltype(SlidingWindowTranspose::window_h)>(py::handle(window_h));
  15549. } CATCH_ALL(-1)
  15550. }
  15551. if (window_w) {
  15552. try {
  15553. // TODO: remove this guard which is used for pybind11 implicit conversion
  15554. py::detail::loader_life_support guard{};
  15555. reinterpret_cast<PyOp(SlidingWindowTranspose)*>(self)->inst().window_w =
  15556. py::cast<decltype(SlidingWindowTranspose::window_w)>(py::handle(window_w));
  15557. } CATCH_ALL(-1)
  15558. }
  15559. if (scope) {
  15560. try {
  15561. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15562. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15563. } CATCH_ALL(-1)
  15564. }
  15565. return 0;
  15566. }
  15567. PyGetSetDef PyOp(SlidingWindowTranspose)::py_getsetters[] = {
  15568. {const_cast<char*>("out_h"), py_get_generic(SlidingWindowTranspose, out_h), py_set_generic(SlidingWindowTranspose, out_h), const_cast<char*>("out_h"), NULL},
  15569. {const_cast<char*>("out_w"), py_get_generic(SlidingWindowTranspose, out_w), py_set_generic(SlidingWindowTranspose, out_w), const_cast<char*>("out_w"), NULL},
  15570. {const_cast<char*>("pad_h"), py_get_generic(SlidingWindowTranspose, pad_h), py_set_generic(SlidingWindowTranspose, pad_h), const_cast<char*>("pad_h"), NULL},
  15571. {const_cast<char*>("pad_w"), py_get_generic(SlidingWindowTranspose, pad_w), py_set_generic(SlidingWindowTranspose, pad_w), const_cast<char*>("pad_w"), NULL},
  15572. {const_cast<char*>("stride_h"), py_get_generic(SlidingWindowTranspose, stride_h), py_set_generic(SlidingWindowTranspose, stride_h), const_cast<char*>("stride_h"), NULL},
  15573. {const_cast<char*>("stride_w"), py_get_generic(SlidingWindowTranspose, stride_w), py_set_generic(SlidingWindowTranspose, stride_w), const_cast<char*>("stride_w"), NULL},
  15574. {const_cast<char*>("dilate_h"), py_get_generic(SlidingWindowTranspose, dilate_h), py_set_generic(SlidingWindowTranspose, dilate_h), const_cast<char*>("dilate_h"), NULL},
  15575. {const_cast<char*>("dilate_w"), py_get_generic(SlidingWindowTranspose, dilate_w), py_set_generic(SlidingWindowTranspose, dilate_w), const_cast<char*>("dilate_w"), NULL},
  15576. {const_cast<char*>("window_h"), py_get_generic(SlidingWindowTranspose, window_h), py_set_generic(SlidingWindowTranspose, window_h), const_cast<char*>("window_h"), NULL},
  15577. {const_cast<char*>("window_w"), py_get_generic(SlidingWindowTranspose, window_w), py_set_generic(SlidingWindowTranspose, window_w), const_cast<char*>("window_w"), NULL},
  15578. {NULL} /* Sentinel */
  15579. };
  15580. PyMethodDef PyOp(SlidingWindowTranspose)::tp_methods[] = {
  15581. {const_cast<char*>("__getstate__"), PyOp(SlidingWindowTranspose)::getstate, METH_NOARGS, "SlidingWindowTranspose getstate"},
  15582. {const_cast<char*>("__setstate__"), PyOp(SlidingWindowTranspose)::setstate, METH_VARARGS, "SlidingWindowTranspose setstate"},
  15583. {NULL} /* Sentinel */
  15584. };
  15585. void _init_py_SlidingWindowTranspose(py::module m) {
  15586. using py_op = PyOp(SlidingWindowTranspose);
  15587. auto& py_type = PyOpType(SlidingWindowTranspose);
  15588. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15589. py_type.tp_name = "megengine.core._imperative_rt.ops.SlidingWindowTranspose";
  15590. py_type.tp_basicsize = sizeof(PyOp(SlidingWindowTranspose));
  15591. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15592. py_type.tp_doc = "SlidingWindowTranspose";
  15593. py_type.tp_base = &PyOpType(OpDef);
  15594. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15595. py_type.tp_new = py_new_generic<py_op>;
  15596. py_type.tp_init = py_op::py_init;
  15597. py_type.tp_methods = py_op::tp_methods;
  15598. py_type.tp_getset = py_op::py_getsetters;
  15599. mgb_assert(PyType_Ready(&py_type) >= 0);
  15600. PyType_Modified(&py_type);
  15601. m.add_object("SlidingWindowTranspose", reinterpret_cast<PyObject*>(&py_type));
  15602. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SlidingWindowTranspose::typeinfo(), &py_type).second);
  15603. }
  15604. PyOpDefBegin(Softmax) // {
  15605. static PyGetSetDef py_getsetters[];
  15606. static PyMethodDef tp_methods[];
  15607. static PyObject* getstate(PyObject* self, PyObject*) {
  15608. auto& opdef = reinterpret_cast<PyOp(Softmax)*>(self)->inst();
  15609. static_cast<void>(opdef);
  15610. std::unordered_map<std::string, py::object> state {
  15611. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)}
  15612. };
  15613. return py::cast(state).release().ptr();
  15614. }
  15615. static PyObject* setstate(PyObject* self, PyObject* args) {
  15616. PyObject* dict = PyTuple_GetItem(args, 0);
  15617. if (!dict) return NULL;
  15618. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15619. auto& opdef = reinterpret_cast<PyOp(Softmax)*>(self)->inst();
  15620. static_cast<void>(opdef);
  15621. {
  15622. auto&& iter = state.find("axis");
  15623. if (iter != state.end()) {
  15624. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  15625. }
  15626. }
  15627. Py_RETURN_NONE;
  15628. }
  15629. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15630. // };
  15631. PyOpDefEnd(Softmax)
  15632. int PyOp(Softmax)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15633. static const char* kwlist[] = {"axis", "scope", NULL};
  15634. PyObject *axis = NULL, *scope = NULL;
  15635. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &axis, &scope))
  15636. return -1;
  15637. if (axis) {
  15638. try {
  15639. // TODO: remove this guard which is used for pybind11 implicit conversion
  15640. py::detail::loader_life_support guard{};
  15641. reinterpret_cast<PyOp(Softmax)*>(self)->inst().axis =
  15642. py::cast<decltype(Softmax::axis)>(py::handle(axis));
  15643. } CATCH_ALL(-1)
  15644. }
  15645. if (scope) {
  15646. try {
  15647. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15648. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15649. } CATCH_ALL(-1)
  15650. }
  15651. return 0;
  15652. }
  15653. PyGetSetDef PyOp(Softmax)::py_getsetters[] = {
  15654. {const_cast<char*>("axis"), py_get_generic(Softmax, axis), py_set_generic(Softmax, axis), const_cast<char*>("axis"), NULL},
  15655. {NULL} /* Sentinel */
  15656. };
  15657. PyMethodDef PyOp(Softmax)::tp_methods[] = {
  15658. {const_cast<char*>("__getstate__"), PyOp(Softmax)::getstate, METH_NOARGS, "Softmax getstate"},
  15659. {const_cast<char*>("__setstate__"), PyOp(Softmax)::setstate, METH_VARARGS, "Softmax setstate"},
  15660. {NULL} /* Sentinel */
  15661. };
  15662. void _init_py_Softmax(py::module m) {
  15663. using py_op = PyOp(Softmax);
  15664. auto& py_type = PyOpType(Softmax);
  15665. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15666. py_type.tp_name = "megengine.core._imperative_rt.ops.Softmax";
  15667. py_type.tp_basicsize = sizeof(PyOp(Softmax));
  15668. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15669. py_type.tp_doc = "Softmax";
  15670. py_type.tp_base = &PyOpType(OpDef);
  15671. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15672. py_type.tp_new = py_new_generic<py_op>;
  15673. py_type.tp_init = py_op::py_init;
  15674. py_type.tp_methods = py_op::tp_methods;
  15675. py_type.tp_getset = py_op::py_getsetters;
  15676. mgb_assert(PyType_Ready(&py_type) >= 0);
  15677. PyType_Modified(&py_type);
  15678. m.add_object("Softmax", reinterpret_cast<PyObject*>(&py_type));
  15679. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Softmax::typeinfo(), &py_type).second);
  15680. }
  15681. PyOpDefBegin(Split) // {
  15682. static PyGetSetDef py_getsetters[];
  15683. static PyMethodDef tp_methods[];
  15684. static PyObject* getstate(PyObject* self, PyObject*) {
  15685. auto& opdef = reinterpret_cast<PyOp(Split)*>(self)->inst();
  15686. static_cast<void>(opdef);
  15687. std::unordered_map<std::string, py::object> state {
  15688. {"axis", serialization<decltype(opdef.axis)>::dump(opdef.axis)},
  15689. {"nsections", serialization<decltype(opdef.nsections)>::dump(opdef.nsections)}
  15690. };
  15691. return py::cast(state).release().ptr();
  15692. }
  15693. static PyObject* setstate(PyObject* self, PyObject* args) {
  15694. PyObject* dict = PyTuple_GetItem(args, 0);
  15695. if (!dict) return NULL;
  15696. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15697. auto& opdef = reinterpret_cast<PyOp(Split)*>(self)->inst();
  15698. static_cast<void>(opdef);
  15699. {
  15700. auto&& iter = state.find("axis");
  15701. if (iter != state.end()) {
  15702. opdef.axis = serialization<decltype(opdef.axis)>::load(iter->second);
  15703. }
  15704. }
  15705. {
  15706. auto&& iter = state.find("nsections");
  15707. if (iter != state.end()) {
  15708. opdef.nsections = serialization<decltype(opdef.nsections)>::load(iter->second);
  15709. }
  15710. }
  15711. Py_RETURN_NONE;
  15712. }
  15713. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15714. // };
  15715. PyOpDefEnd(Split)
  15716. int PyOp(Split)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15717. static const char* kwlist[] = {"axis", "nsections", "scope", NULL};
  15718. PyObject *axis = NULL, *nsections = NULL, *scope = NULL;
  15719. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &axis, &nsections, &scope))
  15720. return -1;
  15721. if (axis) {
  15722. try {
  15723. // TODO: remove this guard which is used for pybind11 implicit conversion
  15724. py::detail::loader_life_support guard{};
  15725. reinterpret_cast<PyOp(Split)*>(self)->inst().axis =
  15726. py::cast<decltype(Split::axis)>(py::handle(axis));
  15727. } CATCH_ALL(-1)
  15728. }
  15729. if (nsections) {
  15730. try {
  15731. // TODO: remove this guard which is used for pybind11 implicit conversion
  15732. py::detail::loader_life_support guard{};
  15733. reinterpret_cast<PyOp(Split)*>(self)->inst().nsections =
  15734. py::cast<decltype(Split::nsections)>(py::handle(nsections));
  15735. } CATCH_ALL(-1)
  15736. }
  15737. if (scope) {
  15738. try {
  15739. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15740. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15741. } CATCH_ALL(-1)
  15742. }
  15743. return 0;
  15744. }
  15745. PyGetSetDef PyOp(Split)::py_getsetters[] = {
  15746. {const_cast<char*>("axis"), py_get_generic(Split, axis), py_set_generic(Split, axis), const_cast<char*>("axis"), NULL},
  15747. {const_cast<char*>("nsections"), py_get_generic(Split, nsections), py_set_generic(Split, nsections), const_cast<char*>("nsections"), NULL},
  15748. {NULL} /* Sentinel */
  15749. };
  15750. PyMethodDef PyOp(Split)::tp_methods[] = {
  15751. {const_cast<char*>("__getstate__"), PyOp(Split)::getstate, METH_NOARGS, "Split getstate"},
  15752. {const_cast<char*>("__setstate__"), PyOp(Split)::setstate, METH_VARARGS, "Split setstate"},
  15753. {NULL} /* Sentinel */
  15754. };
  15755. void _init_py_Split(py::module m) {
  15756. using py_op = PyOp(Split);
  15757. auto& py_type = PyOpType(Split);
  15758. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15759. py_type.tp_name = "megengine.core._imperative_rt.ops.Split";
  15760. py_type.tp_basicsize = sizeof(PyOp(Split));
  15761. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15762. py_type.tp_doc = "Split";
  15763. py_type.tp_base = &PyOpType(OpDef);
  15764. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15765. py_type.tp_new = py_new_generic<py_op>;
  15766. py_type.tp_init = py_op::py_init;
  15767. py_type.tp_methods = py_op::tp_methods;
  15768. py_type.tp_getset = py_op::py_getsetters;
  15769. mgb_assert(PyType_Ready(&py_type) >= 0);
  15770. PyType_Modified(&py_type);
  15771. m.add_object("Split", reinterpret_cast<PyObject*>(&py_type));
  15772. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Split::typeinfo(), &py_type).second);
  15773. }
  15774. PyOpDefBegin(Subtensor) // {
  15775. static PyGetSetDef py_getsetters[];
  15776. static PyMethodDef tp_methods[];
  15777. static PyObject* getstate(PyObject* self, PyObject*) {
  15778. auto& opdef = reinterpret_cast<PyOp(Subtensor)*>(self)->inst();
  15779. static_cast<void>(opdef);
  15780. std::unordered_map<std::string, py::object> state {
  15781. {"items", serialization<decltype(opdef.items)>::dump(opdef.items)}
  15782. };
  15783. return py::cast(state).release().ptr();
  15784. }
  15785. static PyObject* setstate(PyObject* self, PyObject* args) {
  15786. PyObject* dict = PyTuple_GetItem(args, 0);
  15787. if (!dict) return NULL;
  15788. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15789. auto& opdef = reinterpret_cast<PyOp(Subtensor)*>(self)->inst();
  15790. static_cast<void>(opdef);
  15791. {
  15792. auto&& iter = state.find("items");
  15793. if (iter != state.end()) {
  15794. opdef.items = serialization<decltype(opdef.items)>::load(iter->second);
  15795. }
  15796. }
  15797. Py_RETURN_NONE;
  15798. }
  15799. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15800. // };
  15801. PyOpDefEnd(Subtensor)
  15802. int PyOp(Subtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15803. static const char* kwlist[] = {"items", "scope", NULL};
  15804. PyObject *items = NULL, *scope = NULL;
  15805. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &items, &scope))
  15806. return -1;
  15807. if (items) {
  15808. try {
  15809. // TODO: remove this guard which is used for pybind11 implicit conversion
  15810. py::detail::loader_life_support guard{};
  15811. reinterpret_cast<PyOp(Subtensor)*>(self)->inst().items =
  15812. py::cast<decltype(Subtensor::items)>(py::handle(items));
  15813. } CATCH_ALL(-1)
  15814. }
  15815. if (scope) {
  15816. try {
  15817. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15818. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15819. } CATCH_ALL(-1)
  15820. }
  15821. return 0;
  15822. }
  15823. PyGetSetDef PyOp(Subtensor)::py_getsetters[] = {
  15824. {const_cast<char*>("items"), py_get_generic(Subtensor, items), py_set_generic(Subtensor, items), const_cast<char*>("items"), NULL},
  15825. {NULL} /* Sentinel */
  15826. };
  15827. PyMethodDef PyOp(Subtensor)::tp_methods[] = {
  15828. {const_cast<char*>("__getstate__"), PyOp(Subtensor)::getstate, METH_NOARGS, "Subtensor getstate"},
  15829. {const_cast<char*>("__setstate__"), PyOp(Subtensor)::setstate, METH_VARARGS, "Subtensor setstate"},
  15830. {NULL} /* Sentinel */
  15831. };
  15832. void _init_py_Subtensor(py::module m) {
  15833. using py_op = PyOp(Subtensor);
  15834. auto& py_type = PyOpType(Subtensor);
  15835. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15836. py_type.tp_name = "megengine.core._imperative_rt.ops.Subtensor";
  15837. py_type.tp_basicsize = sizeof(PyOp(Subtensor));
  15838. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15839. py_type.tp_doc = "Subtensor";
  15840. py_type.tp_base = &PyOpType(OpDef);
  15841. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15842. py_type.tp_new = py_new_generic<py_op>;
  15843. py_type.tp_init = py_op::py_init;
  15844. py_type.tp_methods = py_op::tp_methods;
  15845. py_type.tp_getset = py_op::py_getsetters;
  15846. mgb_assert(PyType_Ready(&py_type) >= 0);
  15847. PyType_Modified(&py_type);
  15848. m.add_object("Subtensor", reinterpret_cast<PyObject*>(&py_type));
  15849. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Subtensor::typeinfo(), &py_type).second);
  15850. }
  15851. PyOpDefBegin(TQT) // {
  15852. static PyGetSetDef py_getsetters[];
  15853. static PyMethodDef tp_methods[];
  15854. static PyObject* getstate(PyObject* self, PyObject*) {
  15855. auto& opdef = reinterpret_cast<PyOp(TQT)*>(self)->inst();
  15856. static_cast<void>(opdef);
  15857. std::unordered_map<std::string, py::object> state {
  15858. {"qmin", serialization<decltype(opdef.qmin)>::dump(opdef.qmin)},
  15859. {"qmax", serialization<decltype(opdef.qmax)>::dump(opdef.qmax)}
  15860. };
  15861. return py::cast(state).release().ptr();
  15862. }
  15863. static PyObject* setstate(PyObject* self, PyObject* args) {
  15864. PyObject* dict = PyTuple_GetItem(args, 0);
  15865. if (!dict) return NULL;
  15866. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15867. auto& opdef = reinterpret_cast<PyOp(TQT)*>(self)->inst();
  15868. static_cast<void>(opdef);
  15869. {
  15870. auto&& iter = state.find("qmin");
  15871. if (iter != state.end()) {
  15872. opdef.qmin = serialization<decltype(opdef.qmin)>::load(iter->second);
  15873. }
  15874. }
  15875. {
  15876. auto&& iter = state.find("qmax");
  15877. if (iter != state.end()) {
  15878. opdef.qmax = serialization<decltype(opdef.qmax)>::load(iter->second);
  15879. }
  15880. }
  15881. Py_RETURN_NONE;
  15882. }
  15883. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15884. // };
  15885. PyOpDefEnd(TQT)
  15886. int PyOp(TQT)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15887. static const char* kwlist[] = {"qmin", "qmax", "scope", NULL};
  15888. PyObject *qmin = NULL, *qmax = NULL, *scope = NULL;
  15889. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &qmin, &qmax, &scope))
  15890. return -1;
  15891. if (qmin) {
  15892. try {
  15893. // TODO: remove this guard which is used for pybind11 implicit conversion
  15894. py::detail::loader_life_support guard{};
  15895. reinterpret_cast<PyOp(TQT)*>(self)->inst().qmin =
  15896. py::cast<decltype(TQT::qmin)>(py::handle(qmin));
  15897. } CATCH_ALL(-1)
  15898. }
  15899. if (qmax) {
  15900. try {
  15901. // TODO: remove this guard which is used for pybind11 implicit conversion
  15902. py::detail::loader_life_support guard{};
  15903. reinterpret_cast<PyOp(TQT)*>(self)->inst().qmax =
  15904. py::cast<decltype(TQT::qmax)>(py::handle(qmax));
  15905. } CATCH_ALL(-1)
  15906. }
  15907. if (scope) {
  15908. try {
  15909. reinterpret_cast<PyOp(OpDef)*>(self)->op
  15910. ->set_scope(py::cast<std::string>(py::handle(scope)));
  15911. } CATCH_ALL(-1)
  15912. }
  15913. return 0;
  15914. }
  15915. PyGetSetDef PyOp(TQT)::py_getsetters[] = {
  15916. {const_cast<char*>("qmin"), py_get_generic(TQT, qmin), py_set_generic(TQT, qmin), const_cast<char*>("qmin"), NULL},
  15917. {const_cast<char*>("qmax"), py_get_generic(TQT, qmax), py_set_generic(TQT, qmax), const_cast<char*>("qmax"), NULL},
  15918. {NULL} /* Sentinel */
  15919. };
  15920. PyMethodDef PyOp(TQT)::tp_methods[] = {
  15921. {const_cast<char*>("__getstate__"), PyOp(TQT)::getstate, METH_NOARGS, "TQT getstate"},
  15922. {const_cast<char*>("__setstate__"), PyOp(TQT)::setstate, METH_VARARGS, "TQT setstate"},
  15923. {NULL} /* Sentinel */
  15924. };
  15925. void _init_py_TQT(py::module m) {
  15926. using py_op = PyOp(TQT);
  15927. auto& py_type = PyOpType(TQT);
  15928. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  15929. py_type.tp_name = "megengine.core._imperative_rt.ops.TQT";
  15930. py_type.tp_basicsize = sizeof(PyOp(TQT));
  15931. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  15932. py_type.tp_doc = "TQT";
  15933. py_type.tp_base = &PyOpType(OpDef);
  15934. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  15935. py_type.tp_new = py_new_generic<py_op>;
  15936. py_type.tp_init = py_op::py_init;
  15937. py_type.tp_methods = py_op::tp_methods;
  15938. py_type.tp_getset = py_op::py_getsetters;
  15939. mgb_assert(PyType_Ready(&py_type) >= 0);
  15940. PyType_Modified(&py_type);
  15941. m.add_object("TQT", reinterpret_cast<PyObject*>(&py_type));
  15942. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TQT::typeinfo(), &py_type).second);
  15943. }
  15944. PyOpDefBegin(TensorRTRuntime) // {
  15945. static PyGetSetDef py_getsetters[];
  15946. static PyMethodDef tp_methods[];
  15947. static PyObject* getstate(PyObject* self, PyObject*) {
  15948. auto& opdef = reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst();
  15949. static_cast<void>(opdef);
  15950. std::unordered_map<std::string, py::object> state {
  15951. {"buf", serialization<decltype(opdef.buf)>::dump(opdef.buf)},
  15952. {"buf_size", serialization<decltype(opdef.buf_size)>::dump(opdef.buf_size)}
  15953. };
  15954. return py::cast(state).release().ptr();
  15955. }
  15956. static PyObject* setstate(PyObject* self, PyObject* args) {
  15957. PyObject* dict = PyTuple_GetItem(args, 0);
  15958. if (!dict) return NULL;
  15959. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  15960. auto& opdef = reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst();
  15961. static_cast<void>(opdef);
  15962. {
  15963. auto&& iter = state.find("buf");
  15964. if (iter != state.end()) {
  15965. opdef.buf = serialization<decltype(opdef.buf)>::load(iter->second);
  15966. }
  15967. }
  15968. {
  15969. auto&& iter = state.find("buf_size");
  15970. if (iter != state.end()) {
  15971. opdef.buf_size = serialization<decltype(opdef.buf_size)>::load(iter->second);
  15972. }
  15973. }
  15974. Py_RETURN_NONE;
  15975. }
  15976. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  15977. // };
  15978. PyOpDefEnd(TensorRTRuntime)
  15979. int PyOp(TensorRTRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  15980. static const char* kwlist[] = {"buf", "buf_size", "scope", NULL};
  15981. PyObject *buf = NULL, *buf_size = NULL, *scope = NULL;
  15982. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast<char**>(kwlist), &buf, &buf_size, &scope))
  15983. return -1;
  15984. if (buf) {
  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(TensorRTRuntime)*>(self)->inst().buf =
  15989. py::cast<decltype(TensorRTRuntime::buf)>(py::handle(buf));
  15990. } CATCH_ALL(-1)
  15991. }
  15992. if (buf_size) {
  15993. try {
  15994. // TODO: remove this guard which is used for pybind11 implicit conversion
  15995. py::detail::loader_life_support guard{};
  15996. reinterpret_cast<PyOp(TensorRTRuntime)*>(self)->inst().buf_size =
  15997. py::cast<decltype(TensorRTRuntime::buf_size)>(py::handle(buf_size));
  15998. } CATCH_ALL(-1)
  15999. }
  16000. if (scope) {
  16001. try {
  16002. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16003. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16004. } CATCH_ALL(-1)
  16005. }
  16006. return 0;
  16007. }
  16008. PyGetSetDef PyOp(TensorRTRuntime)::py_getsetters[] = {
  16009. {const_cast<char*>("buf"), py_get_generic(TensorRTRuntime, buf), py_set_generic(TensorRTRuntime, buf), const_cast<char*>("buf"), NULL},
  16010. {const_cast<char*>("buf_size"), py_get_generic(TensorRTRuntime, buf_size), py_set_generic(TensorRTRuntime, buf_size), const_cast<char*>("buf_size"), NULL},
  16011. {NULL} /* Sentinel */
  16012. };
  16013. PyMethodDef PyOp(TensorRTRuntime)::tp_methods[] = {
  16014. {const_cast<char*>("__getstate__"), PyOp(TensorRTRuntime)::getstate, METH_NOARGS, "TensorRTRuntime getstate"},
  16015. {const_cast<char*>("__setstate__"), PyOp(TensorRTRuntime)::setstate, METH_VARARGS, "TensorRTRuntime setstate"},
  16016. {NULL} /* Sentinel */
  16017. };
  16018. void _init_py_TensorRTRuntime(py::module m) {
  16019. using py_op = PyOp(TensorRTRuntime);
  16020. auto& py_type = PyOpType(TensorRTRuntime);
  16021. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16022. py_type.tp_name = "megengine.core._imperative_rt.ops.TensorRTRuntime";
  16023. py_type.tp_basicsize = sizeof(PyOp(TensorRTRuntime));
  16024. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16025. py_type.tp_doc = "TensorRTRuntime";
  16026. py_type.tp_base = &PyOpType(OpDef);
  16027. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16028. py_type.tp_new = py_new_generic<py_op>;
  16029. py_type.tp_init = py_op::py_init;
  16030. py_type.tp_methods = py_op::tp_methods;
  16031. py_type.tp_getset = py_op::py_getsetters;
  16032. mgb_assert(PyType_Ready(&py_type) >= 0);
  16033. PyType_Modified(&py_type);
  16034. m.add_object("TensorRTRuntime", reinterpret_cast<PyObject*>(&py_type));
  16035. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TensorRTRuntime::typeinfo(), &py_type).second);
  16036. }
  16037. template<> struct EnumTrait<TopK::Mode> {
  16038. static constexpr const char *name = "TopK.Mode";
  16039. static constexpr std::underlying_type_t<TopK::Mode> max = 3 - 1;
  16040. };
  16041. template<> PyTypeObject* EnumWrapper<TopK::Mode>::type = nullptr;
  16042. template<> const char*
  16043. EnumWrapper<TopK::Mode>::members[] = {"KTH_ONLY", "VALUE_IDX_NOSORT", "VALUE_IDX_SORTED"};
  16044. template<> std::unordered_map<std::string, TopK::Mode>
  16045. 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}};
  16046. template<> PyObject* EnumWrapper<TopK::Mode>::pyobj_insts[3] = {nullptr};
  16047. void _init_py_TopK_Mode(PyTypeObject& py_type) {
  16048. auto& e_type = EnumWrapper<TopK::Mode>::type;
  16049. static PyMethodDef tp_methods[] = {
  16050. {const_cast<char*>("dump"), (PyCFunction)EnumWrapper<TopK::Mode>::py_dump, METH_NOARGS, NULL},
  16051. {NULL} /* Sentinel */
  16052. };
  16053. static PyType_Slot slots[] = {
  16054. {Py_tp_repr, (void*)EnumWrapper<TopK::Mode>::py_repr},
  16055. {Py_tp_richcompare, (void*)EnumWrapper<TopK::Mode>::tp_richcompare},
  16056. {Py_tp_methods, tp_methods},
  16057. {0, NULL}
  16058. };
  16059. static PyType_Spec spec = {
  16060. // name
  16061. "megengine.core._imperative_rt.ops.TopK.Mode",
  16062. // basicsize
  16063. sizeof(EnumWrapper<TopK::Mode>),
  16064. // itemsize
  16065. 0,
  16066. // flags
  16067. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
  16068. // slots
  16069. slots
  16070. };
  16071. e_type = reinterpret_cast<PyTypeObject*>(PyType_FromSpec(&spec));
  16072. mgb_assert(
  16073. e_type->tp_setattro(
  16074. reinterpret_cast<PyObject*>(e_type),
  16075. py::cast("__name__").release().ptr(),
  16076. py::cast("Mode").release().ptr()) >= 0);
  16077. mgb_assert(
  16078. e_type->tp_setattro(
  16079. reinterpret_cast<PyObject*>(e_type),
  16080. py::cast("__module__").release().ptr(),
  16081. py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0);
  16082. mgb_assert(
  16083. e_type->tp_setattro(
  16084. reinterpret_cast<PyObject*>(e_type),
  16085. py::cast("__qualname__").release().ptr(),
  16086. py::cast("TopK.Mode").release().ptr()) >= 0);
  16087. {
  16088. PyObject* inst = e_type->tp_alloc(e_type, 0);
  16089. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::KTH_ONLY;
  16090. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "KTH_ONLY", inst) >= 0);
  16091. EnumWrapper<TopK::Mode>::pyobj_insts[0] = inst;
  16092. }{
  16093. PyObject* inst = e_type->tp_alloc(e_type, 0);
  16094. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::VALUE_IDX_NOSORT;
  16095. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_NOSORT", inst) >= 0);
  16096. EnumWrapper<TopK::Mode>::pyobj_insts[1] = inst;
  16097. }{
  16098. PyObject* inst = e_type->tp_alloc(e_type, 0);
  16099. reinterpret_cast<EnumWrapper<TopK::Mode>*>(inst)->value = TopK::Mode::VALUE_IDX_SORTED;
  16100. mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_SORTED", inst) >= 0);
  16101. EnumWrapper<TopK::Mode>::pyobj_insts[2] = inst;
  16102. }
  16103. Py_INCREF(e_type);
  16104. mgb_assert(PyDict_SetItemString(
  16105. py_type.tp_dict, "Mode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16106. }
  16107. PyOpDefBegin(TopK) // {
  16108. static PyGetSetDef py_getsetters[];
  16109. static PyMethodDef tp_methods[];
  16110. static PyObject* getstate(PyObject* self, PyObject*) {
  16111. auto& opdef = reinterpret_cast<PyOp(TopK)*>(self)->inst();
  16112. static_cast<void>(opdef);
  16113. std::unordered_map<std::string, py::object> state {
  16114. {"mode", serialization<decltype(opdef.mode)>::dump(opdef.mode)}
  16115. };
  16116. return py::cast(state).release().ptr();
  16117. }
  16118. static PyObject* setstate(PyObject* self, PyObject* args) {
  16119. PyObject* dict = PyTuple_GetItem(args, 0);
  16120. if (!dict) return NULL;
  16121. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16122. auto& opdef = reinterpret_cast<PyOp(TopK)*>(self)->inst();
  16123. static_cast<void>(opdef);
  16124. {
  16125. auto&& iter = state.find("mode");
  16126. if (iter != state.end()) {
  16127. opdef.mode = serialization<decltype(opdef.mode)>::load(iter->second);
  16128. }
  16129. }
  16130. Py_RETURN_NONE;
  16131. }
  16132. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16133. // };
  16134. PyOpDefEnd(TopK)
  16135. int PyOp(TopK)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16136. static const char* kwlist[] = {"mode", "scope", NULL};
  16137. PyObject *mode = NULL, *scope = NULL;
  16138. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &mode, &scope))
  16139. return -1;
  16140. if (mode) {
  16141. try {
  16142. // TODO: remove this guard which is used for pybind11 implicit conversion
  16143. py::detail::loader_life_support guard{};
  16144. reinterpret_cast<PyOp(TopK)*>(self)->inst().mode =
  16145. py::cast<decltype(TopK::mode)>(py::handle(mode));
  16146. } CATCH_ALL(-1)
  16147. }
  16148. if (scope) {
  16149. try {
  16150. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16151. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16152. } CATCH_ALL(-1)
  16153. }
  16154. return 0;
  16155. }
  16156. PyGetSetDef PyOp(TopK)::py_getsetters[] = {
  16157. {const_cast<char*>("mode"), py_get_generic(TopK, mode), py_set_generic(TopK, mode), const_cast<char*>("mode"), NULL},
  16158. {NULL} /* Sentinel */
  16159. };
  16160. PyMethodDef PyOp(TopK)::tp_methods[] = {
  16161. {const_cast<char*>("__getstate__"), PyOp(TopK)::getstate, METH_NOARGS, "TopK getstate"},
  16162. {const_cast<char*>("__setstate__"), PyOp(TopK)::setstate, METH_VARARGS, "TopK setstate"},
  16163. {NULL} /* Sentinel */
  16164. };
  16165. void _init_py_TopK(py::module m) {
  16166. using py_op = PyOp(TopK);
  16167. auto& py_type = PyOpType(TopK);
  16168. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16169. py_type.tp_name = "megengine.core._imperative_rt.ops.TopK";
  16170. py_type.tp_basicsize = sizeof(PyOp(TopK));
  16171. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16172. py_type.tp_doc = "TopK";
  16173. py_type.tp_base = &PyOpType(OpDef);
  16174. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16175. py_type.tp_new = py_new_generic<py_op>;
  16176. py_type.tp_init = py_op::py_init;
  16177. py_type.tp_methods = py_op::tp_methods;
  16178. py_type.tp_getset = py_op::py_getsetters;
  16179. mgb_assert(PyType_Ready(&py_type) >= 0);
  16180. _init_py_TopK_Mode(py_type);
  16181. PyType_Modified(&py_type);
  16182. m.add_object("TopK", reinterpret_cast<PyObject*>(&py_type));
  16183. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TopK::typeinfo(), &py_type).second);
  16184. }
  16185. PyOpDefBegin(TypeCvt) // {
  16186. static PyGetSetDef py_getsetters[];
  16187. static PyMethodDef tp_methods[];
  16188. static PyObject* getstate(PyObject* self, PyObject*) {
  16189. auto& opdef = reinterpret_cast<PyOp(TypeCvt)*>(self)->inst();
  16190. static_cast<void>(opdef);
  16191. std::unordered_map<std::string, py::object> state {
  16192. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)}
  16193. };
  16194. return py::cast(state).release().ptr();
  16195. }
  16196. static PyObject* setstate(PyObject* self, PyObject* args) {
  16197. PyObject* dict = PyTuple_GetItem(args, 0);
  16198. if (!dict) return NULL;
  16199. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16200. auto& opdef = reinterpret_cast<PyOp(TypeCvt)*>(self)->inst();
  16201. static_cast<void>(opdef);
  16202. {
  16203. auto&& iter = state.find("dtype");
  16204. if (iter != state.end()) {
  16205. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  16206. }
  16207. }
  16208. Py_RETURN_NONE;
  16209. }
  16210. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16211. // };
  16212. PyOpDefEnd(TypeCvt)
  16213. int PyOp(TypeCvt)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16214. static const char* kwlist[] = {"dtype", "scope", NULL};
  16215. PyObject *dtype = NULL, *scope = NULL;
  16216. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast<char**>(kwlist), &dtype, &scope))
  16217. return -1;
  16218. if (dtype) {
  16219. try {
  16220. // TODO: remove this guard which is used for pybind11 implicit conversion
  16221. py::detail::loader_life_support guard{};
  16222. reinterpret_cast<PyOp(TypeCvt)*>(self)->inst().dtype =
  16223. py::cast<decltype(TypeCvt::dtype)>(py::handle(dtype));
  16224. } CATCH_ALL(-1)
  16225. }
  16226. if (scope) {
  16227. try {
  16228. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16229. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16230. } CATCH_ALL(-1)
  16231. }
  16232. return 0;
  16233. }
  16234. PyGetSetDef PyOp(TypeCvt)::py_getsetters[] = {
  16235. {const_cast<char*>("dtype"), py_get_generic(TypeCvt, dtype), py_set_generic(TypeCvt, dtype), const_cast<char*>("dtype"), NULL},
  16236. {NULL} /* Sentinel */
  16237. };
  16238. PyMethodDef PyOp(TypeCvt)::tp_methods[] = {
  16239. {const_cast<char*>("__getstate__"), PyOp(TypeCvt)::getstate, METH_NOARGS, "TypeCvt getstate"},
  16240. {const_cast<char*>("__setstate__"), PyOp(TypeCvt)::setstate, METH_VARARGS, "TypeCvt setstate"},
  16241. {NULL} /* Sentinel */
  16242. };
  16243. void _init_py_TypeCvt(py::module m) {
  16244. using py_op = PyOp(TypeCvt);
  16245. auto& py_type = PyOpType(TypeCvt);
  16246. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16247. py_type.tp_name = "megengine.core._imperative_rt.ops.TypeCvt";
  16248. py_type.tp_basicsize = sizeof(PyOp(TypeCvt));
  16249. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16250. py_type.tp_doc = "TypeCvt";
  16251. py_type.tp_base = &PyOpType(OpDef);
  16252. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16253. py_type.tp_new = py_new_generic<py_op>;
  16254. py_type.tp_init = py_op::py_init;
  16255. py_type.tp_methods = py_op::tp_methods;
  16256. py_type.tp_getset = py_op::py_getsetters;
  16257. mgb_assert(PyType_Ready(&py_type) >= 0);
  16258. PyType_Modified(&py_type);
  16259. m.add_object("TypeCvt", reinterpret_cast<PyObject*>(&py_type));
  16260. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TypeCvt::typeinfo(), &py_type).second);
  16261. }
  16262. PyOpDefBegin(UniformRNG) // {
  16263. static PyGetSetDef py_getsetters[];
  16264. static PyMethodDef tp_methods[];
  16265. static PyObject* getstate(PyObject* self, PyObject*) {
  16266. auto& opdef = reinterpret_cast<PyOp(UniformRNG)*>(self)->inst();
  16267. static_cast<void>(opdef);
  16268. std::unordered_map<std::string, py::object> state {
  16269. {"seed", serialization<decltype(opdef.seed)>::dump(opdef.seed)},
  16270. {"dtype", serialization<decltype(opdef.dtype)>::dump(opdef.dtype)},
  16271. {"handle", serialization<decltype(opdef.handle)>::dump(opdef.handle)}
  16272. };
  16273. return py::cast(state).release().ptr();
  16274. }
  16275. static PyObject* setstate(PyObject* self, PyObject* args) {
  16276. PyObject* dict = PyTuple_GetItem(args, 0);
  16277. if (!dict) return NULL;
  16278. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16279. auto& opdef = reinterpret_cast<PyOp(UniformRNG)*>(self)->inst();
  16280. static_cast<void>(opdef);
  16281. {
  16282. auto&& iter = state.find("seed");
  16283. if (iter != state.end()) {
  16284. opdef.seed = serialization<decltype(opdef.seed)>::load(iter->second);
  16285. }
  16286. }
  16287. {
  16288. auto&& iter = state.find("dtype");
  16289. if (iter != state.end()) {
  16290. opdef.dtype = serialization<decltype(opdef.dtype)>::load(iter->second);
  16291. }
  16292. }
  16293. {
  16294. auto&& iter = state.find("handle");
  16295. if (iter != state.end()) {
  16296. opdef.handle = serialization<decltype(opdef.handle)>::load(iter->second);
  16297. }
  16298. }
  16299. Py_RETURN_NONE;
  16300. }
  16301. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16302. // };
  16303. PyOpDefEnd(UniformRNG)
  16304. int PyOp(UniformRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16305. static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL};
  16306. PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL;
  16307. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast<char**>(kwlist), &seed, &dtype, &handle, &scope))
  16308. return -1;
  16309. if (seed) {
  16310. try {
  16311. // TODO: remove this guard which is used for pybind11 implicit conversion
  16312. py::detail::loader_life_support guard{};
  16313. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().seed =
  16314. py::cast<decltype(UniformRNG::seed)>(py::handle(seed));
  16315. } CATCH_ALL(-1)
  16316. }
  16317. if (dtype) {
  16318. try {
  16319. // TODO: remove this guard which is used for pybind11 implicit conversion
  16320. py::detail::loader_life_support guard{};
  16321. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().dtype =
  16322. py::cast<decltype(UniformRNG::dtype)>(py::handle(dtype));
  16323. } CATCH_ALL(-1)
  16324. }
  16325. if (handle) {
  16326. try {
  16327. // TODO: remove this guard which is used for pybind11 implicit conversion
  16328. py::detail::loader_life_support guard{};
  16329. reinterpret_cast<PyOp(UniformRNG)*>(self)->inst().handle =
  16330. py::cast<decltype(UniformRNG::handle)>(py::handle(handle));
  16331. } CATCH_ALL(-1)
  16332. }
  16333. if (scope) {
  16334. try {
  16335. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16336. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16337. } CATCH_ALL(-1)
  16338. }
  16339. return 0;
  16340. }
  16341. PyGetSetDef PyOp(UniformRNG)::py_getsetters[] = {
  16342. {const_cast<char*>("seed"), py_get_generic(UniformRNG, seed), py_set_generic(UniformRNG, seed), const_cast<char*>("seed"), NULL},
  16343. {const_cast<char*>("dtype"), py_get_generic(UniformRNG, dtype), py_set_generic(UniformRNG, dtype), const_cast<char*>("dtype"), NULL},
  16344. {const_cast<char*>("handle"), py_get_generic(UniformRNG, handle), py_set_generic(UniformRNG, handle), const_cast<char*>("handle"), NULL},
  16345. {NULL} /* Sentinel */
  16346. };
  16347. PyMethodDef PyOp(UniformRNG)::tp_methods[] = {
  16348. {const_cast<char*>("__getstate__"), PyOp(UniformRNG)::getstate, METH_NOARGS, "UniformRNG getstate"},
  16349. {const_cast<char*>("__setstate__"), PyOp(UniformRNG)::setstate, METH_VARARGS, "UniformRNG setstate"},
  16350. {NULL} /* Sentinel */
  16351. };
  16352. void _init_py_UniformRNG(py::module m) {
  16353. using py_op = PyOp(UniformRNG);
  16354. auto& py_type = PyOpType(UniformRNG);
  16355. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16356. py_type.tp_name = "megengine.core._imperative_rt.ops.UniformRNG";
  16357. py_type.tp_basicsize = sizeof(PyOp(UniformRNG));
  16358. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16359. py_type.tp_doc = "UniformRNG";
  16360. py_type.tp_base = &PyOpType(OpDef);
  16361. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16362. py_type.tp_new = py_new_generic<py_op>;
  16363. py_type.tp_init = py_op::py_init;
  16364. py_type.tp_methods = py_op::tp_methods;
  16365. py_type.tp_getset = py_op::py_getsetters;
  16366. mgb_assert(PyType_Ready(&py_type) >= 0);
  16367. PyType_Modified(&py_type);
  16368. m.add_object("UniformRNG", reinterpret_cast<PyObject*>(&py_type));
  16369. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(UniformRNG::typeinfo(), &py_type).second);
  16370. }
  16371. void _init_py_WarpAffine_InterpolationMode(PyTypeObject& py_type) {
  16372. auto& e_type = EnumWrapper<WarpAffine::InterpolationMode>::type;
  16373. Py_INCREF(e_type);
  16374. mgb_assert(PyDict_SetItemString(
  16375. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16376. }
  16377. void _init_py_WarpAffine_BorderMode(PyTypeObject& py_type) {
  16378. auto& e_type = EnumWrapper<WarpAffine::BorderMode>::type;
  16379. Py_INCREF(e_type);
  16380. mgb_assert(PyDict_SetItemString(
  16381. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16382. }
  16383. void _init_py_WarpAffine_Format(PyTypeObject& py_type) {
  16384. auto& e_type = EnumWrapper<WarpAffine::Format>::type;
  16385. Py_INCREF(e_type);
  16386. mgb_assert(PyDict_SetItemString(
  16387. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16388. }
  16389. PyOpDefBegin(WarpAffine) // {
  16390. static PyGetSetDef py_getsetters[];
  16391. static PyMethodDef tp_methods[];
  16392. static PyObject* getstate(PyObject* self, PyObject*) {
  16393. auto& opdef = reinterpret_cast<PyOp(WarpAffine)*>(self)->inst();
  16394. static_cast<void>(opdef);
  16395. std::unordered_map<std::string, py::object> state {
  16396. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  16397. {"border_mode", serialization<decltype(opdef.border_mode)>::dump(opdef.border_mode)},
  16398. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)},
  16399. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)}
  16400. };
  16401. return py::cast(state).release().ptr();
  16402. }
  16403. static PyObject* setstate(PyObject* self, PyObject* args) {
  16404. PyObject* dict = PyTuple_GetItem(args, 0);
  16405. if (!dict) return NULL;
  16406. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16407. auto& opdef = reinterpret_cast<PyOp(WarpAffine)*>(self)->inst();
  16408. static_cast<void>(opdef);
  16409. {
  16410. auto&& iter = state.find("imode");
  16411. if (iter != state.end()) {
  16412. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  16413. }
  16414. }
  16415. {
  16416. auto&& iter = state.find("border_mode");
  16417. if (iter != state.end()) {
  16418. opdef.border_mode = serialization<decltype(opdef.border_mode)>::load(iter->second);
  16419. }
  16420. }
  16421. {
  16422. auto&& iter = state.find("border_val");
  16423. if (iter != state.end()) {
  16424. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  16425. }
  16426. }
  16427. {
  16428. auto&& iter = state.find("format");
  16429. if (iter != state.end()) {
  16430. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  16431. }
  16432. }
  16433. Py_RETURN_NONE;
  16434. }
  16435. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16436. // };
  16437. PyOpDefEnd(WarpAffine)
  16438. int PyOp(WarpAffine)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16439. static const char* kwlist[] = {"imode", "border_mode", "border_val", "format", "scope", NULL};
  16440. PyObject *imode = NULL, *border_mode = NULL, *border_val = NULL, *format = NULL, *scope = NULL;
  16441. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &border_mode, &border_val, &format, &scope))
  16442. return -1;
  16443. if (imode) {
  16444. try {
  16445. // TODO: remove this guard which is used for pybind11 implicit conversion
  16446. py::detail::loader_life_support guard{};
  16447. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().imode =
  16448. py::cast<decltype(WarpAffine::imode)>(py::handle(imode));
  16449. } CATCH_ALL(-1)
  16450. }
  16451. if (border_mode) {
  16452. try {
  16453. // TODO: remove this guard which is used for pybind11 implicit conversion
  16454. py::detail::loader_life_support guard{};
  16455. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().border_mode =
  16456. py::cast<decltype(WarpAffine::border_mode)>(py::handle(border_mode));
  16457. } CATCH_ALL(-1)
  16458. }
  16459. if (border_val) {
  16460. try {
  16461. // TODO: remove this guard which is used for pybind11 implicit conversion
  16462. py::detail::loader_life_support guard{};
  16463. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().border_val =
  16464. py::cast<decltype(WarpAffine::border_val)>(py::handle(border_val));
  16465. } CATCH_ALL(-1)
  16466. }
  16467. if (format) {
  16468. try {
  16469. // TODO: remove this guard which is used for pybind11 implicit conversion
  16470. py::detail::loader_life_support guard{};
  16471. reinterpret_cast<PyOp(WarpAffine)*>(self)->inst().format =
  16472. py::cast<decltype(WarpAffine::format)>(py::handle(format));
  16473. } CATCH_ALL(-1)
  16474. }
  16475. if (scope) {
  16476. try {
  16477. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16478. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16479. } CATCH_ALL(-1)
  16480. }
  16481. return 0;
  16482. }
  16483. PyGetSetDef PyOp(WarpAffine)::py_getsetters[] = {
  16484. {const_cast<char*>("imode"), py_get_generic(WarpAffine, imode), py_set_generic(WarpAffine, imode), const_cast<char*>("imode"), NULL},
  16485. {const_cast<char*>("border_mode"), py_get_generic(WarpAffine, border_mode), py_set_generic(WarpAffine, border_mode), const_cast<char*>("border_mode"), NULL},
  16486. {const_cast<char*>("border_val"), py_get_generic(WarpAffine, border_val), py_set_generic(WarpAffine, border_val), const_cast<char*>("border_val"), NULL},
  16487. {const_cast<char*>("format"), py_get_generic(WarpAffine, format), py_set_generic(WarpAffine, format), const_cast<char*>("format"), NULL},
  16488. {NULL} /* Sentinel */
  16489. };
  16490. PyMethodDef PyOp(WarpAffine)::tp_methods[] = {
  16491. {const_cast<char*>("__getstate__"), PyOp(WarpAffine)::getstate, METH_NOARGS, "WarpAffine getstate"},
  16492. {const_cast<char*>("__setstate__"), PyOp(WarpAffine)::setstate, METH_VARARGS, "WarpAffine setstate"},
  16493. {NULL} /* Sentinel */
  16494. };
  16495. void _init_py_WarpAffine(py::module m) {
  16496. using py_op = PyOp(WarpAffine);
  16497. auto& py_type = PyOpType(WarpAffine);
  16498. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16499. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpAffine";
  16500. py_type.tp_basicsize = sizeof(PyOp(WarpAffine));
  16501. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16502. py_type.tp_doc = "WarpAffine";
  16503. py_type.tp_base = &PyOpType(OpDef);
  16504. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16505. py_type.tp_new = py_new_generic<py_op>;
  16506. py_type.tp_init = py_op::py_init;
  16507. py_type.tp_methods = py_op::tp_methods;
  16508. py_type.tp_getset = py_op::py_getsetters;
  16509. mgb_assert(PyType_Ready(&py_type) >= 0);
  16510. _init_py_WarpAffine_InterpolationMode(py_type);
  16511. _init_py_WarpAffine_BorderMode(py_type);
  16512. _init_py_WarpAffine_Format(py_type);
  16513. PyType_Modified(&py_type);
  16514. m.add_object("WarpAffine", reinterpret_cast<PyObject*>(&py_type));
  16515. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpAffine::typeinfo(), &py_type).second);
  16516. }
  16517. void _init_py_WarpPerspective_InterpolationMode(PyTypeObject& py_type) {
  16518. auto& e_type = EnumWrapper<WarpPerspective::InterpolationMode>::type;
  16519. Py_INCREF(e_type);
  16520. mgb_assert(PyDict_SetItemString(
  16521. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16522. }
  16523. void _init_py_WarpPerspective_BorderMode(PyTypeObject& py_type) {
  16524. auto& e_type = EnumWrapper<WarpPerspective::BorderMode>::type;
  16525. Py_INCREF(e_type);
  16526. mgb_assert(PyDict_SetItemString(
  16527. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16528. }
  16529. void _init_py_WarpPerspective_Format(PyTypeObject& py_type) {
  16530. auto& e_type = EnumWrapper<WarpPerspective::Format>::type;
  16531. Py_INCREF(e_type);
  16532. mgb_assert(PyDict_SetItemString(
  16533. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16534. }
  16535. PyOpDefBegin(WarpPerspective) // {
  16536. static PyGetSetDef py_getsetters[];
  16537. static PyMethodDef tp_methods[];
  16538. static PyObject* getstate(PyObject* self, PyObject*) {
  16539. auto& opdef = reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst();
  16540. static_cast<void>(opdef);
  16541. std::unordered_map<std::string, py::object> state {
  16542. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  16543. {"bmode", serialization<decltype(opdef.bmode)>::dump(opdef.bmode)},
  16544. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  16545. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)}
  16546. };
  16547. return py::cast(state).release().ptr();
  16548. }
  16549. static PyObject* setstate(PyObject* self, PyObject* args) {
  16550. PyObject* dict = PyTuple_GetItem(args, 0);
  16551. if (!dict) return NULL;
  16552. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16553. auto& opdef = reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst();
  16554. static_cast<void>(opdef);
  16555. {
  16556. auto&& iter = state.find("imode");
  16557. if (iter != state.end()) {
  16558. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  16559. }
  16560. }
  16561. {
  16562. auto&& iter = state.find("bmode");
  16563. if (iter != state.end()) {
  16564. opdef.bmode = serialization<decltype(opdef.bmode)>::load(iter->second);
  16565. }
  16566. }
  16567. {
  16568. auto&& iter = state.find("format");
  16569. if (iter != state.end()) {
  16570. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  16571. }
  16572. }
  16573. {
  16574. auto&& iter = state.find("border_val");
  16575. if (iter != state.end()) {
  16576. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  16577. }
  16578. }
  16579. Py_RETURN_NONE;
  16580. }
  16581. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16582. // };
  16583. PyOpDefEnd(WarpPerspective)
  16584. int PyOp(WarpPerspective)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16585. static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL};
  16586. PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL;
  16587. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &bmode, &format, &border_val, &scope))
  16588. return -1;
  16589. if (imode) {
  16590. try {
  16591. // TODO: remove this guard which is used for pybind11 implicit conversion
  16592. py::detail::loader_life_support guard{};
  16593. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().imode =
  16594. py::cast<decltype(WarpPerspective::imode)>(py::handle(imode));
  16595. } CATCH_ALL(-1)
  16596. }
  16597. if (bmode) {
  16598. try {
  16599. // TODO: remove this guard which is used for pybind11 implicit conversion
  16600. py::detail::loader_life_support guard{};
  16601. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().bmode =
  16602. py::cast<decltype(WarpPerspective::bmode)>(py::handle(bmode));
  16603. } CATCH_ALL(-1)
  16604. }
  16605. if (format) {
  16606. try {
  16607. // TODO: remove this guard which is used for pybind11 implicit conversion
  16608. py::detail::loader_life_support guard{};
  16609. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().format =
  16610. py::cast<decltype(WarpPerspective::format)>(py::handle(format));
  16611. } CATCH_ALL(-1)
  16612. }
  16613. if (border_val) {
  16614. try {
  16615. // TODO: remove this guard which is used for pybind11 implicit conversion
  16616. py::detail::loader_life_support guard{};
  16617. reinterpret_cast<PyOp(WarpPerspective)*>(self)->inst().border_val =
  16618. py::cast<decltype(WarpPerspective::border_val)>(py::handle(border_val));
  16619. } CATCH_ALL(-1)
  16620. }
  16621. if (scope) {
  16622. try {
  16623. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16624. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16625. } CATCH_ALL(-1)
  16626. }
  16627. return 0;
  16628. }
  16629. PyGetSetDef PyOp(WarpPerspective)::py_getsetters[] = {
  16630. {const_cast<char*>("imode"), py_get_generic(WarpPerspective, imode), py_set_generic(WarpPerspective, imode), const_cast<char*>("imode"), NULL},
  16631. {const_cast<char*>("bmode"), py_get_generic(WarpPerspective, bmode), py_set_generic(WarpPerspective, bmode), const_cast<char*>("bmode"), NULL},
  16632. {const_cast<char*>("format"), py_get_generic(WarpPerspective, format), py_set_generic(WarpPerspective, format), const_cast<char*>("format"), NULL},
  16633. {const_cast<char*>("border_val"), py_get_generic(WarpPerspective, border_val), py_set_generic(WarpPerspective, border_val), const_cast<char*>("border_val"), NULL},
  16634. {NULL} /* Sentinel */
  16635. };
  16636. PyMethodDef PyOp(WarpPerspective)::tp_methods[] = {
  16637. {const_cast<char*>("__getstate__"), PyOp(WarpPerspective)::getstate, METH_NOARGS, "WarpPerspective getstate"},
  16638. {const_cast<char*>("__setstate__"), PyOp(WarpPerspective)::setstate, METH_VARARGS, "WarpPerspective setstate"},
  16639. {NULL} /* Sentinel */
  16640. };
  16641. void _init_py_WarpPerspective(py::module m) {
  16642. using py_op = PyOp(WarpPerspective);
  16643. auto& py_type = PyOpType(WarpPerspective);
  16644. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16645. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspective";
  16646. py_type.tp_basicsize = sizeof(PyOp(WarpPerspective));
  16647. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16648. py_type.tp_doc = "WarpPerspective";
  16649. py_type.tp_base = &PyOpType(OpDef);
  16650. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16651. py_type.tp_new = py_new_generic<py_op>;
  16652. py_type.tp_init = py_op::py_init;
  16653. py_type.tp_methods = py_op::tp_methods;
  16654. py_type.tp_getset = py_op::py_getsetters;
  16655. mgb_assert(PyType_Ready(&py_type) >= 0);
  16656. _init_py_WarpPerspective_InterpolationMode(py_type);
  16657. _init_py_WarpPerspective_BorderMode(py_type);
  16658. _init_py_WarpPerspective_Format(py_type);
  16659. PyType_Modified(&py_type);
  16660. m.add_object("WarpPerspective", reinterpret_cast<PyObject*>(&py_type));
  16661. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspective::typeinfo(), &py_type).second);
  16662. }
  16663. void _init_py_WarpPerspectiveBackwardData_InterpolationMode(PyTypeObject& py_type) {
  16664. auto& e_type = EnumWrapper<WarpPerspectiveBackwardData::InterpolationMode>::type;
  16665. Py_INCREF(e_type);
  16666. mgb_assert(PyDict_SetItemString(
  16667. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16668. }
  16669. void _init_py_WarpPerspectiveBackwardData_BorderMode(PyTypeObject& py_type) {
  16670. auto& e_type = EnumWrapper<WarpPerspectiveBackwardData::BorderMode>::type;
  16671. Py_INCREF(e_type);
  16672. mgb_assert(PyDict_SetItemString(
  16673. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16674. }
  16675. void _init_py_WarpPerspectiveBackwardData_Format(PyTypeObject& py_type) {
  16676. auto& e_type = EnumWrapper<WarpPerspectiveBackwardData::Format>::type;
  16677. Py_INCREF(e_type);
  16678. mgb_assert(PyDict_SetItemString(
  16679. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16680. }
  16681. PyOpDefBegin(WarpPerspectiveBackwardData) // {
  16682. static PyGetSetDef py_getsetters[];
  16683. static PyMethodDef tp_methods[];
  16684. static PyObject* getstate(PyObject* self, PyObject*) {
  16685. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst();
  16686. static_cast<void>(opdef);
  16687. std::unordered_map<std::string, py::object> state {
  16688. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  16689. {"bmode", serialization<decltype(opdef.bmode)>::dump(opdef.bmode)},
  16690. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  16691. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)}
  16692. };
  16693. return py::cast(state).release().ptr();
  16694. }
  16695. static PyObject* setstate(PyObject* self, PyObject* args) {
  16696. PyObject* dict = PyTuple_GetItem(args, 0);
  16697. if (!dict) return NULL;
  16698. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16699. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst();
  16700. static_cast<void>(opdef);
  16701. {
  16702. auto&& iter = state.find("imode");
  16703. if (iter != state.end()) {
  16704. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  16705. }
  16706. }
  16707. {
  16708. auto&& iter = state.find("bmode");
  16709. if (iter != state.end()) {
  16710. opdef.bmode = serialization<decltype(opdef.bmode)>::load(iter->second);
  16711. }
  16712. }
  16713. {
  16714. auto&& iter = state.find("format");
  16715. if (iter != state.end()) {
  16716. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  16717. }
  16718. }
  16719. {
  16720. auto&& iter = state.find("border_val");
  16721. if (iter != state.end()) {
  16722. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  16723. }
  16724. }
  16725. Py_RETURN_NONE;
  16726. }
  16727. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16728. // };
  16729. PyOpDefEnd(WarpPerspectiveBackwardData)
  16730. int PyOp(WarpPerspectiveBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16731. static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL};
  16732. PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL;
  16733. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &bmode, &format, &border_val, &scope))
  16734. return -1;
  16735. if (imode) {
  16736. try {
  16737. // TODO: remove this guard which is used for pybind11 implicit conversion
  16738. py::detail::loader_life_support guard{};
  16739. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().imode =
  16740. py::cast<decltype(WarpPerspectiveBackwardData::imode)>(py::handle(imode));
  16741. } CATCH_ALL(-1)
  16742. }
  16743. if (bmode) {
  16744. try {
  16745. // TODO: remove this guard which is used for pybind11 implicit conversion
  16746. py::detail::loader_life_support guard{};
  16747. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().bmode =
  16748. py::cast<decltype(WarpPerspectiveBackwardData::bmode)>(py::handle(bmode));
  16749. } CATCH_ALL(-1)
  16750. }
  16751. if (format) {
  16752. try {
  16753. // TODO: remove this guard which is used for pybind11 implicit conversion
  16754. py::detail::loader_life_support guard{};
  16755. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().format =
  16756. py::cast<decltype(WarpPerspectiveBackwardData::format)>(py::handle(format));
  16757. } CATCH_ALL(-1)
  16758. }
  16759. if (border_val) {
  16760. try {
  16761. // TODO: remove this guard which is used for pybind11 implicit conversion
  16762. py::detail::loader_life_support guard{};
  16763. reinterpret_cast<PyOp(WarpPerspectiveBackwardData)*>(self)->inst().border_val =
  16764. py::cast<decltype(WarpPerspectiveBackwardData::border_val)>(py::handle(border_val));
  16765. } CATCH_ALL(-1)
  16766. }
  16767. if (scope) {
  16768. try {
  16769. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16770. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16771. } CATCH_ALL(-1)
  16772. }
  16773. return 0;
  16774. }
  16775. PyGetSetDef PyOp(WarpPerspectiveBackwardData)::py_getsetters[] = {
  16776. {const_cast<char*>("imode"), py_get_generic(WarpPerspectiveBackwardData, imode), py_set_generic(WarpPerspectiveBackwardData, imode), const_cast<char*>("imode"), NULL},
  16777. {const_cast<char*>("bmode"), py_get_generic(WarpPerspectiveBackwardData, bmode), py_set_generic(WarpPerspectiveBackwardData, bmode), const_cast<char*>("bmode"), NULL},
  16778. {const_cast<char*>("format"), py_get_generic(WarpPerspectiveBackwardData, format), py_set_generic(WarpPerspectiveBackwardData, format), const_cast<char*>("format"), NULL},
  16779. {const_cast<char*>("border_val"), py_get_generic(WarpPerspectiveBackwardData, border_val), py_set_generic(WarpPerspectiveBackwardData, border_val), const_cast<char*>("border_val"), NULL},
  16780. {NULL} /* Sentinel */
  16781. };
  16782. PyMethodDef PyOp(WarpPerspectiveBackwardData)::tp_methods[] = {
  16783. {const_cast<char*>("__getstate__"), PyOp(WarpPerspectiveBackwardData)::getstate, METH_NOARGS, "WarpPerspectiveBackwardData getstate"},
  16784. {const_cast<char*>("__setstate__"), PyOp(WarpPerspectiveBackwardData)::setstate, METH_VARARGS, "WarpPerspectiveBackwardData setstate"},
  16785. {NULL} /* Sentinel */
  16786. };
  16787. void _init_py_WarpPerspectiveBackwardData(py::module m) {
  16788. using py_op = PyOp(WarpPerspectiveBackwardData);
  16789. auto& py_type = PyOpType(WarpPerspectiveBackwardData);
  16790. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16791. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspectiveBackwardData";
  16792. py_type.tp_basicsize = sizeof(PyOp(WarpPerspectiveBackwardData));
  16793. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16794. py_type.tp_doc = "WarpPerspectiveBackwardData";
  16795. py_type.tp_base = &PyOpType(OpDef);
  16796. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16797. py_type.tp_new = py_new_generic<py_op>;
  16798. py_type.tp_init = py_op::py_init;
  16799. py_type.tp_methods = py_op::tp_methods;
  16800. py_type.tp_getset = py_op::py_getsetters;
  16801. mgb_assert(PyType_Ready(&py_type) >= 0);
  16802. _init_py_WarpPerspectiveBackwardData_InterpolationMode(py_type);
  16803. _init_py_WarpPerspectiveBackwardData_BorderMode(py_type);
  16804. _init_py_WarpPerspectiveBackwardData_Format(py_type);
  16805. PyType_Modified(&py_type);
  16806. m.add_object("WarpPerspectiveBackwardData", reinterpret_cast<PyObject*>(&py_type));
  16807. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspectiveBackwardData::typeinfo(), &py_type).second);
  16808. }
  16809. void _init_py_WarpPerspectiveBackwardMat_InterpolationMode(PyTypeObject& py_type) {
  16810. auto& e_type = EnumWrapper<WarpPerspectiveBackwardMat::InterpolationMode>::type;
  16811. Py_INCREF(e_type);
  16812. mgb_assert(PyDict_SetItemString(
  16813. py_type.tp_dict, "InterpolationMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16814. }
  16815. void _init_py_WarpPerspectiveBackwardMat_BorderMode(PyTypeObject& py_type) {
  16816. auto& e_type = EnumWrapper<WarpPerspectiveBackwardMat::BorderMode>::type;
  16817. Py_INCREF(e_type);
  16818. mgb_assert(PyDict_SetItemString(
  16819. py_type.tp_dict, "BorderMode", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16820. }
  16821. void _init_py_WarpPerspectiveBackwardMat_Format(PyTypeObject& py_type) {
  16822. auto& e_type = EnumWrapper<WarpPerspectiveBackwardMat::Format>::type;
  16823. Py_INCREF(e_type);
  16824. mgb_assert(PyDict_SetItemString(
  16825. py_type.tp_dict, "Format", reinterpret_cast<PyObject*>(e_type)) >= 0);
  16826. }
  16827. PyOpDefBegin(WarpPerspectiveBackwardMat) // {
  16828. static PyGetSetDef py_getsetters[];
  16829. static PyMethodDef tp_methods[];
  16830. static PyObject* getstate(PyObject* self, PyObject*) {
  16831. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst();
  16832. static_cast<void>(opdef);
  16833. std::unordered_map<std::string, py::object> state {
  16834. {"imode", serialization<decltype(opdef.imode)>::dump(opdef.imode)},
  16835. {"bmode", serialization<decltype(opdef.bmode)>::dump(opdef.bmode)},
  16836. {"format", serialization<decltype(opdef.format)>::dump(opdef.format)},
  16837. {"border_val", serialization<decltype(opdef.border_val)>::dump(opdef.border_val)}
  16838. };
  16839. return py::cast(state).release().ptr();
  16840. }
  16841. static PyObject* setstate(PyObject* self, PyObject* args) {
  16842. PyObject* dict = PyTuple_GetItem(args, 0);
  16843. if (!dict) return NULL;
  16844. auto state = py::cast<std::unordered_map<std::string, py::object>>(dict);
  16845. auto& opdef = reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst();
  16846. static_cast<void>(opdef);
  16847. {
  16848. auto&& iter = state.find("imode");
  16849. if (iter != state.end()) {
  16850. opdef.imode = serialization<decltype(opdef.imode)>::load(iter->second);
  16851. }
  16852. }
  16853. {
  16854. auto&& iter = state.find("bmode");
  16855. if (iter != state.end()) {
  16856. opdef.bmode = serialization<decltype(opdef.bmode)>::load(iter->second);
  16857. }
  16858. }
  16859. {
  16860. auto&& iter = state.find("format");
  16861. if (iter != state.end()) {
  16862. opdef.format = serialization<decltype(opdef.format)>::load(iter->second);
  16863. }
  16864. }
  16865. {
  16866. auto&& iter = state.find("border_val");
  16867. if (iter != state.end()) {
  16868. opdef.border_val = serialization<decltype(opdef.border_val)>::load(iter->second);
  16869. }
  16870. }
  16871. Py_RETURN_NONE;
  16872. }
  16873. static int py_init(PyObject *self, PyObject *args, PyObject *kwds);
  16874. // };
  16875. PyOpDefEnd(WarpPerspectiveBackwardMat)
  16876. int PyOp(WarpPerspectiveBackwardMat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) {
  16877. static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL};
  16878. PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL;
  16879. if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast<char**>(kwlist), &imode, &bmode, &format, &border_val, &scope))
  16880. return -1;
  16881. if (imode) {
  16882. try {
  16883. // TODO: remove this guard which is used for pybind11 implicit conversion
  16884. py::detail::loader_life_support guard{};
  16885. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().imode =
  16886. py::cast<decltype(WarpPerspectiveBackwardMat::imode)>(py::handle(imode));
  16887. } CATCH_ALL(-1)
  16888. }
  16889. if (bmode) {
  16890. try {
  16891. // TODO: remove this guard which is used for pybind11 implicit conversion
  16892. py::detail::loader_life_support guard{};
  16893. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().bmode =
  16894. py::cast<decltype(WarpPerspectiveBackwardMat::bmode)>(py::handle(bmode));
  16895. } CATCH_ALL(-1)
  16896. }
  16897. if (format) {
  16898. try {
  16899. // TODO: remove this guard which is used for pybind11 implicit conversion
  16900. py::detail::loader_life_support guard{};
  16901. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().format =
  16902. py::cast<decltype(WarpPerspectiveBackwardMat::format)>(py::handle(format));
  16903. } CATCH_ALL(-1)
  16904. }
  16905. if (border_val) {
  16906. try {
  16907. // TODO: remove this guard which is used for pybind11 implicit conversion
  16908. py::detail::loader_life_support guard{};
  16909. reinterpret_cast<PyOp(WarpPerspectiveBackwardMat)*>(self)->inst().border_val =
  16910. py::cast<decltype(WarpPerspectiveBackwardMat::border_val)>(py::handle(border_val));
  16911. } CATCH_ALL(-1)
  16912. }
  16913. if (scope) {
  16914. try {
  16915. reinterpret_cast<PyOp(OpDef)*>(self)->op
  16916. ->set_scope(py::cast<std::string>(py::handle(scope)));
  16917. } CATCH_ALL(-1)
  16918. }
  16919. return 0;
  16920. }
  16921. PyGetSetDef PyOp(WarpPerspectiveBackwardMat)::py_getsetters[] = {
  16922. {const_cast<char*>("imode"), py_get_generic(WarpPerspectiveBackwardMat, imode), py_set_generic(WarpPerspectiveBackwardMat, imode), const_cast<char*>("imode"), NULL},
  16923. {const_cast<char*>("bmode"), py_get_generic(WarpPerspectiveBackwardMat, bmode), py_set_generic(WarpPerspectiveBackwardMat, bmode), const_cast<char*>("bmode"), NULL},
  16924. {const_cast<char*>("format"), py_get_generic(WarpPerspectiveBackwardMat, format), py_set_generic(WarpPerspectiveBackwardMat, format), const_cast<char*>("format"), NULL},
  16925. {const_cast<char*>("border_val"), py_get_generic(WarpPerspectiveBackwardMat, border_val), py_set_generic(WarpPerspectiveBackwardMat, border_val), const_cast<char*>("border_val"), NULL},
  16926. {NULL} /* Sentinel */
  16927. };
  16928. PyMethodDef PyOp(WarpPerspectiveBackwardMat)::tp_methods[] = {
  16929. {const_cast<char*>("__getstate__"), PyOp(WarpPerspectiveBackwardMat)::getstate, METH_NOARGS, "WarpPerspectiveBackwardMat getstate"},
  16930. {const_cast<char*>("__setstate__"), PyOp(WarpPerspectiveBackwardMat)::setstate, METH_VARARGS, "WarpPerspectiveBackwardMat setstate"},
  16931. {NULL} /* Sentinel */
  16932. };
  16933. void _init_py_WarpPerspectiveBackwardMat(py::module m) {
  16934. using py_op = PyOp(WarpPerspectiveBackwardMat);
  16935. auto& py_type = PyOpType(WarpPerspectiveBackwardMat);
  16936. py_type = {PyVarObject_HEAD_INIT(NULL, 0)};
  16937. py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspectiveBackwardMat";
  16938. py_type.tp_basicsize = sizeof(PyOp(WarpPerspectiveBackwardMat));
  16939. py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  16940. py_type.tp_doc = "WarpPerspectiveBackwardMat";
  16941. py_type.tp_base = &PyOpType(OpDef);
  16942. py_type.tp_dealloc = py_dealloc_generic<py_op>;
  16943. py_type.tp_new = py_new_generic<py_op>;
  16944. py_type.tp_init = py_op::py_init;
  16945. py_type.tp_methods = py_op::tp_methods;
  16946. py_type.tp_getset = py_op::py_getsetters;
  16947. mgb_assert(PyType_Ready(&py_type) >= 0);
  16948. _init_py_WarpPerspectiveBackwardMat_InterpolationMode(py_type);
  16949. _init_py_WarpPerspectiveBackwardMat_BorderMode(py_type);
  16950. _init_py_WarpPerspectiveBackwardMat_Format(py_type);
  16951. PyType_Modified(&py_type);
  16952. m.add_object("WarpPerspectiveBackwardMat", reinterpret_cast<PyObject*>(&py_type));
  16953. mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspectiveBackwardMat::typeinfo(), &py_type).second);
  16954. }
  16955. #define INIT_ALL_OP(m) \
  16956. _init_py_AdaptivePooling(m); \
  16957. _init_py_AddAxis(m); \
  16958. _init_py_Argmax(m); \
  16959. _init_py_Argmin(m); \
  16960. _init_py_Argsort(m); \
  16961. _init_py_AssertEqual(m); \
  16962. _init_py_AtlasRuntime(m); \
  16963. _init_py_Barrier(m); \
  16964. _init_py_BatchConvBias(m); \
  16965. _init_py_BatchNorm(m); \
  16966. _init_py_BatchNormBackward(m); \
  16967. _init_py_BatchedIncrMeshIndexing(m); \
  16968. _init_py_BatchedMatrixMul(m); \
  16969. _init_py_BatchedMeshIndexing(m); \
  16970. _init_py_BatchedSetMeshIndexing(m); \
  16971. _init_py_BetaRNG(m); \
  16972. _init_py_Borrow(m); \
  16973. _init_py_Broadcast(m); \
  16974. _init_py_CambriconRuntime(m); \
  16975. _init_py_CheckNonFinite(m); \
  16976. _init_py_CollectiveComm(m); \
  16977. _init_py_Concat(m); \
  16978. _init_py_CondTake(m); \
  16979. _init_py_ConvBias(m); \
  16980. _init_py_Convolution(m); \
  16981. _init_py_Convolution3D(m); \
  16982. _init_py_Convolution3DBackwardData(m); \
  16983. _init_py_ConvolutionBackwardData(m); \
  16984. _init_py_Copy(m); \
  16985. _init_py_Correlation(m); \
  16986. _init_py_Cumsum(m); \
  16987. _init_py_CvtColor(m); \
  16988. _init_py_DeformableConv(m); \
  16989. _init_py_DeformablePSROIPooling(m); \
  16990. _init_py_Diag(m); \
  16991. _init_py_Dimshuffle(m); \
  16992. _init_py_Dot(m); \
  16993. _init_py_Dropout(m); \
  16994. _init_py_Elemwise(m); \
  16995. _init_py_ElemwiseMultiType(m); \
  16996. _init_py_ExternOpr(m); \
  16997. _init_py_Eye(m); \
  16998. _init_py_FakeQuant(m); \
  16999. _init_py_FastpathCopy(m); \
  17000. _init_py_GammaRNG(m); \
  17001. _init_py_GaussianRNG(m); \
  17002. _init_py_GetVarShape(m); \
  17003. _init_py_GroupLocal(m); \
  17004. _init_py_GroupNorm(m); \
  17005. _init_py_Identity(m); \
  17006. _init_py_Images2Neibs(m); \
  17007. _init_py_IncrMeshIndexing(m); \
  17008. _init_py_IncrSubtensor(m); \
  17009. _init_py_IndexingIncrMultiAxisVec(m); \
  17010. _init_py_IndexingMultiAxisVec(m); \
  17011. _init_py_IndexingOneHot(m); \
  17012. _init_py_IndexingSetMultiAxisVec(m); \
  17013. _init_py_IndexingSetOneHot(m); \
  17014. _init_py_InplaceAdd(m); \
  17015. _init_py_LAMBUpdate(m); \
  17016. _init_py_LRN(m); \
  17017. _init_py_LSQ(m); \
  17018. _init_py_LSTM(m); \
  17019. _init_py_LSTMCell(m); \
  17020. _init_py_LayerNorm(m); \
  17021. _init_py_Linspace(m); \
  17022. _init_py_MagicMindRuntime(m); \
  17023. _init_py_MatrixInverse(m); \
  17024. _init_py_MatrixMul(m); \
  17025. _init_py_MeshGrid(m); \
  17026. _init_py_MeshIndexing(m); \
  17027. _init_py_NMSKeep(m); \
  17028. _init_py_NvOf(m); \
  17029. _init_py_Padding(m); \
  17030. _init_py_ParamPackConcat(m); \
  17031. _init_py_ParamPackSplit(m); \
  17032. _init_py_PermutationRNG(m); \
  17033. _init_py_PixelShuffle(m); \
  17034. _init_py_PixelShuffleBackward(m); \
  17035. _init_py_PoissonRNG(m); \
  17036. _init_py_Pooling(m); \
  17037. _init_py_RNN(m); \
  17038. _init_py_RNNCell(m); \
  17039. _init_py_ROIAlign(m); \
  17040. _init_py_ROIPooling(m); \
  17041. _init_py_Reduce(m); \
  17042. _init_py_RegionRestrictedConvolution(m); \
  17043. _init_py_RegionRestrictedConvolutionBackwardData(m); \
  17044. _init_py_Remap(m); \
  17045. _init_py_RemoteRecv(m); \
  17046. _init_py_RemoteSend(m); \
  17047. _init_py_RemoveAxis(m); \
  17048. _init_py_Reshape(m); \
  17049. _init_py_Resize(m); \
  17050. _init_py_SVD(m); \
  17051. _init_py_SetMeshIndexing(m); \
  17052. _init_py_SetSubtensor(m); \
  17053. _init_py_ShuffleRNG(m); \
  17054. _init_py_SlidingWindowTranspose(m); \
  17055. _init_py_Softmax(m); \
  17056. _init_py_Split(m); \
  17057. _init_py_Subtensor(m); \
  17058. _init_py_TQT(m); \
  17059. _init_py_TensorRTRuntime(m); \
  17060. _init_py_TopK(m); \
  17061. _init_py_TypeCvt(m); \
  17062. _init_py_UniformRNG(m); \
  17063. _init_py_WarpAffine(m); \
  17064. _init_py_WarpPerspective(m); \
  17065. _init_py_WarpPerspectiveBackwardData(m); \
  17066. _init_py_WarpPerspectiveBackwardMat(m);
  17067. // clang-format on