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.py.inl 116 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  1. // clang-format off
  2. py::class_<AdaptivePooling, std::shared_ptr<AdaptivePooling>, OpDef> AdaptivePoolingInst(m, "AdaptivePooling");
  3. py::enum_<AdaptivePooling::Mode>(AdaptivePoolingInst, "Mode")
  4. .value("MAX", AdaptivePooling::Mode::MAX)
  5. .value("AVERAGE", AdaptivePooling::Mode::AVERAGE)
  6. .value("AVERAGE_COUNT_EXCLUDE_PADDING", AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING)
  7. .def(py::init([](const std::string& in) {
  8. auto&& str = normalize_enum(in);
  9. if (str == "MAX") return AdaptivePooling::Mode::MAX;
  10. if (str == "AVERAGE") return AdaptivePooling::Mode::AVERAGE;
  11. if (str == "AVERAGE_COUNT_EXCLUDE_PADDING") return AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING;
  12. throw py::cast_error("invalid enum value " + in);
  13. }));
  14. py::implicitly_convertible<std::string, AdaptivePooling::Mode>();
  15. py::enum_<AdaptivePooling::Format>(AdaptivePoolingInst, "Format")
  16. .value("NCHW", AdaptivePooling::Format::NCHW)
  17. .value("NHWC", AdaptivePooling::Format::NHWC)
  18. .value("NHWCD4", AdaptivePooling::Format::NHWCD4)
  19. .value("NCHW4", AdaptivePooling::Format::NCHW4)
  20. .value("NCHW8", AdaptivePooling::Format::NCHW8)
  21. .value("NCHW32", AdaptivePooling::Format::NCHW32)
  22. .value("NCHW88", AdaptivePooling::Format::NCHW88)
  23. .value("NCHW44", AdaptivePooling::Format::NCHW44)
  24. .value("NCHW44_DOT", AdaptivePooling::Format::NCHW44_DOT)
  25. .value("NCHW4_NCHW32", AdaptivePooling::Format::NCHW4_NCHW32)
  26. .value("NCHW32_NCHW4", AdaptivePooling::Format::NCHW32_NCHW4)
  27. .value("NCHW4_NCHW", AdaptivePooling::Format::NCHW4_NCHW)
  28. .value("NHWC_NCHW", AdaptivePooling::Format::NHWC_NCHW)
  29. .value("NHWC_NCHW4_IC_SMALL", AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL)
  30. .value("NCHW_NCHW4_IC_SMALL", AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL)
  31. .value("CHWN4", AdaptivePooling::Format::CHWN4)
  32. .value("NCHW64", AdaptivePooling::Format::NCHW64)
  33. .value("NCHW4_NHWC", AdaptivePooling::Format::NCHW4_NHWC)
  34. .def(py::init([](const std::string& in) {
  35. auto&& str = normalize_enum(in);
  36. if (str == "NCHW") return AdaptivePooling::Format::NCHW;
  37. if (str == "NHWC") return AdaptivePooling::Format::NHWC;
  38. if (str == "NHWCD4") return AdaptivePooling::Format::NHWCD4;
  39. if (str == "NCHW4") return AdaptivePooling::Format::NCHW4;
  40. if (str == "NCHW8") return AdaptivePooling::Format::NCHW8;
  41. if (str == "NCHW32") return AdaptivePooling::Format::NCHW32;
  42. if (str == "NCHW88") return AdaptivePooling::Format::NCHW88;
  43. if (str == "NCHW44") return AdaptivePooling::Format::NCHW44;
  44. if (str == "NCHW44_DOT") return AdaptivePooling::Format::NCHW44_DOT;
  45. if (str == "NCHW4_NCHW32") return AdaptivePooling::Format::NCHW4_NCHW32;
  46. if (str == "NCHW32_NCHW4") return AdaptivePooling::Format::NCHW32_NCHW4;
  47. if (str == "NCHW4_NCHW") return AdaptivePooling::Format::NCHW4_NCHW;
  48. if (str == "NHWC_NCHW") return AdaptivePooling::Format::NHWC_NCHW;
  49. if (str == "NHWC_NCHW4_IC_SMALL") return AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL;
  50. if (str == "NCHW_NCHW4_IC_SMALL") return AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL;
  51. if (str == "CHWN4") return AdaptivePooling::Format::CHWN4;
  52. if (str == "NCHW64") return AdaptivePooling::Format::NCHW64;
  53. if (str == "NCHW4_NHWC") return AdaptivePooling::Format::NCHW4_NHWC;
  54. throw py::cast_error("invalid enum value " + in);
  55. }));
  56. py::implicitly_convertible<std::string, AdaptivePooling::Format>();
  57. AdaptivePoolingInst
  58. .def(py::init<::megdnn::param::AdaptivePooling::Mode, ::megdnn::param::AdaptivePooling::Format, std::vector<int32_t>, std::string>(), py::arg("mode") = ::megdnn::param::AdaptivePooling::Mode::MAX, py::arg("format") = ::megdnn::param::AdaptivePooling::Format::NCHW, py::arg("shape"), py::arg("scope") = {})
  59. .def(py::init<>())
  60. .def_readwrite("mode", &AdaptivePooling::mode)
  61. .def_readwrite("format", &AdaptivePooling::format)
  62. .def_readwrite("shape", &AdaptivePooling::shape);
  63. py::class_<AddAxis, std::shared_ptr<AddAxis>, OpDef> AddAxisInst(m, "AddAxis");
  64. AddAxisInst
  65. .def(py::init<std::vector<int32_t>, std::string>(), py::arg("axis"), py::arg("scope") = {})
  66. .def(py::init<>())
  67. .def_readwrite("axis", &AddAxis::axis);
  68. py::class_<Argmax, std::shared_ptr<Argmax>, OpDef> ArgmaxInst(m, "Argmax");
  69. ArgmaxInst
  70. .def(py::init<int32_t, std::string>(), py::arg("axis") = 0, py::arg("scope") = {})
  71. .def_readwrite("axis", &Argmax::axis);
  72. py::class_<Argmin, std::shared_ptr<Argmin>, OpDef> ArgminInst(m, "Argmin");
  73. ArgminInst
  74. .def(py::init<int32_t, std::string>(), py::arg("axis") = 0, py::arg("scope") = {})
  75. .def_readwrite("axis", &Argmin::axis);
  76. py::class_<Argsort, std::shared_ptr<Argsort>, OpDef> ArgsortInst(m, "Argsort");
  77. py::enum_<Argsort::Order>(ArgsortInst, "Order")
  78. .value("ASCENDING", Argsort::Order::ASCENDING)
  79. .value("DESCENDING", Argsort::Order::DESCENDING)
  80. .def(py::init([](const std::string& in) {
  81. auto&& str = normalize_enum(in);
  82. if (str == "ASCENDING") return Argsort::Order::ASCENDING;
  83. if (str == "DESCENDING") return Argsort::Order::DESCENDING;
  84. throw py::cast_error("invalid enum value " + in);
  85. }));
  86. py::implicitly_convertible<std::string, Argsort::Order>();
  87. ArgsortInst
  88. .def(py::init<::megdnn::param::Argsort::Order, std::string>(), py::arg("order") = ::megdnn::param::Argsort::Order::ASCENDING, py::arg("scope") = {})
  89. .def_readwrite("order", &Argsort::order);
  90. py::class_<AssertEqual, std::shared_ptr<AssertEqual>, OpDef> AssertEqualInst(m, "AssertEqual");
  91. AssertEqualInst
  92. .def(py::init<float, bool, std::string>(), py::arg("maxerr") = 0.0001, py::arg("verbose") = false, py::arg("scope") = {})
  93. .def_readwrite("maxerr", &AssertEqual::maxerr)
  94. .def_readwrite("verbose", &AssertEqual::verbose);
  95. py::class_<AtlasRuntime, std::shared_ptr<AtlasRuntime>, OpDef> AtlasRuntimeInst(m, "AtlasRuntime");
  96. AtlasRuntimeInst
  97. .def(py::init<std::string, size_t, std::string>(), py::arg("buf"), py::arg("buf_size"), py::arg("scope") = {})
  98. .def(py::init<>())
  99. .def_readwrite("buf", &AtlasRuntime::buf)
  100. .def_readwrite("buf_size", &AtlasRuntime::buf_size);
  101. py::class_<Barrier, std::shared_ptr<Barrier>, OpDef> BarrierInst(m, "Barrier");
  102. BarrierInst
  103. .def(py::init<::mgb::CompNode, uint32_t, std::string>(), py::arg("comp_node"), py::arg("nr_outputs"), py::arg("scope") = {})
  104. .def(py::init<>())
  105. .def_readwrite("comp_node", &Barrier::comp_node)
  106. .def_readwrite("nr_outputs", &Barrier::nr_outputs);
  107. py::class_<BatchConvBias, std::shared_ptr<BatchConvBias>, OpDef> BatchConvBiasInst(m, "BatchConvBias");
  108. py::enum_<BatchConvBias::NonlineMode>(BatchConvBiasInst, "NonlineMode")
  109. .value("IDENTITY", BatchConvBias::NonlineMode::IDENTITY)
  110. .value("RELU", BatchConvBias::NonlineMode::RELU)
  111. .value("SIGMOID", BatchConvBias::NonlineMode::SIGMOID)
  112. .value("H_SWISH", BatchConvBias::NonlineMode::H_SWISH)
  113. .def(py::init([](const std::string& in) {
  114. auto&& str = normalize_enum(in);
  115. if (str == "IDENTITY") return BatchConvBias::NonlineMode::IDENTITY;
  116. if (str == "RELU") return BatchConvBias::NonlineMode::RELU;
  117. if (str == "SIGMOID") return BatchConvBias::NonlineMode::SIGMOID;
  118. if (str == "H_SWISH") return BatchConvBias::NonlineMode::H_SWISH;
  119. throw py::cast_error("invalid enum value " + in);
  120. }));
  121. py::implicitly_convertible<std::string, BatchConvBias::NonlineMode>();
  122. py::enum_<BatchConvBias::Mode>(BatchConvBiasInst, "Mode")
  123. .value("CROSS_CORRELATION", BatchConvBias::Mode::CROSS_CORRELATION)
  124. .value("CONVOLUTION", BatchConvBias::Mode::CONVOLUTION)
  125. .def(py::init([](const std::string& in) {
  126. auto&& str = normalize_enum(in);
  127. if (str == "CROSS_CORRELATION") return BatchConvBias::Mode::CROSS_CORRELATION;
  128. if (str == "CONVOLUTION") return BatchConvBias::Mode::CONVOLUTION;
  129. throw py::cast_error("invalid enum value " + in);
  130. }));
  131. py::implicitly_convertible<std::string, BatchConvBias::Mode>();
  132. py::enum_<BatchConvBias::Sparse>(BatchConvBiasInst, "Sparse")
  133. .value("DENSE", BatchConvBias::Sparse::DENSE)
  134. .value("GROUP", BatchConvBias::Sparse::GROUP)
  135. .def(py::init([](const std::string& in) {
  136. auto&& str = normalize_enum(in);
  137. if (str == "DENSE") return BatchConvBias::Sparse::DENSE;
  138. if (str == "GROUP") return BatchConvBias::Sparse::GROUP;
  139. throw py::cast_error("invalid enum value " + in);
  140. }));
  141. py::implicitly_convertible<std::string, BatchConvBias::Sparse>();
  142. BatchConvBiasInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  143. py::enum_<BatchConvBias::ComputeMode>(BatchConvBiasInst, "ComputeMode")
  144. .value("DEFAULT", BatchConvBias::ComputeMode::DEFAULT)
  145. .value("FLOAT32", BatchConvBias::ComputeMode::FLOAT32)
  146. .def(py::init([](const std::string& in) {
  147. auto&& str = normalize_enum(in);
  148. if (str == "DEFAULT") return BatchConvBias::ComputeMode::DEFAULT;
  149. if (str == "FLOAT32") return BatchConvBias::ComputeMode::FLOAT32;
  150. throw py::cast_error("invalid enum value " + in);
  151. }));
  152. py::implicitly_convertible<std::string, BatchConvBias::ComputeMode>();
  153. py::enum_<BatchConvBias::Strategy>(BatchConvBiasInst, "Strategy")
  154. .value("HEURISTIC", BatchConvBias::Strategy::HEURISTIC)
  155. .value("PROFILE", BatchConvBias::Strategy::PROFILE)
  156. .value("REPRODUCIBLE", BatchConvBias::Strategy::REPRODUCIBLE)
  157. .value("OPTIMIZED", BatchConvBias::Strategy::OPTIMIZED)
  158. .def("__or__", [](BatchConvBias::Strategy s0, BatchConvBias::Strategy s1) {
  159. return static_cast<BatchConvBias::Strategy>(uint32_t(s0) | uint32_t(s1));
  160. })
  161. .def("__and__", [](BatchConvBias::Strategy s0, BatchConvBias::Strategy s1) {
  162. return static_cast<BatchConvBias::Strategy>(uint32_t(s0) & uint32_t(s1));
  163. })
  164. .def(py::init([](const std::string& in) {
  165. auto&& str = normalize_enum(in);
  166. if (str == "HEURISTIC") return BatchConvBias::Strategy::HEURISTIC;
  167. if (str == "PROFILE") return BatchConvBias::Strategy::PROFILE;
  168. if (str == "REPRODUCIBLE") return BatchConvBias::Strategy::REPRODUCIBLE;
  169. if (str == "OPTIMIZED") return BatchConvBias::Strategy::OPTIMIZED;
  170. throw py::cast_error("invalid enum value " + in);
  171. }));
  172. py::implicitly_convertible<std::string, BatchConvBias::Strategy>();
  173. BatchConvBiasInst
  174. .def(py::init<::megdnn::param::BatchConvBias::NonlineMode, ::megdnn::param::BatchConvBias::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::BatchConvBias::Sparse, ::megdnn::param::BatchConvBias::Format, ::megdnn::param::BatchConvBias::ComputeMode, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, ::megdnn::DType, std::string>(), py::arg("nonlineMode") = ::megdnn::param::BatchConvBias::NonlineMode::IDENTITY, py::arg("mode") = ::megdnn::param::BatchConvBias::Mode::CROSS_CORRELATION, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::BatchConvBias::Sparse::DENSE, py::arg("format") = ::megdnn::param::BatchConvBias::Format::NCHW, py::arg("compute_mode") = ::megdnn::param::BatchConvBias::ComputeMode::DEFAULT, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("dtype"), py::arg("scope") = {})
  175. .def(py::init<>())
  176. .def_readwrite("nonlineMode", &BatchConvBias::nonlineMode)
  177. .def_readwrite("mode", &BatchConvBias::mode)
  178. .def_readwrite("pad_h", &BatchConvBias::pad_h)
  179. .def_readwrite("pad_w", &BatchConvBias::pad_w)
  180. .def_readwrite("stride_h", &BatchConvBias::stride_h)
  181. .def_readwrite("stride_w", &BatchConvBias::stride_w)
  182. .def_readwrite("dilate_h", &BatchConvBias::dilate_h)
  183. .def_readwrite("dilate_w", &BatchConvBias::dilate_w)
  184. .def_readwrite("sparse", &BatchConvBias::sparse)
  185. .def_readwrite("format", &BatchConvBias::format)
  186. .def_readwrite("compute_mode", &BatchConvBias::compute_mode)
  187. .def_readwrite("strategy", &BatchConvBias::strategy)
  188. .def_readwrite("workspace_limit", &BatchConvBias::workspace_limit)
  189. .def_readwrite("dtype", &BatchConvBias::dtype);
  190. py::class_<BatchNorm, std::shared_ptr<BatchNorm>, OpDef> BatchNormInst(m, "BatchNorm");
  191. py::enum_<BatchNorm::ParamDim>(BatchNormInst, "ParamDim")
  192. .value("DIM_11HW", BatchNorm::ParamDim::DIM_11HW)
  193. .value("DIM_1CHW", BatchNorm::ParamDim::DIM_1CHW)
  194. .value("DIM_1C11", BatchNorm::ParamDim::DIM_1C11)
  195. .value("DIM_111C", BatchNorm::ParamDim::DIM_111C)
  196. .def(py::init([](const std::string& in) {
  197. auto&& str = normalize_enum(in);
  198. if (str == "DIM_11HW") return BatchNorm::ParamDim::DIM_11HW;
  199. if (str == "DIM_1CHW") return BatchNorm::ParamDim::DIM_1CHW;
  200. if (str == "DIM_1C11") return BatchNorm::ParamDim::DIM_1C11;
  201. if (str == "DIM_111C") return BatchNorm::ParamDim::DIM_111C;
  202. throw py::cast_error("invalid enum value " + in);
  203. }));
  204. py::implicitly_convertible<std::string, BatchNorm::ParamDim>();
  205. py::enum_<BatchNorm::FwdMode>(BatchNormInst, "FwdMode")
  206. .value("TRAINING", BatchNorm::FwdMode::TRAINING)
  207. .value("INFERENCE", BatchNorm::FwdMode::INFERENCE)
  208. .def(py::init([](const std::string& in) {
  209. auto&& str = normalize_enum(in);
  210. if (str == "TRAINING") return BatchNorm::FwdMode::TRAINING;
  211. if (str == "INFERENCE") return BatchNorm::FwdMode::INFERENCE;
  212. throw py::cast_error("invalid enum value " + in);
  213. }));
  214. py::implicitly_convertible<std::string, BatchNorm::FwdMode>();
  215. BatchNormInst
  216. .def(py::init<::megdnn::param::BN::ParamDim, ::megdnn::param::BN::FwdMode, double, double, float, float, std::string>(), py::arg("param_dim") = ::megdnn::param::BN::ParamDim::DIM_11HW, py::arg("fwd_mode") = ::megdnn::param::BN::FwdMode::TRAINING, py::arg("epsilon") = 1e-4f, py::arg("avg_factor") = 1.f, py::arg("scale") = 1.f, py::arg("bias") = 0.f, py::arg("scope") = {})
  217. .def_readwrite("param_dim", &BatchNorm::param_dim)
  218. .def_readwrite("fwd_mode", &BatchNorm::fwd_mode)
  219. .def_readwrite("epsilon", &BatchNorm::epsilon)
  220. .def_readwrite("avg_factor", &BatchNorm::avg_factor)
  221. .def_readwrite("scale", &BatchNorm::scale)
  222. .def_readwrite("bias", &BatchNorm::bias);
  223. py::class_<BatchNormBackward, std::shared_ptr<BatchNormBackward>, OpDef> BatchNormBackwardInst(m, "BatchNormBackward");
  224. BatchNormBackwardInst.attr("ParamDim") = BatchNormInst.attr("ParamDim");
  225. BatchNormBackwardInst.attr("FwdMode") = BatchNormInst.attr("FwdMode");
  226. BatchNormBackwardInst
  227. .def(py::init<::megdnn::param::BN::ParamDim, ::megdnn::param::BN::FwdMode, double, double, float, float, std::string>(), py::arg("param_dim") = ::megdnn::param::BN::ParamDim::DIM_11HW, py::arg("fwd_mode") = ::megdnn::param::BN::FwdMode::TRAINING, py::arg("epsilon") = 1e-4f, py::arg("avg_factor") = 1.f, py::arg("scale") = 1.f, py::arg("bias") = 0.f, py::arg("scope") = {})
  228. .def_readwrite("param_dim", &BatchNormBackward::param_dim)
  229. .def_readwrite("fwd_mode", &BatchNormBackward::fwd_mode)
  230. .def_readwrite("epsilon", &BatchNormBackward::epsilon)
  231. .def_readwrite("avg_factor", &BatchNormBackward::avg_factor)
  232. .def_readwrite("scale", &BatchNormBackward::scale)
  233. .def_readwrite("bias", &BatchNormBackward::bias);
  234. py::class_<BatchedIncrMeshIndexing, std::shared_ptr<BatchedIncrMeshIndexing>, OpDef> BatchedIncrMeshIndexingInst(m, "BatchedIncrMeshIndexing");
  235. BatchedIncrMeshIndexingInst
  236. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  237. .def(py::init<>())
  238. .def_readwrite("items", &BatchedIncrMeshIndexing::items);
  239. py::class_<BatchedMatrixMul, std::shared_ptr<BatchedMatrixMul>, OpDef> BatchedMatrixMulInst(m, "BatchedMatrixMul");
  240. py::enum_<BatchedMatrixMul::ComputeMode>(BatchedMatrixMulInst, "ComputeMode")
  241. .value("DEFAULT", BatchedMatrixMul::ComputeMode::DEFAULT)
  242. .value("FLOAT32", BatchedMatrixMul::ComputeMode::FLOAT32)
  243. .def(py::init([](const std::string& in) {
  244. auto&& str = normalize_enum(in);
  245. if (str == "DEFAULT") return BatchedMatrixMul::ComputeMode::DEFAULT;
  246. if (str == "FLOAT32") return BatchedMatrixMul::ComputeMode::FLOAT32;
  247. throw py::cast_error("invalid enum value " + in);
  248. }));
  249. py::implicitly_convertible<std::string, BatchedMatrixMul::ComputeMode>();
  250. py::enum_<BatchedMatrixMul::Format>(BatchedMatrixMulInst, "Format")
  251. .value("DEFAULT", BatchedMatrixMul::Format::DEFAULT)
  252. .value("MK4", BatchedMatrixMul::Format::MK4)
  253. .value("MK8", BatchedMatrixMul::Format::MK8)
  254. .value("MK4_DOT", BatchedMatrixMul::Format::MK4_DOT)
  255. .value("N32K4_DOT", BatchedMatrixMul::Format::N32K4_DOT)
  256. .def(py::init([](const std::string& in) {
  257. auto&& str = normalize_enum(in);
  258. if (str == "DEFAULT") return BatchedMatrixMul::Format::DEFAULT;
  259. if (str == "MK4") return BatchedMatrixMul::Format::MK4;
  260. if (str == "MK8") return BatchedMatrixMul::Format::MK8;
  261. if (str == "MK4_DOT") return BatchedMatrixMul::Format::MK4_DOT;
  262. if (str == "N32K4_DOT") return BatchedMatrixMul::Format::N32K4_DOT;
  263. throw py::cast_error("invalid enum value " + in);
  264. }));
  265. py::implicitly_convertible<std::string, BatchedMatrixMul::Format>();
  266. BatchedMatrixMulInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  267. BatchedMatrixMulInst
  268. .def(py::init<bool, bool, ::megdnn::param::MatrixMul::ComputeMode, ::megdnn::param::MatrixMul::Format, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, uint32_t, uint32_t, std::string>(), py::arg("transposeA") = false, py::arg("transposeB") = false, py::arg("compute_mode") = ::megdnn::param::MatrixMul::ComputeMode::DEFAULT, py::arg("format") = ::megdnn::param::MatrixMul::Format::DEFAULT, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("dimA"), py::arg("dimB"), py::arg("scope") = {})
  269. .def(py::init<>())
  270. .def_readwrite("transposeA", &BatchedMatrixMul::transposeA)
  271. .def_readwrite("transposeB", &BatchedMatrixMul::transposeB)
  272. .def_readwrite("compute_mode", &BatchedMatrixMul::compute_mode)
  273. .def_readwrite("format", &BatchedMatrixMul::format)
  274. .def_readwrite("strategy", &BatchedMatrixMul::strategy)
  275. .def_readwrite("workspace_limit", &BatchedMatrixMul::workspace_limit)
  276. .def_readwrite("dimA", &BatchedMatrixMul::dimA)
  277. .def_readwrite("dimB", &BatchedMatrixMul::dimB);
  278. py::class_<BatchedMeshIndexing, std::shared_ptr<BatchedMeshIndexing>, OpDef> BatchedMeshIndexingInst(m, "BatchedMeshIndexing");
  279. BatchedMeshIndexingInst
  280. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  281. .def(py::init<>())
  282. .def_readwrite("items", &BatchedMeshIndexing::items);
  283. py::class_<BatchedSetMeshIndexing, std::shared_ptr<BatchedSetMeshIndexing>, OpDef> BatchedSetMeshIndexingInst(m, "BatchedSetMeshIndexing");
  284. BatchedSetMeshIndexingInst
  285. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  286. .def(py::init<>())
  287. .def_readwrite("items", &BatchedSetMeshIndexing::items);
  288. py::class_<BetaRNG, std::shared_ptr<BetaRNG>, OpDef> BetaRNGInst(m, "BetaRNG");
  289. BetaRNGInst
  290. .def(py::init<uint64_t, size_t, std::string>(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {})
  291. .def(py::init<>())
  292. .def_readwrite("seed", &BetaRNG::seed)
  293. .def_readwrite("handle", &BetaRNG::handle);
  294. py::class_<Borrow, std::shared_ptr<Borrow>, OpDef> BorrowInst(m, "Borrow");
  295. BorrowInst
  296. .def(py::init<::mgb::CompNode, std::string>(), py::arg("comp_node"), py::arg("scope") = {})
  297. .def(py::init<>())
  298. .def_readwrite("comp_node", &Borrow::comp_node);
  299. py::class_<Broadcast, std::shared_ptr<Broadcast>, OpDef> BroadcastInst(m, "Broadcast");
  300. BroadcastInst
  301. .def(py::init<std::vector<int32_t>, std::string>(), py::arg("shape"), py::arg("scope") = {})
  302. .def(py::init<>())
  303. .def_readwrite("shape", &Broadcast::shape);
  304. py::class_<CambriconRuntime, std::shared_ptr<CambriconRuntime>, OpDef> CambriconRuntimeInst(m, "CambriconRuntime");
  305. CambriconRuntimeInst
  306. .def(py::init<std::string, size_t, std::string, bool, std::string>(), py::arg("buf"), py::arg("buf_size"), py::arg("symbol"), py::arg("tensor_dim_mutable"), py::arg("scope") = {})
  307. .def(py::init<>())
  308. .def_readwrite("buf", &CambriconRuntime::buf)
  309. .def_readwrite("buf_size", &CambriconRuntime::buf_size)
  310. .def_readwrite("symbol", &CambriconRuntime::symbol)
  311. .def_readwrite("tensor_dim_mutable", &CambriconRuntime::tensor_dim_mutable);
  312. py::class_<CheckNonFinite, std::shared_ptr<CheckNonFinite>, OpDef> CheckNonFiniteInst(m, "CheckNonFinite");
  313. CheckNonFiniteInst
  314. .def(py::init<float, std::string>(), py::arg("scale") = 1.0, py::arg("scope") = {})
  315. .def_readwrite("scale", &CheckNonFinite::scale);
  316. py::class_<CollectiveComm, std::shared_ptr<CollectiveComm>, OpDef> CollectiveCommInst(m, "CollectiveComm");
  317. py::enum_<CollectiveComm::Mode>(CollectiveCommInst, "Mode")
  318. .value("REDUCE_SUM", CollectiveComm::Mode::REDUCE_SUM)
  319. .value("BROADCAST", CollectiveComm::Mode::BROADCAST)
  320. .value("ALL_GATHER", CollectiveComm::Mode::ALL_GATHER)
  321. .value("REDUCE_SCATTER_SUM", CollectiveComm::Mode::REDUCE_SCATTER_SUM)
  322. .value("ALL_REDUCE_SUM", CollectiveComm::Mode::ALL_REDUCE_SUM)
  323. .value("ALL_REDUCE_MAX", CollectiveComm::Mode::ALL_REDUCE_MAX)
  324. .value("ALL_REDUCE_MIN", CollectiveComm::Mode::ALL_REDUCE_MIN)
  325. .value("ALL_REDUCE_PROD", CollectiveComm::Mode::ALL_REDUCE_PROD)
  326. .value("GATHER", CollectiveComm::Mode::GATHER)
  327. .value("SCATTER", CollectiveComm::Mode::SCATTER)
  328. .value("ALL_TO_ALL", CollectiveComm::Mode::ALL_TO_ALL)
  329. .def(py::init([](const std::string& in) {
  330. auto&& str = normalize_enum(in);
  331. if (str == "REDUCE_SUM") return CollectiveComm::Mode::REDUCE_SUM;
  332. if (str == "BROADCAST") return CollectiveComm::Mode::BROADCAST;
  333. if (str == "ALL_GATHER") return CollectiveComm::Mode::ALL_GATHER;
  334. if (str == "REDUCE_SCATTER_SUM") return CollectiveComm::Mode::REDUCE_SCATTER_SUM;
  335. if (str == "ALL_REDUCE_SUM") return CollectiveComm::Mode::ALL_REDUCE_SUM;
  336. if (str == "ALL_REDUCE_MAX") return CollectiveComm::Mode::ALL_REDUCE_MAX;
  337. if (str == "ALL_REDUCE_MIN") return CollectiveComm::Mode::ALL_REDUCE_MIN;
  338. if (str == "ALL_REDUCE_PROD") return CollectiveComm::Mode::ALL_REDUCE_PROD;
  339. if (str == "GATHER") return CollectiveComm::Mode::GATHER;
  340. if (str == "SCATTER") return CollectiveComm::Mode::SCATTER;
  341. if (str == "ALL_TO_ALL") return CollectiveComm::Mode::ALL_TO_ALL;
  342. throw py::cast_error("invalid enum value " + in);
  343. }));
  344. py::implicitly_convertible<std::string, CollectiveComm::Mode>();
  345. CollectiveCommInst
  346. .def(py::init<::megdnn::param::CollectiveComm::Mode, std::string, uint32_t, uint32_t, bool, bool, std::string, uint32_t, ::megdnn::DType, std::string, std::string, std::string>(), py::arg("mode") = ::megdnn::param::CollectiveComm::Mode::REDUCE_SUM, py::arg("key"), py::arg("nr_devices"), py::arg("rank"), py::arg("is_root"), py::arg("local_grad"), py::arg("addr"), py::arg("port"), py::arg("dtype"), py::arg("backend"), py::arg("comp_node"), py::arg("scope") = {})
  347. .def(py::init<>())
  348. .def_readwrite("mode", &CollectiveComm::mode)
  349. .def_readwrite("key", &CollectiveComm::key)
  350. .def_readwrite("nr_devices", &CollectiveComm::nr_devices)
  351. .def_readwrite("rank", &CollectiveComm::rank)
  352. .def_readwrite("is_root", &CollectiveComm::is_root)
  353. .def_readwrite("local_grad", &CollectiveComm::local_grad)
  354. .def_readwrite("addr", &CollectiveComm::addr)
  355. .def_readwrite("port", &CollectiveComm::port)
  356. .def_readwrite("dtype", &CollectiveComm::dtype)
  357. .def_readwrite("backend", &CollectiveComm::backend)
  358. .def_readwrite("comp_node", &CollectiveComm::comp_node);
  359. py::class_<Concat, std::shared_ptr<Concat>, OpDef> ConcatInst(m, "Concat");
  360. ConcatInst
  361. .def(py::init<int32_t, ::mgb::CompNode, std::string>(), py::arg("axis") = 0, py::arg("comp_node"), py::arg("scope") = {})
  362. .def(py::init<>())
  363. .def_readwrite("axis", &Concat::axis)
  364. .def_readwrite("comp_node", &Concat::comp_node);
  365. py::class_<CondTake, std::shared_ptr<CondTake>, OpDef> CondTakeInst(m, "CondTake");
  366. CondTakeInst
  367. .def(py::init<>());
  368. py::class_<ConvBias, std::shared_ptr<ConvBias>, OpDef> ConvBiasInst(m, "ConvBias");
  369. ConvBiasInst.attr("NonlineMode") = BatchConvBiasInst.attr("NonlineMode");
  370. ConvBiasInst.attr("Mode") = BatchConvBiasInst.attr("Mode");
  371. ConvBiasInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse");
  372. ConvBiasInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  373. ConvBiasInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode");
  374. ConvBiasInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  375. ConvBiasInst
  376. .def(py::init<::megdnn::param::ConvBias::NonlineMode, ::megdnn::param::ConvBias::Mode, ::megdnn::param::ConvBias::Sparse, ::megdnn::param::ConvBias::Format, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::ConvBias::ComputeMode, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, ::megdnn::DType, std::string>(), py::arg("nonlineMode") = ::megdnn::param::ConvBias::NonlineMode::IDENTITY, py::arg("mode") = ::megdnn::param::ConvBias::Mode::CROSS_CORRELATION, py::arg("sparse") = ::megdnn::param::ConvBias::Sparse::DENSE, py::arg("format") = ::megdnn::param::ConvBias::Format::NCHW, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("compute_mode") = ::megdnn::param::ConvBias::ComputeMode::DEFAULT, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("dtype"), py::arg("scope") = {})
  377. .def(py::init<>())
  378. .def_readwrite("nonlineMode", &ConvBias::nonlineMode)
  379. .def_readwrite("mode", &ConvBias::mode)
  380. .def_readwrite("sparse", &ConvBias::sparse)
  381. .def_readwrite("format", &ConvBias::format)
  382. .def_readwrite("pad_h", &ConvBias::pad_h)
  383. .def_readwrite("pad_w", &ConvBias::pad_w)
  384. .def_readwrite("stride_h", &ConvBias::stride_h)
  385. .def_readwrite("stride_w", &ConvBias::stride_w)
  386. .def_readwrite("dilate_h", &ConvBias::dilate_h)
  387. .def_readwrite("dilate_w", &ConvBias::dilate_w)
  388. .def_readwrite("compute_mode", &ConvBias::compute_mode)
  389. .def_readwrite("strategy", &ConvBias::strategy)
  390. .def_readwrite("workspace_limit", &ConvBias::workspace_limit)
  391. .def_readwrite("dtype", &ConvBias::dtype);
  392. py::class_<Convolution, std::shared_ptr<Convolution>, OpDef> ConvolutionInst(m, "Convolution");
  393. ConvolutionInst.attr("Mode") = BatchConvBiasInst.attr("Mode");
  394. ConvolutionInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse");
  395. ConvolutionInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  396. ConvolutionInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode");
  397. ConvolutionInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  398. ConvolutionInst
  399. .def(py::init<::megdnn::param::Convolution::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution::Sparse, ::megdnn::param::Convolution::Format, ::megdnn::param::Convolution::ComputeMode, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, std::string>(), py::arg("mode") = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution::Sparse::DENSE, py::arg("format") = ::megdnn::param::Convolution::Format::NCHW, py::arg("compute_mode") = ::megdnn::param::Convolution::ComputeMode::DEFAULT, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("scope") = {})
  400. .def_readwrite("mode", &Convolution::mode)
  401. .def_readwrite("pad_h", &Convolution::pad_h)
  402. .def_readwrite("pad_w", &Convolution::pad_w)
  403. .def_readwrite("stride_h", &Convolution::stride_h)
  404. .def_readwrite("stride_w", &Convolution::stride_w)
  405. .def_readwrite("dilate_h", &Convolution::dilate_h)
  406. .def_readwrite("dilate_w", &Convolution::dilate_w)
  407. .def_readwrite("sparse", &Convolution::sparse)
  408. .def_readwrite("format", &Convolution::format)
  409. .def_readwrite("compute_mode", &Convolution::compute_mode)
  410. .def_readwrite("strategy", &Convolution::strategy)
  411. .def_readwrite("workspace_limit", &Convolution::workspace_limit);
  412. py::class_<Convolution3D, std::shared_ptr<Convolution3D>, OpDef> Convolution3DInst(m, "Convolution3D");
  413. py::enum_<Convolution3D::Mode>(Convolution3DInst, "Mode")
  414. .value("CROSS_CORRELATION", Convolution3D::Mode::CROSS_CORRELATION)
  415. .value("CONVOLUTION", Convolution3D::Mode::CONVOLUTION)
  416. .def(py::init([](const std::string& in) {
  417. auto&& str = normalize_enum(in);
  418. if (str == "CROSS_CORRELATION") return Convolution3D::Mode::CROSS_CORRELATION;
  419. if (str == "CONVOLUTION") return Convolution3D::Mode::CONVOLUTION;
  420. throw py::cast_error("invalid enum value " + in);
  421. }));
  422. py::implicitly_convertible<std::string, Convolution3D::Mode>();
  423. py::enum_<Convolution3D::Sparse>(Convolution3DInst, "Sparse")
  424. .value("DENSE", Convolution3D::Sparse::DENSE)
  425. .value("GROUP", Convolution3D::Sparse::GROUP)
  426. .def(py::init([](const std::string& in) {
  427. auto&& str = normalize_enum(in);
  428. if (str == "DENSE") return Convolution3D::Sparse::DENSE;
  429. if (str == "GROUP") return Convolution3D::Sparse::GROUP;
  430. throw py::cast_error("invalid enum value " + in);
  431. }));
  432. py::implicitly_convertible<std::string, Convolution3D::Sparse>();
  433. py::enum_<Convolution3D::DataType>(Convolution3DInst, "DataType")
  434. .value("FLOAT", Convolution3D::DataType::FLOAT)
  435. .value("FLOAT_IO16xC32", Convolution3D::DataType::FLOAT_IO16xC32)
  436. .def(py::init([](const std::string& in) {
  437. auto&& str = normalize_enum(in);
  438. if (str == "FLOAT") return Convolution3D::DataType::FLOAT;
  439. if (str == "FLOAT_IO16xC32") return Convolution3D::DataType::FLOAT_IO16xC32;
  440. throw py::cast_error("invalid enum value " + in);
  441. }));
  442. py::implicitly_convertible<std::string, Convolution3D::DataType>();
  443. py::enum_<Convolution3D::Format>(Convolution3DInst, "Format")
  444. .value("NCDHW", Convolution3D::Format::NCDHW)
  445. .value("NDHWC", Convolution3D::Format::NDHWC)
  446. .def(py::init([](const std::string& in) {
  447. auto&& str = normalize_enum(in);
  448. if (str == "NCDHW") return Convolution3D::Format::NCDHW;
  449. if (str == "NDHWC") return Convolution3D::Format::NDHWC;
  450. throw py::cast_error("invalid enum value " + in);
  451. }));
  452. py::implicitly_convertible<std::string, Convolution3D::Format>();
  453. Convolution3DInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  454. Convolution3DInst
  455. .def(py::init<::megdnn::param::Convolution3D::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution3D::Sparse, ::megdnn::param::Convolution3D::DataType, ::megdnn::param::Convolution3D::Format, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, std::string>(), py::arg("mode") = ::megdnn::param::Convolution3D::Mode::CROSS_CORRELATION, py::arg("pad_d") = 0, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_d") = 1, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_d") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution3D::Sparse::DENSE, py::arg("data_type") = ::megdnn::param::Convolution3D::DataType::FLOAT, py::arg("format") = ::megdnn::param::Convolution3D::Format::NCDHW, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("scope") = {})
  456. .def_readwrite("mode", &Convolution3D::mode)
  457. .def_readwrite("pad_d", &Convolution3D::pad_d)
  458. .def_readwrite("pad_h", &Convolution3D::pad_h)
  459. .def_readwrite("pad_w", &Convolution3D::pad_w)
  460. .def_readwrite("stride_d", &Convolution3D::stride_d)
  461. .def_readwrite("stride_h", &Convolution3D::stride_h)
  462. .def_readwrite("stride_w", &Convolution3D::stride_w)
  463. .def_readwrite("dilate_d", &Convolution3D::dilate_d)
  464. .def_readwrite("dilate_h", &Convolution3D::dilate_h)
  465. .def_readwrite("dilate_w", &Convolution3D::dilate_w)
  466. .def_readwrite("sparse", &Convolution3D::sparse)
  467. .def_readwrite("data_type", &Convolution3D::data_type)
  468. .def_readwrite("format", &Convolution3D::format)
  469. .def_readwrite("strategy", &Convolution3D::strategy)
  470. .def_readwrite("workspace_limit", &Convolution3D::workspace_limit);
  471. py::class_<Convolution3DBackwardData, std::shared_ptr<Convolution3DBackwardData>, OpDef> Convolution3DBackwardDataInst(m, "Convolution3DBackwardData");
  472. Convolution3DBackwardDataInst.attr("Mode") = Convolution3DInst.attr("Mode");
  473. Convolution3DBackwardDataInst.attr("Sparse") = Convolution3DInst.attr("Sparse");
  474. Convolution3DBackwardDataInst.attr("DataType") = Convolution3DInst.attr("DataType");
  475. Convolution3DBackwardDataInst.attr("Format") = Convolution3DInst.attr("Format");
  476. Convolution3DBackwardDataInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  477. Convolution3DBackwardDataInst
  478. .def(py::init<::megdnn::param::Convolution3D::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution3D::Sparse, ::megdnn::param::Convolution3D::DataType, ::megdnn::param::Convolution3D::Format, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, std::string>(), py::arg("mode") = ::megdnn::param::Convolution3D::Mode::CROSS_CORRELATION, py::arg("pad_d") = 0, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_d") = 1, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_d") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution3D::Sparse::DENSE, py::arg("data_type") = ::megdnn::param::Convolution3D::DataType::FLOAT, py::arg("format") = ::megdnn::param::Convolution3D::Format::NCDHW, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("scope") = {})
  479. .def_readwrite("mode", &Convolution3DBackwardData::mode)
  480. .def_readwrite("pad_d", &Convolution3DBackwardData::pad_d)
  481. .def_readwrite("pad_h", &Convolution3DBackwardData::pad_h)
  482. .def_readwrite("pad_w", &Convolution3DBackwardData::pad_w)
  483. .def_readwrite("stride_d", &Convolution3DBackwardData::stride_d)
  484. .def_readwrite("stride_h", &Convolution3DBackwardData::stride_h)
  485. .def_readwrite("stride_w", &Convolution3DBackwardData::stride_w)
  486. .def_readwrite("dilate_d", &Convolution3DBackwardData::dilate_d)
  487. .def_readwrite("dilate_h", &Convolution3DBackwardData::dilate_h)
  488. .def_readwrite("dilate_w", &Convolution3DBackwardData::dilate_w)
  489. .def_readwrite("sparse", &Convolution3DBackwardData::sparse)
  490. .def_readwrite("data_type", &Convolution3DBackwardData::data_type)
  491. .def_readwrite("format", &Convolution3DBackwardData::format)
  492. .def_readwrite("strategy", &Convolution3DBackwardData::strategy)
  493. .def_readwrite("workspace_limit", &Convolution3DBackwardData::workspace_limit);
  494. py::class_<ConvolutionBackwardData, std::shared_ptr<ConvolutionBackwardData>, OpDef> ConvolutionBackwardDataInst(m, "ConvolutionBackwardData");
  495. ConvolutionBackwardDataInst.attr("Mode") = BatchConvBiasInst.attr("Mode");
  496. ConvolutionBackwardDataInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse");
  497. ConvolutionBackwardDataInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  498. ConvolutionBackwardDataInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode");
  499. ConvolutionBackwardDataInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  500. ConvolutionBackwardDataInst
  501. .def(py::init<::megdnn::param::Convolution::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution::Sparse, ::megdnn::param::Convolution::Format, ::megdnn::param::Convolution::ComputeMode, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, ::megdnn::DType, std::string>(), py::arg("mode") = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution::Sparse::DENSE, py::arg("format") = ::megdnn::param::Convolution::Format::NCHW, py::arg("compute_mode") = ::megdnn::param::Convolution::ComputeMode::DEFAULT, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("dtype"), py::arg("scope") = {})
  502. .def(py::init<>())
  503. .def_readwrite("mode", &ConvolutionBackwardData::mode)
  504. .def_readwrite("pad_h", &ConvolutionBackwardData::pad_h)
  505. .def_readwrite("pad_w", &ConvolutionBackwardData::pad_w)
  506. .def_readwrite("stride_h", &ConvolutionBackwardData::stride_h)
  507. .def_readwrite("stride_w", &ConvolutionBackwardData::stride_w)
  508. .def_readwrite("dilate_h", &ConvolutionBackwardData::dilate_h)
  509. .def_readwrite("dilate_w", &ConvolutionBackwardData::dilate_w)
  510. .def_readwrite("sparse", &ConvolutionBackwardData::sparse)
  511. .def_readwrite("format", &ConvolutionBackwardData::format)
  512. .def_readwrite("compute_mode", &ConvolutionBackwardData::compute_mode)
  513. .def_readwrite("strategy", &ConvolutionBackwardData::strategy)
  514. .def_readwrite("workspace_limit", &ConvolutionBackwardData::workspace_limit)
  515. .def_readwrite("dtype", &ConvolutionBackwardData::dtype);
  516. py::class_<Copy, std::shared_ptr<Copy>, OpDef> CopyInst(m, "Copy");
  517. CopyInst
  518. .def(py::init<::mgb::CompNode, std::string>(), py::arg("comp_node"), py::arg("scope") = {})
  519. .def(py::init<>())
  520. .def_readwrite("comp_node", &Copy::comp_node);
  521. py::class_<Correlation, std::shared_ptr<Correlation>, OpDef> CorrelationInst(m, "Correlation");
  522. py::enum_<Correlation::Format>(CorrelationInst, "Format")
  523. .value("NCHW", Correlation::Format::NCHW)
  524. .value("NHWC", Correlation::Format::NHWC)
  525. .value("NHWCD4", Correlation::Format::NHWCD4)
  526. .value("NCHW4", Correlation::Format::NCHW4)
  527. .value("NCHW8", Correlation::Format::NCHW8)
  528. .value("NCHW32", Correlation::Format::NCHW32)
  529. .value("NCHW88", Correlation::Format::NCHW88)
  530. .value("NCHW44", Correlation::Format::NCHW44)
  531. .value("NCHW44_DOT", Correlation::Format::NCHW44_DOT)
  532. .value("NCHW_WINOGRAD", Correlation::Format::NCHW_WINOGRAD)
  533. .value("NCHW88_WINOGRAD", Correlation::Format::NCHW88_WINOGRAD)
  534. .value("NCHW44_WINOGRAD", Correlation::Format::NCHW44_WINOGRAD)
  535. .value("NCHW4_NCHW32", Correlation::Format::NCHW4_NCHW32)
  536. .value("NCHW32_NCHW4", Correlation::Format::NCHW32_NCHW4)
  537. .value("NCHW4_NCHW", Correlation::Format::NCHW4_NCHW)
  538. .value("NHWC_NCHW", Correlation::Format::NHWC_NCHW)
  539. .value("NHWC_NCHW4_IC_SMALL", Correlation::Format::NHWC_NCHW4_IC_SMALL)
  540. .value("NCHW_NCHW4_IC_SMALL", Correlation::Format::NCHW_NCHW4_IC_SMALL)
  541. .value("CHWN4", Correlation::Format::CHWN4)
  542. .value("NCHW4_NHWC", Correlation::Format::NCHW4_NHWC)
  543. .def(py::init([](const std::string& in) {
  544. auto&& str = normalize_enum(in);
  545. if (str == "NCHW") return Correlation::Format::NCHW;
  546. if (str == "NHWC") return Correlation::Format::NHWC;
  547. if (str == "NHWCD4") return Correlation::Format::NHWCD4;
  548. if (str == "NCHW4") return Correlation::Format::NCHW4;
  549. if (str == "NCHW8") return Correlation::Format::NCHW8;
  550. if (str == "NCHW32") return Correlation::Format::NCHW32;
  551. if (str == "NCHW88") return Correlation::Format::NCHW88;
  552. if (str == "NCHW44") return Correlation::Format::NCHW44;
  553. if (str == "NCHW44_DOT") return Correlation::Format::NCHW44_DOT;
  554. if (str == "NCHW_WINOGRAD") return Correlation::Format::NCHW_WINOGRAD;
  555. if (str == "NCHW88_WINOGRAD") return Correlation::Format::NCHW88_WINOGRAD;
  556. if (str == "NCHW44_WINOGRAD") return Correlation::Format::NCHW44_WINOGRAD;
  557. if (str == "NCHW4_NCHW32") return Correlation::Format::NCHW4_NCHW32;
  558. if (str == "NCHW32_NCHW4") return Correlation::Format::NCHW32_NCHW4;
  559. if (str == "NCHW4_NCHW") return Correlation::Format::NCHW4_NCHW;
  560. if (str == "NHWC_NCHW") return Correlation::Format::NHWC_NCHW;
  561. if (str == "NHWC_NCHW4_IC_SMALL") return Correlation::Format::NHWC_NCHW4_IC_SMALL;
  562. if (str == "NCHW_NCHW4_IC_SMALL") return Correlation::Format::NCHW_NCHW4_IC_SMALL;
  563. if (str == "CHWN4") return Correlation::Format::CHWN4;
  564. if (str == "NCHW4_NHWC") return Correlation::Format::NCHW4_NHWC;
  565. throw py::cast_error("invalid enum value " + in);
  566. }));
  567. py::implicitly_convertible<std::string, Correlation::Format>();
  568. CorrelationInst
  569. .def(py::init<::megdnn::param::Correlation::Format, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, bool, std::string>(), py::arg("format") = ::megdnn::param::Correlation::Format::NCHW, py::arg("kernel_size") = 1, py::arg("max_displacement") = 1, py::arg("stride1") = 1, py::arg("stride2") = 1, py::arg("pad_size") = 0, py::arg("is_multiply") = true, py::arg("scope") = {})
  570. .def_readwrite("format", &Correlation::format)
  571. .def_readwrite("kernel_size", &Correlation::kernel_size)
  572. .def_readwrite("max_displacement", &Correlation::max_displacement)
  573. .def_readwrite("stride1", &Correlation::stride1)
  574. .def_readwrite("stride2", &Correlation::stride2)
  575. .def_readwrite("pad_size", &Correlation::pad_size)
  576. .def_readwrite("is_multiply", &Correlation::is_multiply);
  577. py::class_<Cumsum, std::shared_ptr<Cumsum>, OpDef> CumsumInst(m, "Cumsum");
  578. CumsumInst
  579. .def(py::init<int32_t, bool, bool, std::string>(), py::arg("axis") = 2147483647, py::arg("exclusive") = true, py::arg("reverse") = false, py::arg("scope") = {})
  580. .def_readwrite("axis", &Cumsum::axis)
  581. .def_readwrite("exclusive", &Cumsum::exclusive)
  582. .def_readwrite("reverse", &Cumsum::reverse);
  583. py::class_<CvtColor, std::shared_ptr<CvtColor>, OpDef> CvtColorInst(m, "CvtColor");
  584. py::enum_<CvtColor::Mode>(CvtColorInst, "Mode")
  585. .value("RGB2GRAY", CvtColor::Mode::RGB2GRAY)
  586. .value("RGB2YUV", CvtColor::Mode::RGB2YUV)
  587. .value("YUV2RGB", CvtColor::Mode::YUV2RGB)
  588. .value("GRAY2RGB", CvtColor::Mode::GRAY2RGB)
  589. .value("RGBA2RGB", CvtColor::Mode::RGBA2RGB)
  590. .value("RGBA2BGR", CvtColor::Mode::RGBA2BGR)
  591. .value("RGBA2GRAY", CvtColor::Mode::RGBA2GRAY)
  592. .value("RGB2BGR", CvtColor::Mode::RGB2BGR)
  593. .value("BGR2GRAY", CvtColor::Mode::BGR2GRAY)
  594. .value("BGR2RGB", CvtColor::Mode::BGR2RGB)
  595. .value("YUV2GRAY_NV21", CvtColor::Mode::YUV2GRAY_NV21)
  596. .value("YUV2RGB_NV21", CvtColor::Mode::YUV2RGB_NV21)
  597. .value("YUV2BGR_NV21", CvtColor::Mode::YUV2BGR_NV21)
  598. .value("YUV2GRAY_NV12", CvtColor::Mode::YUV2GRAY_NV12)
  599. .value("YUV2RGB_NV12", CvtColor::Mode::YUV2RGB_NV12)
  600. .value("YUV2BGR_NV12", CvtColor::Mode::YUV2BGR_NV12)
  601. .value("YUV2GRAY_YV12", CvtColor::Mode::YUV2GRAY_YV12)
  602. .value("YUV2RGB_YV12", CvtColor::Mode::YUV2RGB_YV12)
  603. .value("YUV2BGR_YV12", CvtColor::Mode::YUV2BGR_YV12)
  604. .value("YUV2GRAY_YU12", CvtColor::Mode::YUV2GRAY_YU12)
  605. .value("YUV2RGB_YU12", CvtColor::Mode::YUV2RGB_YU12)
  606. .value("YUV2BGR_YU12", CvtColor::Mode::YUV2BGR_YU12)
  607. .value("YCrCb2RGB", CvtColor::Mode::YCrCb2RGB)
  608. .value("YCrCb2BGR", CvtColor::Mode::YCrCb2BGR)
  609. .value("BT601_YUV2RGB_NV21", CvtColor::Mode::BT601_YUV2RGB_NV21)
  610. .value("BT601_YUV2BGR_NV21", CvtColor::Mode::BT601_YUV2BGR_NV21)
  611. .value("BT601_YUV2RGB_NV12", CvtColor::Mode::BT601_YUV2RGB_NV12)
  612. .value("BT601_YUV2BGR_NV12", CvtColor::Mode::BT601_YUV2BGR_NV12)
  613. .value("BT601_YUV2RGB_YV12", CvtColor::Mode::BT601_YUV2RGB_YV12)
  614. .value("BT601_YUV2BGR_YV12", CvtColor::Mode::BT601_YUV2BGR_YV12)
  615. .value("BT601_YUV2RGB_YU12", CvtColor::Mode::BT601_YUV2RGB_YU12)
  616. .value("BT601_YUV2BGR_YU12", CvtColor::Mode::BT601_YUV2BGR_YU12)
  617. .def(py::init([](const std::string& in) {
  618. auto&& str = normalize_enum(in);
  619. if (str == "RGB2GRAY") return CvtColor::Mode::RGB2GRAY;
  620. if (str == "RGB2YUV") return CvtColor::Mode::RGB2YUV;
  621. if (str == "YUV2RGB") return CvtColor::Mode::YUV2RGB;
  622. if (str == "GRAY2RGB") return CvtColor::Mode::GRAY2RGB;
  623. if (str == "RGBA2RGB") return CvtColor::Mode::RGBA2RGB;
  624. if (str == "RGBA2BGR") return CvtColor::Mode::RGBA2BGR;
  625. if (str == "RGBA2GRAY") return CvtColor::Mode::RGBA2GRAY;
  626. if (str == "RGB2BGR") return CvtColor::Mode::RGB2BGR;
  627. if (str == "BGR2GRAY") return CvtColor::Mode::BGR2GRAY;
  628. if (str == "BGR2RGB") return CvtColor::Mode::BGR2RGB;
  629. if (str == "YUV2GRAY_NV21") return CvtColor::Mode::YUV2GRAY_NV21;
  630. if (str == "YUV2RGB_NV21") return CvtColor::Mode::YUV2RGB_NV21;
  631. if (str == "YUV2BGR_NV21") return CvtColor::Mode::YUV2BGR_NV21;
  632. if (str == "YUV2GRAY_NV12") return CvtColor::Mode::YUV2GRAY_NV12;
  633. if (str == "YUV2RGB_NV12") return CvtColor::Mode::YUV2RGB_NV12;
  634. if (str == "YUV2BGR_NV12") return CvtColor::Mode::YUV2BGR_NV12;
  635. if (str == "YUV2GRAY_YV12") return CvtColor::Mode::YUV2GRAY_YV12;
  636. if (str == "YUV2RGB_YV12") return CvtColor::Mode::YUV2RGB_YV12;
  637. if (str == "YUV2BGR_YV12") return CvtColor::Mode::YUV2BGR_YV12;
  638. if (str == "YUV2GRAY_YU12") return CvtColor::Mode::YUV2GRAY_YU12;
  639. if (str == "YUV2RGB_YU12") return CvtColor::Mode::YUV2RGB_YU12;
  640. if (str == "YUV2BGR_YU12") return CvtColor::Mode::YUV2BGR_YU12;
  641. if (str == "YCrCb2RGB") return CvtColor::Mode::YCrCb2RGB;
  642. if (str == "YCrCb2BGR") return CvtColor::Mode::YCrCb2BGR;
  643. if (str == "BT601_YUV2RGB_NV21") return CvtColor::Mode::BT601_YUV2RGB_NV21;
  644. if (str == "BT601_YUV2BGR_NV21") return CvtColor::Mode::BT601_YUV2BGR_NV21;
  645. if (str == "BT601_YUV2RGB_NV12") return CvtColor::Mode::BT601_YUV2RGB_NV12;
  646. if (str == "BT601_YUV2BGR_NV12") return CvtColor::Mode::BT601_YUV2BGR_NV12;
  647. if (str == "BT601_YUV2RGB_YV12") return CvtColor::Mode::BT601_YUV2RGB_YV12;
  648. if (str == "BT601_YUV2BGR_YV12") return CvtColor::Mode::BT601_YUV2BGR_YV12;
  649. if (str == "BT601_YUV2RGB_YU12") return CvtColor::Mode::BT601_YUV2RGB_YU12;
  650. if (str == "BT601_YUV2BGR_YU12") return CvtColor::Mode::BT601_YUV2BGR_YU12;
  651. throw py::cast_error("invalid enum value " + in);
  652. }));
  653. py::implicitly_convertible<std::string, CvtColor::Mode>();
  654. CvtColorInst
  655. .def(py::init<::megdnn::param::CvtColor::Mode, std::string>(), py::arg("mode") = ::megdnn::param::CvtColor::Mode::RGB2GRAY, py::arg("scope") = {})
  656. .def_readwrite("mode", &CvtColor::mode);
  657. py::class_<DeformableConv, std::shared_ptr<DeformableConv>, OpDef> DeformableConvInst(m, "DeformableConv");
  658. DeformableConvInst.attr("Mode") = BatchConvBiasInst.attr("Mode");
  659. DeformableConvInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse");
  660. DeformableConvInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  661. DeformableConvInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode");
  662. DeformableConvInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  663. DeformableConvInst
  664. .def(py::init<::megdnn::param::Convolution::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution::Sparse, ::megdnn::param::Convolution::Format, ::megdnn::param::Convolution::ComputeMode, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, std::string>(), py::arg("mode") = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution::Sparse::DENSE, py::arg("format") = ::megdnn::param::Convolution::Format::NCHW, py::arg("compute_mode") = ::megdnn::param::Convolution::ComputeMode::DEFAULT, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("scope") = {})
  665. .def_readwrite("mode", &DeformableConv::mode)
  666. .def_readwrite("pad_h", &DeformableConv::pad_h)
  667. .def_readwrite("pad_w", &DeformableConv::pad_w)
  668. .def_readwrite("stride_h", &DeformableConv::stride_h)
  669. .def_readwrite("stride_w", &DeformableConv::stride_w)
  670. .def_readwrite("dilate_h", &DeformableConv::dilate_h)
  671. .def_readwrite("dilate_w", &DeformableConv::dilate_w)
  672. .def_readwrite("sparse", &DeformableConv::sparse)
  673. .def_readwrite("format", &DeformableConv::format)
  674. .def_readwrite("compute_mode", &DeformableConv::compute_mode)
  675. .def_readwrite("strategy", &DeformableConv::strategy)
  676. .def_readwrite("workspace_limit", &DeformableConv::workspace_limit);
  677. py::class_<DeformablePSROIPooling, std::shared_ptr<DeformablePSROIPooling>, OpDef> DeformablePSROIPoolingInst(m, "DeformablePSROIPooling");
  678. DeformablePSROIPoolingInst
  679. .def(py::init<bool, float, float, uint32_t, uint32_t, uint32_t, uint32_t, std::string>(), py::arg("no_trans") = true, py::arg("spatial_scale") = 1, py::arg("trans_std") = 1, py::arg("pooled_h") = 1, py::arg("pooled_w") = 1, py::arg("part_size") = 1, py::arg("sample_per_part") = 1, py::arg("scope") = {})
  680. .def_readwrite("no_trans", &DeformablePSROIPooling::no_trans)
  681. .def_readwrite("spatial_scale", &DeformablePSROIPooling::spatial_scale)
  682. .def_readwrite("trans_std", &DeformablePSROIPooling::trans_std)
  683. .def_readwrite("pooled_h", &DeformablePSROIPooling::pooled_h)
  684. .def_readwrite("pooled_w", &DeformablePSROIPooling::pooled_w)
  685. .def_readwrite("part_size", &DeformablePSROIPooling::part_size)
  686. .def_readwrite("sample_per_part", &DeformablePSROIPooling::sample_per_part);
  687. py::class_<Diag, std::shared_ptr<Diag>, OpDef> DiagInst(m, "Diag");
  688. DiagInst
  689. .def(py::init<int32_t, std::string>(), py::arg("k") = 0, py::arg("scope") = {})
  690. .def_readwrite("k", &Diag::k);
  691. py::class_<Dimshuffle, std::shared_ptr<Dimshuffle>, OpDef> DimshuffleInst(m, "Dimshuffle");
  692. DimshuffleInst
  693. .def(py::init<std::vector<int32_t>, std::string>(), py::arg("pattern"), py::arg("scope") = {})
  694. .def(py::init<>())
  695. .def_readwrite("pattern", &Dimshuffle::pattern);
  696. py::class_<Dot, std::shared_ptr<Dot>, OpDef> DotInst(m, "Dot");
  697. DotInst
  698. .def(py::init<>());
  699. py::class_<Dropout, std::shared_ptr<Dropout>, OpDef> DropoutInst(m, "Dropout");
  700. DropoutInst
  701. .def(py::init<float, uint64_t, size_t, std::string>(), py::arg("drop_prob") = 0, py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {})
  702. .def(py::init<>())
  703. .def_readwrite("drop_prob", &Dropout::drop_prob)
  704. .def_readwrite("seed", &Dropout::seed)
  705. .def_readwrite("handle", &Dropout::handle);
  706. py::class_<Elemwise, std::shared_ptr<Elemwise>, OpDef> ElemwiseInst(m, "Elemwise");
  707. py::enum_<Elemwise::Mode>(ElemwiseInst, "Mode")
  708. .value("RELU", Elemwise::Mode::RELU)
  709. .value("ABS", Elemwise::Mode::ABS)
  710. .value("ACOS", Elemwise::Mode::ACOS)
  711. .value("ASIN", Elemwise::Mode::ASIN)
  712. .value("CEIL", Elemwise::Mode::CEIL)
  713. .value("COS", Elemwise::Mode::COS)
  714. .value("EXP", Elemwise::Mode::EXP)
  715. .value("EXPM1", Elemwise::Mode::EXPM1)
  716. .value("FLOOR", Elemwise::Mode::FLOOR)
  717. .value("LOG", Elemwise::Mode::LOG)
  718. .value("LOG1P", Elemwise::Mode::LOG1P)
  719. .value("NEGATE", Elemwise::Mode::NEGATE)
  720. .value("SIGMOID", Elemwise::Mode::SIGMOID)
  721. .value("SIN", Elemwise::Mode::SIN)
  722. .value("TANH", Elemwise::Mode::TANH)
  723. .value("ABS_GRAD", Elemwise::Mode::ABS_GRAD)
  724. .value("ADD", Elemwise::Mode::ADD)
  725. .value("FLOOR_DIV", Elemwise::Mode::FLOOR_DIV)
  726. .value("MAX", Elemwise::Mode::MAX)
  727. .value("MIN", Elemwise::Mode::MIN)
  728. .value("MOD", Elemwise::Mode::MOD)
  729. .value("MUL", Elemwise::Mode::MUL)
  730. .value("POW", Elemwise::Mode::POW)
  731. .value("SIGMOID_GRAD", Elemwise::Mode::SIGMOID_GRAD)
  732. .value("SUB", Elemwise::Mode::SUB)
  733. .value("SWITCH_GT0", Elemwise::Mode::SWITCH_GT0)
  734. .value("TANH_GRAD", Elemwise::Mode::TANH_GRAD)
  735. .value("TRUE_DIV", Elemwise::Mode::TRUE_DIV)
  736. .value("LOG_SUM_EXP", Elemwise::Mode::LOG_SUM_EXP)
  737. .value("LT", Elemwise::Mode::LT)
  738. .value("LEQ", Elemwise::Mode::LEQ)
  739. .value("EQ", Elemwise::Mode::EQ)
  740. .value("SHL", Elemwise::Mode::SHL)
  741. .value("SHR", Elemwise::Mode::SHR)
  742. .value("COND_LEQ_MOV", Elemwise::Mode::COND_LEQ_MOV)
  743. .value("FUSE_MUL_ADD3", Elemwise::Mode::FUSE_MUL_ADD3)
  744. .value("FUSE_MUL_ADD4", Elemwise::Mode::FUSE_MUL_ADD4)
  745. .value("FUSE_ADD_RELU", Elemwise::Mode::FUSE_ADD_RELU)
  746. .value("FUSE_ADD_SIGMOID", Elemwise::Mode::FUSE_ADD_SIGMOID)
  747. .value("FUSE_ADD_TANH", Elemwise::Mode::FUSE_ADD_TANH)
  748. .value("FAST_TANH", Elemwise::Mode::FAST_TANH)
  749. .value("FAST_TANH_GRAD", Elemwise::Mode::FAST_TANH_GRAD)
  750. .value("ROUND", Elemwise::Mode::ROUND)
  751. .value("RMULH", Elemwise::Mode::RMULH)
  752. .value("ATAN2", Elemwise::Mode::ATAN2)
  753. .value("ERF", Elemwise::Mode::ERF)
  754. .value("ERFINV", Elemwise::Mode::ERFINV)
  755. .value("ERFC", Elemwise::Mode::ERFC)
  756. .value("ERFCINV", Elemwise::Mode::ERFCINV)
  757. .value("H_SWISH", Elemwise::Mode::H_SWISH)
  758. .value("H_SWISH_GRAD", Elemwise::Mode::H_SWISH_GRAD)
  759. .value("FUSE_ADD_H_SWISH", Elemwise::Mode::FUSE_ADD_H_SWISH)
  760. .value("NOT", Elemwise::Mode::NOT)
  761. .value("AND", Elemwise::Mode::AND)
  762. .value("OR", Elemwise::Mode::OR)
  763. .value("XOR", Elemwise::Mode::XOR)
  764. .value("SILU", Elemwise::Mode::SILU)
  765. .value("SILU_GRAD", Elemwise::Mode::SILU_GRAD)
  766. .value("GELU", Elemwise::Mode::GELU)
  767. .value("GELU_GRAD", Elemwise::Mode::GELU_GRAD)
  768. .value("COND_LT_MOV", Elemwise::Mode::COND_LT_MOV)
  769. .value("NEQ", Elemwise::Mode::NEQ)
  770. .value("ISNAN", Elemwise::Mode::ISNAN)
  771. .value("ISINF", Elemwise::Mode::ISINF)
  772. .def(py::init([](const std::string& in) {
  773. auto&& str = normalize_enum(in);
  774. if (str == "RELU") return Elemwise::Mode::RELU;
  775. if (str == "ABS") return Elemwise::Mode::ABS;
  776. if (str == "ACOS") return Elemwise::Mode::ACOS;
  777. if (str == "ASIN") return Elemwise::Mode::ASIN;
  778. if (str == "CEIL") return Elemwise::Mode::CEIL;
  779. if (str == "COS") return Elemwise::Mode::COS;
  780. if (str == "EXP") return Elemwise::Mode::EXP;
  781. if (str == "EXPM1") return Elemwise::Mode::EXPM1;
  782. if (str == "FLOOR") return Elemwise::Mode::FLOOR;
  783. if (str == "LOG") return Elemwise::Mode::LOG;
  784. if (str == "LOG1P") return Elemwise::Mode::LOG1P;
  785. if (str == "NEGATE") return Elemwise::Mode::NEGATE;
  786. if (str == "SIGMOID") return Elemwise::Mode::SIGMOID;
  787. if (str == "SIN") return Elemwise::Mode::SIN;
  788. if (str == "TANH") return Elemwise::Mode::TANH;
  789. if (str == "ABS_GRAD") return Elemwise::Mode::ABS_GRAD;
  790. if (str == "ADD") return Elemwise::Mode::ADD;
  791. if (str == "FLOOR_DIV") return Elemwise::Mode::FLOOR_DIV;
  792. if (str == "MAX") return Elemwise::Mode::MAX;
  793. if (str == "MIN") return Elemwise::Mode::MIN;
  794. if (str == "MOD") return Elemwise::Mode::MOD;
  795. if (str == "MUL") return Elemwise::Mode::MUL;
  796. if (str == "POW") return Elemwise::Mode::POW;
  797. if (str == "SIGMOID_GRAD") return Elemwise::Mode::SIGMOID_GRAD;
  798. if (str == "SUB") return Elemwise::Mode::SUB;
  799. if (str == "SWITCH_GT0") return Elemwise::Mode::SWITCH_GT0;
  800. if (str == "TANH_GRAD") return Elemwise::Mode::TANH_GRAD;
  801. if (str == "TRUE_DIV") return Elemwise::Mode::TRUE_DIV;
  802. if (str == "LOG_SUM_EXP") return Elemwise::Mode::LOG_SUM_EXP;
  803. if (str == "LT") return Elemwise::Mode::LT;
  804. if (str == "LEQ") return Elemwise::Mode::LEQ;
  805. if (str == "EQ") return Elemwise::Mode::EQ;
  806. if (str == "SHL") return Elemwise::Mode::SHL;
  807. if (str == "SHR") return Elemwise::Mode::SHR;
  808. if (str == "COND_LEQ_MOV") return Elemwise::Mode::COND_LEQ_MOV;
  809. if (str == "FUSE_MUL_ADD3") return Elemwise::Mode::FUSE_MUL_ADD3;
  810. if (str == "FUSE_MUL_ADD4") return Elemwise::Mode::FUSE_MUL_ADD4;
  811. if (str == "FUSE_ADD_RELU") return Elemwise::Mode::FUSE_ADD_RELU;
  812. if (str == "FUSE_ADD_SIGMOID") return Elemwise::Mode::FUSE_ADD_SIGMOID;
  813. if (str == "FUSE_ADD_TANH") return Elemwise::Mode::FUSE_ADD_TANH;
  814. if (str == "FAST_TANH") return Elemwise::Mode::FAST_TANH;
  815. if (str == "FAST_TANH_GRAD") return Elemwise::Mode::FAST_TANH_GRAD;
  816. if (str == "ROUND") return Elemwise::Mode::ROUND;
  817. if (str == "RMULH") return Elemwise::Mode::RMULH;
  818. if (str == "ATAN2") return Elemwise::Mode::ATAN2;
  819. if (str == "ERF") return Elemwise::Mode::ERF;
  820. if (str == "ERFINV") return Elemwise::Mode::ERFINV;
  821. if (str == "ERFC") return Elemwise::Mode::ERFC;
  822. if (str == "ERFCINV") return Elemwise::Mode::ERFCINV;
  823. if (str == "H_SWISH") return Elemwise::Mode::H_SWISH;
  824. if (str == "H_SWISH_GRAD") return Elemwise::Mode::H_SWISH_GRAD;
  825. if (str == "FUSE_ADD_H_SWISH") return Elemwise::Mode::FUSE_ADD_H_SWISH;
  826. if (str == "NOT") return Elemwise::Mode::NOT;
  827. if (str == "AND") return Elemwise::Mode::AND;
  828. if (str == "OR") return Elemwise::Mode::OR;
  829. if (str == "XOR") return Elemwise::Mode::XOR;
  830. if (str == "SILU") return Elemwise::Mode::SILU;
  831. if (str == "SILU_GRAD") return Elemwise::Mode::SILU_GRAD;
  832. if (str == "GELU") return Elemwise::Mode::GELU;
  833. if (str == "GELU_GRAD") return Elemwise::Mode::GELU_GRAD;
  834. if (str == "COND_LT_MOV") return Elemwise::Mode::COND_LT_MOV;
  835. if (str == "NEQ") return Elemwise::Mode::NEQ;
  836. if (str == "ISNAN") return Elemwise::Mode::ISNAN;
  837. if (str == "ISINF") return Elemwise::Mode::ISINF;
  838. throw py::cast_error("invalid enum value " + in);
  839. }));
  840. py::implicitly_convertible<std::string, Elemwise::Mode>();
  841. ElemwiseInst
  842. .def(py::init<::megdnn::param::Elemwise::Mode, std::string>(), py::arg("mode") = ::megdnn::param::Elemwise::Mode::RELU, py::arg("scope") = {})
  843. .def_readwrite("mode", &Elemwise::mode);
  844. py::class_<ElemwiseMultiType, std::shared_ptr<ElemwiseMultiType>, OpDef> ElemwiseMultiTypeInst(m, "ElemwiseMultiType");
  845. py::enum_<ElemwiseMultiType::Mode>(ElemwiseMultiTypeInst, "Mode")
  846. .value("FUSE_MUL_ADD3_INT16x32x32x32", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32)
  847. .value("FUSE_MUL_ADD3_IXxF32xF32xI8", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8)
  848. .value("ROUND_SHR_SATURATE_IXxI8xI8", ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8)
  849. .value("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8)
  850. .value("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8)
  851. .value("ROUND_SHR_SATURATE_IXxI8xI16", ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16)
  852. .value("QADD", ElemwiseMultiType::Mode::QADD)
  853. .value("QFUSE_ADD_RELU", ElemwiseMultiType::Mode::QFUSE_ADD_RELU)
  854. .value("QMUL", ElemwiseMultiType::Mode::QMUL)
  855. .value("QMIN", ElemwiseMultiType::Mode::QMIN)
  856. .value("QMAX", ElemwiseMultiType::Mode::QMAX)
  857. .value("QSUB", ElemwiseMultiType::Mode::QSUB)
  858. .value("QTRUE_DIV", ElemwiseMultiType::Mode::QTRUE_DIV)
  859. .value("QFUSE_ADD_SIGMOID", ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID)
  860. .value("QFUSE_ADD_TANH", ElemwiseMultiType::Mode::QFUSE_ADD_TANH)
  861. .value("QRELU", ElemwiseMultiType::Mode::QRELU)
  862. .value("QABS", ElemwiseMultiType::Mode::QABS)
  863. .value("QSIGMOID", ElemwiseMultiType::Mode::QSIGMOID)
  864. .value("QEXP", ElemwiseMultiType::Mode::QEXP)
  865. .value("QTANH", ElemwiseMultiType::Mode::QTANH)
  866. .value("QFUSE_MUL_ADD3", ElemwiseMultiType::Mode::QFUSE_MUL_ADD3)
  867. .value("QFAST_TANH", ElemwiseMultiType::Mode::QFAST_TANH)
  868. .value("QNEGATE", ElemwiseMultiType::Mode::QNEGATE)
  869. .value("QACOS", ElemwiseMultiType::Mode::QACOS)
  870. .value("QASIN", ElemwiseMultiType::Mode::QASIN)
  871. .value("QCEIL", ElemwiseMultiType::Mode::QCEIL)
  872. .value("QCOS", ElemwiseMultiType::Mode::QCOS)
  873. .value("QEXPM1", ElemwiseMultiType::Mode::QEXPM1)
  874. .value("QFLOOR", ElemwiseMultiType::Mode::QFLOOR)
  875. .value("QLOG", ElemwiseMultiType::Mode::QLOG)
  876. .value("QLOG1P", ElemwiseMultiType::Mode::QLOG1P)
  877. .value("QSIN", ElemwiseMultiType::Mode::QSIN)
  878. .value("QROUND", ElemwiseMultiType::Mode::QROUND)
  879. .value("QERF", ElemwiseMultiType::Mode::QERF)
  880. .value("QERFINV", ElemwiseMultiType::Mode::QERFINV)
  881. .value("QERFC", ElemwiseMultiType::Mode::QERFC)
  882. .value("QERFCINV", ElemwiseMultiType::Mode::QERFCINV)
  883. .value("QABS_GRAD", ElemwiseMultiType::Mode::QABS_GRAD)
  884. .value("QFLOOR_DIV", ElemwiseMultiType::Mode::QFLOOR_DIV)
  885. .value("QMOD", ElemwiseMultiType::Mode::QMOD)
  886. .value("QSIGMOID_GRAD", ElemwiseMultiType::Mode::QSIGMOID_GRAD)
  887. .value("QSWITCH_GT0", ElemwiseMultiType::Mode::QSWITCH_GT0)
  888. .value("QTANH_GRAD", ElemwiseMultiType::Mode::QTANH_GRAD)
  889. .value("QLT", ElemwiseMultiType::Mode::QLT)
  890. .value("QLEQ", ElemwiseMultiType::Mode::QLEQ)
  891. .value("QEQ", ElemwiseMultiType::Mode::QEQ)
  892. .value("QPOW", ElemwiseMultiType::Mode::QPOW)
  893. .value("QLOG_SUM_EXP", ElemwiseMultiType::Mode::QLOG_SUM_EXP)
  894. .value("QFAST_TANH_GRAD", ElemwiseMultiType::Mode::QFAST_TANH_GRAD)
  895. .value("QATAN2", ElemwiseMultiType::Mode::QATAN2)
  896. .value("QCOND_LEQ_MOV", ElemwiseMultiType::Mode::QCOND_LEQ_MOV)
  897. .value("QH_SWISH", ElemwiseMultiType::Mode::QH_SWISH)
  898. .value("QFUSE_ADD_H_SWISH", ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH)
  899. .value("QH_SWISH_GRAD", ElemwiseMultiType::Mode::QH_SWISH_GRAD)
  900. .value("FUSE_MUL_ADD3_INT16xF32xF32xF32", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32)
  901. .value("MUL_INT16xF32xF32", ElemwiseMultiType::Mode::MUL_INT16xF32xF32)
  902. .value("FUSE_MUL_ADD3_UINT8xF32xF32xF32", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32)
  903. .value("QCOND_LT_MOV", ElemwiseMultiType::Mode::QCOND_LT_MOV)
  904. .value("EQ", ElemwiseMultiType::Mode::EQ)
  905. .value("NEQ", ElemwiseMultiType::Mode::NEQ)
  906. .value("LT", ElemwiseMultiType::Mode::LT)
  907. .value("LEQ", ElemwiseMultiType::Mode::LEQ)
  908. .value("ISNAN", ElemwiseMultiType::Mode::ISNAN)
  909. .value("ISINF", ElemwiseMultiType::Mode::ISINF)
  910. .def(py::init([](const std::string& in) {
  911. auto&& str = normalize_enum(in);
  912. if (str == "FUSE_MUL_ADD3_INT16x32x32x32") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32;
  913. if (str == "FUSE_MUL_ADD3_IXxF32xF32xI8") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8;
  914. if (str == "ROUND_SHR_SATURATE_IXxI8xI8") return ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8;
  915. if (str == "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8") return ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8;
  916. if (str == "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8") return ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8;
  917. if (str == "ROUND_SHR_SATURATE_IXxI8xI16") return ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16;
  918. if (str == "QADD") return ElemwiseMultiType::Mode::QADD;
  919. if (str == "QFUSE_ADD_RELU") return ElemwiseMultiType::Mode::QFUSE_ADD_RELU;
  920. if (str == "QMUL") return ElemwiseMultiType::Mode::QMUL;
  921. if (str == "QMIN") return ElemwiseMultiType::Mode::QMIN;
  922. if (str == "QMAX") return ElemwiseMultiType::Mode::QMAX;
  923. if (str == "QSUB") return ElemwiseMultiType::Mode::QSUB;
  924. if (str == "QTRUE_DIV") return ElemwiseMultiType::Mode::QTRUE_DIV;
  925. if (str == "QFUSE_ADD_SIGMOID") return ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID;
  926. if (str == "QFUSE_ADD_TANH") return ElemwiseMultiType::Mode::QFUSE_ADD_TANH;
  927. if (str == "QRELU") return ElemwiseMultiType::Mode::QRELU;
  928. if (str == "QABS") return ElemwiseMultiType::Mode::QABS;
  929. if (str == "QSIGMOID") return ElemwiseMultiType::Mode::QSIGMOID;
  930. if (str == "QEXP") return ElemwiseMultiType::Mode::QEXP;
  931. if (str == "QTANH") return ElemwiseMultiType::Mode::QTANH;
  932. if (str == "QFUSE_MUL_ADD3") return ElemwiseMultiType::Mode::QFUSE_MUL_ADD3;
  933. if (str == "QFAST_TANH") return ElemwiseMultiType::Mode::QFAST_TANH;
  934. if (str == "QNEGATE") return ElemwiseMultiType::Mode::QNEGATE;
  935. if (str == "QACOS") return ElemwiseMultiType::Mode::QACOS;
  936. if (str == "QASIN") return ElemwiseMultiType::Mode::QASIN;
  937. if (str == "QCEIL") return ElemwiseMultiType::Mode::QCEIL;
  938. if (str == "QCOS") return ElemwiseMultiType::Mode::QCOS;
  939. if (str == "QEXPM1") return ElemwiseMultiType::Mode::QEXPM1;
  940. if (str == "QFLOOR") return ElemwiseMultiType::Mode::QFLOOR;
  941. if (str == "QLOG") return ElemwiseMultiType::Mode::QLOG;
  942. if (str == "QLOG1P") return ElemwiseMultiType::Mode::QLOG1P;
  943. if (str == "QSIN") return ElemwiseMultiType::Mode::QSIN;
  944. if (str == "QROUND") return ElemwiseMultiType::Mode::QROUND;
  945. if (str == "QERF") return ElemwiseMultiType::Mode::QERF;
  946. if (str == "QERFINV") return ElemwiseMultiType::Mode::QERFINV;
  947. if (str == "QERFC") return ElemwiseMultiType::Mode::QERFC;
  948. if (str == "QERFCINV") return ElemwiseMultiType::Mode::QERFCINV;
  949. if (str == "QABS_GRAD") return ElemwiseMultiType::Mode::QABS_GRAD;
  950. if (str == "QFLOOR_DIV") return ElemwiseMultiType::Mode::QFLOOR_DIV;
  951. if (str == "QMOD") return ElemwiseMultiType::Mode::QMOD;
  952. if (str == "QSIGMOID_GRAD") return ElemwiseMultiType::Mode::QSIGMOID_GRAD;
  953. if (str == "QSWITCH_GT0") return ElemwiseMultiType::Mode::QSWITCH_GT0;
  954. if (str == "QTANH_GRAD") return ElemwiseMultiType::Mode::QTANH_GRAD;
  955. if (str == "QLT") return ElemwiseMultiType::Mode::QLT;
  956. if (str == "QLEQ") return ElemwiseMultiType::Mode::QLEQ;
  957. if (str == "QEQ") return ElemwiseMultiType::Mode::QEQ;
  958. if (str == "QPOW") return ElemwiseMultiType::Mode::QPOW;
  959. if (str == "QLOG_SUM_EXP") return ElemwiseMultiType::Mode::QLOG_SUM_EXP;
  960. if (str == "QFAST_TANH_GRAD") return ElemwiseMultiType::Mode::QFAST_TANH_GRAD;
  961. if (str == "QATAN2") return ElemwiseMultiType::Mode::QATAN2;
  962. if (str == "QCOND_LEQ_MOV") return ElemwiseMultiType::Mode::QCOND_LEQ_MOV;
  963. if (str == "QH_SWISH") return ElemwiseMultiType::Mode::QH_SWISH;
  964. if (str == "QFUSE_ADD_H_SWISH") return ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH;
  965. if (str == "QH_SWISH_GRAD") return ElemwiseMultiType::Mode::QH_SWISH_GRAD;
  966. if (str == "FUSE_MUL_ADD3_INT16xF32xF32xF32") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32;
  967. if (str == "MUL_INT16xF32xF32") return ElemwiseMultiType::Mode::MUL_INT16xF32xF32;
  968. if (str == "FUSE_MUL_ADD3_UINT8xF32xF32xF32") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32;
  969. if (str == "QCOND_LT_MOV") return ElemwiseMultiType::Mode::QCOND_LT_MOV;
  970. if (str == "EQ") return ElemwiseMultiType::Mode::EQ;
  971. if (str == "NEQ") return ElemwiseMultiType::Mode::NEQ;
  972. if (str == "LT") return ElemwiseMultiType::Mode::LT;
  973. if (str == "LEQ") return ElemwiseMultiType::Mode::LEQ;
  974. if (str == "ISNAN") return ElemwiseMultiType::Mode::ISNAN;
  975. if (str == "ISINF") return ElemwiseMultiType::Mode::ISINF;
  976. throw py::cast_error("invalid enum value " + in);
  977. }));
  978. py::implicitly_convertible<std::string, ElemwiseMultiType::Mode>();
  979. ElemwiseMultiTypeInst
  980. .def(py::init<::megdnn::param::ElemwiseMultiType::Mode, ::megdnn::DType, std::string>(), py::arg("mode") = ::megdnn::param::ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32, py::arg("dtype"), py::arg("scope") = {})
  981. .def(py::init<>())
  982. .def_readwrite("mode", &ElemwiseMultiType::mode)
  983. .def_readwrite("dtype", &ElemwiseMultiType::dtype);
  984. py::class_<ExternOpr, std::shared_ptr<ExternOpr>, OpDef> ExternOprInst(m, "ExternOpr");
  985. ExternOprInst
  986. .def(py::init<std::vector<std::vector<size_t>>, std::string, std::string, size_t, std::vector<::megdnn::DType>, std::string>(), py::arg("output_shapes"), py::arg("name"), py::arg("data"), py::arg("data_len"), py::arg("output_dtypes"), py::arg("scope") = {})
  987. .def(py::init<>())
  988. .def_readwrite("output_shapes", &ExternOpr::output_shapes)
  989. .def_readwrite("name", &ExternOpr::name)
  990. .def_readwrite("data", &ExternOpr::data)
  991. .def_readwrite("data_len", &ExternOpr::data_len)
  992. .def_readwrite("output_dtypes", &ExternOpr::output_dtypes);
  993. py::class_<Eye, std::shared_ptr<Eye>, OpDef> EyeInst(m, "Eye");
  994. EyeInst
  995. .def(py::init<int32_t, ::megdnn::DType, ::mgb::CompNode, std::string>(), py::arg("k") = 0, py::arg("dtype") = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32), py::arg("comp_node"), py::arg("scope") = {})
  996. .def(py::init<>())
  997. .def_readwrite("k", &Eye::k)
  998. .def_readwrite("dtype", &Eye::dtype)
  999. .def_readwrite("comp_node", &Eye::comp_node);
  1000. py::class_<FakeQuant, std::shared_ptr<FakeQuant>, OpDef> FakeQuantInst(m, "FakeQuant");
  1001. FakeQuantInst
  1002. .def(py::init<int32_t, int32_t, std::string>(), py::arg("qmin") = -2147483648, py::arg("qmax") = 2147483647, py::arg("scope") = {})
  1003. .def_readwrite("qmin", &FakeQuant::qmin)
  1004. .def_readwrite("qmax", &FakeQuant::qmax);
  1005. py::class_<FastpathCopy, std::shared_ptr<FastpathCopy>, OpDef> FastpathCopyInst(m, "FastpathCopy");
  1006. FastpathCopyInst
  1007. .def(py::init<>());
  1008. py::class_<GammaRNG, std::shared_ptr<GammaRNG>, OpDef> GammaRNGInst(m, "GammaRNG");
  1009. GammaRNGInst
  1010. .def(py::init<uint64_t, size_t, std::string>(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {})
  1011. .def(py::init<>())
  1012. .def_readwrite("seed", &GammaRNG::seed)
  1013. .def_readwrite("handle", &GammaRNG::handle);
  1014. py::class_<GaussianRNG, std::shared_ptr<GaussianRNG>, OpDef> GaussianRNGInst(m, "GaussianRNG");
  1015. GaussianRNGInst
  1016. .def(py::init<uint64_t, float, float, ::megdnn::DType, size_t, std::string>(), py::arg("seed") = 0, py::arg("mean") = 0, py::arg("std") = 1, py::arg("dtype") = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32), py::arg("handle"), py::arg("scope") = {})
  1017. .def(py::init<>())
  1018. .def_readwrite("seed", &GaussianRNG::seed)
  1019. .def_readwrite("mean", &GaussianRNG::mean)
  1020. .def_readwrite("std", &GaussianRNG::std)
  1021. .def_readwrite("dtype", &GaussianRNG::dtype)
  1022. .def_readwrite("handle", &GaussianRNG::handle);
  1023. py::class_<GetVarShape, std::shared_ptr<GetVarShape>, OpDef> GetVarShapeInst(m, "GetVarShape");
  1024. GetVarShapeInst
  1025. .def(py::init<int32_t, std::string>(), py::arg("axis") = ::megdnn::param::OptionalAxisV1::INVALID_AXIS, py::arg("scope") = {})
  1026. .def_readwrite("axis", &GetVarShape::axis);
  1027. py::class_<GroupLocal, std::shared_ptr<GroupLocal>, OpDef> GroupLocalInst(m, "GroupLocal");
  1028. GroupLocalInst.attr("Mode") = BatchConvBiasInst.attr("Mode");
  1029. GroupLocalInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse");
  1030. GroupLocalInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1031. GroupLocalInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode");
  1032. GroupLocalInst
  1033. .def(py::init<::megdnn::param::Convolution::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution::Sparse, ::megdnn::param::Convolution::Format, ::megdnn::param::Convolution::ComputeMode, std::string>(), py::arg("mode") = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution::Sparse::DENSE, py::arg("format") = ::megdnn::param::Convolution::Format::NCHW, py::arg("compute_mode") = ::megdnn::param::Convolution::ComputeMode::DEFAULT, py::arg("scope") = {})
  1034. .def_readwrite("mode", &GroupLocal::mode)
  1035. .def_readwrite("pad_h", &GroupLocal::pad_h)
  1036. .def_readwrite("pad_w", &GroupLocal::pad_w)
  1037. .def_readwrite("stride_h", &GroupLocal::stride_h)
  1038. .def_readwrite("stride_w", &GroupLocal::stride_w)
  1039. .def_readwrite("dilate_h", &GroupLocal::dilate_h)
  1040. .def_readwrite("dilate_w", &GroupLocal::dilate_w)
  1041. .def_readwrite("sparse", &GroupLocal::sparse)
  1042. .def_readwrite("format", &GroupLocal::format)
  1043. .def_readwrite("compute_mode", &GroupLocal::compute_mode);
  1044. py::class_<GroupNorm, std::shared_ptr<GroupNorm>, OpDef> GroupNormInst(m, "GroupNorm");
  1045. GroupNormInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1046. GroupNormInst
  1047. .def(py::init<bool, float, uint32_t, ::megdnn::param::GroupNorm::Format, std::string>(), py::arg("affine") = true, py::arg("eps") = 1e-5f, py::arg("group") = 1, py::arg("format") = ::megdnn::param::GroupNorm::Format::NCHW, py::arg("scope") = {})
  1048. .def_readwrite("affine", &GroupNorm::affine)
  1049. .def_readwrite("eps", &GroupNorm::eps)
  1050. .def_readwrite("group", &GroupNorm::group)
  1051. .def_readwrite("format", &GroupNorm::format);
  1052. py::class_<Identity, std::shared_ptr<Identity>, OpDef> IdentityInst(m, "Identity");
  1053. IdentityInst
  1054. .def(py::init<>());
  1055. py::class_<Images2Neibs, std::shared_ptr<Images2Neibs>, OpDef> Images2NeibsInst(m, "Images2Neibs");
  1056. Images2NeibsInst
  1057. .def(py::init<uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, std::string>(), py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("window_h") = 3, py::arg("window_w") = 3, py::arg("scope") = {})
  1058. .def_readwrite("pad_h", &Images2Neibs::pad_h)
  1059. .def_readwrite("pad_w", &Images2Neibs::pad_w)
  1060. .def_readwrite("stride_h", &Images2Neibs::stride_h)
  1061. .def_readwrite("stride_w", &Images2Neibs::stride_w)
  1062. .def_readwrite("dilate_h", &Images2Neibs::dilate_h)
  1063. .def_readwrite("dilate_w", &Images2Neibs::dilate_w)
  1064. .def_readwrite("window_h", &Images2Neibs::window_h)
  1065. .def_readwrite("window_w", &Images2Neibs::window_w);
  1066. py::class_<IncrMeshIndexing, std::shared_ptr<IncrMeshIndexing>, OpDef> IncrMeshIndexingInst(m, "IncrMeshIndexing");
  1067. IncrMeshIndexingInst
  1068. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1069. .def(py::init<>())
  1070. .def_readwrite("items", &IncrMeshIndexing::items);
  1071. py::class_<IncrSubtensor, std::shared_ptr<IncrSubtensor>, OpDef> IncrSubtensorInst(m, "IncrSubtensor");
  1072. IncrSubtensorInst
  1073. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1074. .def(py::init<>())
  1075. .def_readwrite("items", &IncrSubtensor::items);
  1076. py::class_<IndexingIncrMultiAxisVec, std::shared_ptr<IndexingIncrMultiAxisVec>, OpDef> IndexingIncrMultiAxisVecInst(m, "IndexingIncrMultiAxisVec");
  1077. IndexingIncrMultiAxisVecInst
  1078. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1079. .def(py::init<>())
  1080. .def_readwrite("items", &IndexingIncrMultiAxisVec::items);
  1081. py::class_<IndexingMultiAxisVec, std::shared_ptr<IndexingMultiAxisVec>, OpDef> IndexingMultiAxisVecInst(m, "IndexingMultiAxisVec");
  1082. IndexingMultiAxisVecInst
  1083. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1084. .def(py::init<>())
  1085. .def_readwrite("items", &IndexingMultiAxisVec::items);
  1086. py::class_<IndexingOneHot, std::shared_ptr<IndexingOneHot>, OpDef> IndexingOneHotInst(m, "IndexingOneHot");
  1087. IndexingOneHotInst
  1088. .def(py::init<int32_t, int32_t, std::string>(), py::arg("axis") = 0, py::arg("ndim"), py::arg("scope") = {})
  1089. .def(py::init<>())
  1090. .def_readwrite("axis", &IndexingOneHot::axis)
  1091. .def_readwrite("ndim", &IndexingOneHot::ndim);
  1092. py::class_<IndexingSetMultiAxisVec, std::shared_ptr<IndexingSetMultiAxisVec>, OpDef> IndexingSetMultiAxisVecInst(m, "IndexingSetMultiAxisVec");
  1093. IndexingSetMultiAxisVecInst
  1094. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1095. .def(py::init<>())
  1096. .def_readwrite("items", &IndexingSetMultiAxisVec::items);
  1097. py::class_<IndexingSetOneHot, std::shared_ptr<IndexingSetOneHot>, OpDef> IndexingSetOneHotInst(m, "IndexingSetOneHot");
  1098. IndexingSetOneHotInst
  1099. .def(py::init<int32_t, int32_t, std::string>(), py::arg("axis") = 0, py::arg("ndim"), py::arg("scope") = {})
  1100. .def(py::init<>())
  1101. .def_readwrite("axis", &IndexingSetOneHot::axis)
  1102. .def_readwrite("ndim", &IndexingSetOneHot::ndim);
  1103. py::class_<InplaceAdd, std::shared_ptr<InplaceAdd>, OpDef> InplaceAddInst(m, "InplaceAdd");
  1104. InplaceAddInst
  1105. .def(py::init<>());
  1106. py::class_<LAMBUpdate, std::shared_ptr<LAMBUpdate>, OpDef> LAMBUpdateInst(m, "LAMBUpdate");
  1107. LAMBUpdateInst
  1108. .def(py::init<float, float, float, float, float, float, bool, bool, std::string>(), py::arg("beta_1") = 1.f, py::arg("beta_2") = 1.f, py::arg("step") = 1.f, py::arg("lr") = 1.f, py::arg("weight_decay") = 1.f, py::arg("eps") = 1.f, py::arg("bias_correction") = true, py::arg("always_adapt") = false, py::arg("scope") = {})
  1109. .def_readwrite("beta_1", &LAMBUpdate::beta_1)
  1110. .def_readwrite("beta_2", &LAMBUpdate::beta_2)
  1111. .def_readwrite("step", &LAMBUpdate::step)
  1112. .def_readwrite("lr", &LAMBUpdate::lr)
  1113. .def_readwrite("weight_decay", &LAMBUpdate::weight_decay)
  1114. .def_readwrite("eps", &LAMBUpdate::eps)
  1115. .def_readwrite("bias_correction", &LAMBUpdate::bias_correction)
  1116. .def_readwrite("always_adapt", &LAMBUpdate::always_adapt);
  1117. py::class_<LRN, std::shared_ptr<LRN>, OpDef> LRNInst(m, "LRN");
  1118. LRNInst
  1119. .def(py::init<uint32_t, float, float, float, std::string>(), py::arg("n") = 5, py::arg("k") = 2.f, py::arg("alpha") = 1e-4f, py::arg("beta") = 0.75f, py::arg("scope") = {})
  1120. .def_readwrite("n", &LRN::n)
  1121. .def_readwrite("k", &LRN::k)
  1122. .def_readwrite("alpha", &LRN::alpha)
  1123. .def_readwrite("beta", &LRN::beta);
  1124. py::class_<LSQ, std::shared_ptr<LSQ>, OpDef> LSQInst(m, "LSQ");
  1125. LSQInst
  1126. .def(py::init<int32_t, int32_t, std::string>(), py::arg("qmin") = -2147483648, py::arg("qmax") = 2147483647, py::arg("scope") = {})
  1127. .def_readwrite("qmin", &LSQ::qmin)
  1128. .def_readwrite("qmax", &LSQ::qmax);
  1129. py::class_<LSTM, std::shared_ptr<LSTM>, OpDef> LSTMInst(m, "LSTM");
  1130. LSTMInst.attr("FwdMode") = BatchNormInst.attr("FwdMode");
  1131. LSTMInst
  1132. .def(py::init<uint32_t, bool, bool, uint32_t, uint32_t, float, ::megdnn::param::LSTM::FwdMode, std::string>(), py::arg("num_layers") = 1, py::arg("bidirectional") = false, py::arg("bias") = true, py::arg("hidden_size") = 128, py::arg("proj_size") = 0, py::arg("dropout") = 0.f, py::arg("fwd_mode") = ::megdnn::param::LSTM::FwdMode::TRAINING, py::arg("scope") = {})
  1133. .def_readwrite("num_layers", &LSTM::num_layers)
  1134. .def_readwrite("bidirectional", &LSTM::bidirectional)
  1135. .def_readwrite("bias", &LSTM::bias)
  1136. .def_readwrite("hidden_size", &LSTM::hidden_size)
  1137. .def_readwrite("proj_size", &LSTM::proj_size)
  1138. .def_readwrite("dropout", &LSTM::dropout)
  1139. .def_readwrite("fwd_mode", &LSTM::fwd_mode);
  1140. py::class_<LSTMCell, std::shared_ptr<LSTMCell>, OpDef> LSTMCellInst(m, "LSTMCell");
  1141. LSTMCellInst
  1142. .def(py::init<>());
  1143. py::class_<LayerNorm, std::shared_ptr<LayerNorm>, OpDef> LayerNormInst(m, "LayerNorm");
  1144. LayerNormInst
  1145. .def(py::init<bool, float, uint64_t, uint64_t, std::string>(), py::arg("affine") = true, py::arg("eps") = 1e-5f, py::arg("normalized_dim") = 1, py::arg("normalized_size") = 1, py::arg("scope") = {})
  1146. .def_readwrite("affine", &LayerNorm::affine)
  1147. .def_readwrite("eps", &LayerNorm::eps)
  1148. .def_readwrite("normalized_dim", &LayerNorm::normalized_dim)
  1149. .def_readwrite("normalized_size", &LayerNorm::normalized_size);
  1150. py::class_<Linspace, std::shared_ptr<Linspace>, OpDef> LinspaceInst(m, "Linspace");
  1151. LinspaceInst
  1152. .def(py::init<bool, ::mgb::CompNode, std::string>(), py::arg("endpoint") = true, py::arg("comp_node"), py::arg("scope") = {})
  1153. .def(py::init<>())
  1154. .def_readwrite("endpoint", &Linspace::endpoint)
  1155. .def_readwrite("comp_node", &Linspace::comp_node);
  1156. py::class_<MagicMindRuntime, std::shared_ptr<MagicMindRuntime>, OpDef> MagicMindRuntimeInst(m, "MagicMindRuntime");
  1157. MagicMindRuntimeInst
  1158. .def(py::init<std::string, size_t, std::string>(), py::arg("buf"), py::arg("buf_size"), py::arg("scope") = {})
  1159. .def(py::init<>())
  1160. .def_readwrite("buf", &MagicMindRuntime::buf)
  1161. .def_readwrite("buf_size", &MagicMindRuntime::buf_size);
  1162. py::class_<MatrixInverse, std::shared_ptr<MatrixInverse>, OpDef> MatrixInverseInst(m, "MatrixInverse");
  1163. MatrixInverseInst
  1164. .def(py::init<>());
  1165. py::class_<MatrixMul, std::shared_ptr<MatrixMul>, OpDef> MatrixMulInst(m, "MatrixMul");
  1166. MatrixMulInst.attr("ComputeMode") = BatchedMatrixMulInst.attr("ComputeMode");
  1167. MatrixMulInst.attr("Format") = BatchedMatrixMulInst.attr("Format");
  1168. MatrixMulInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  1169. MatrixMulInst
  1170. .def(py::init<bool, bool, ::megdnn::param::MatrixMul::ComputeMode, ::megdnn::param::MatrixMul::Format, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, uint32_t, uint32_t, std::string>(), py::arg("transposeA") = false, py::arg("transposeB") = false, py::arg("compute_mode") = ::megdnn::param::MatrixMul::ComputeMode::DEFAULT, py::arg("format") = ::megdnn::param::MatrixMul::Format::DEFAULT, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("dimA"), py::arg("dimB"), py::arg("scope") = {})
  1171. .def(py::init<>())
  1172. .def_readwrite("transposeA", &MatrixMul::transposeA)
  1173. .def_readwrite("transposeB", &MatrixMul::transposeB)
  1174. .def_readwrite("compute_mode", &MatrixMul::compute_mode)
  1175. .def_readwrite("format", &MatrixMul::format)
  1176. .def_readwrite("strategy", &MatrixMul::strategy)
  1177. .def_readwrite("workspace_limit", &MatrixMul::workspace_limit)
  1178. .def_readwrite("dimA", &MatrixMul::dimA)
  1179. .def_readwrite("dimB", &MatrixMul::dimB);
  1180. py::class_<MeshGrid, std::shared_ptr<MeshGrid>, OpDef> MeshGridInst(m, "MeshGrid");
  1181. MeshGridInst
  1182. .def(py::init<std::string, std::string>(), py::arg("indexing"), py::arg("scope") = {})
  1183. .def(py::init<>())
  1184. .def_readwrite("indexing", &MeshGrid::indexing);
  1185. py::class_<MeshIndexing, std::shared_ptr<MeshIndexing>, OpDef> MeshIndexingInst(m, "MeshIndexing");
  1186. MeshIndexingInst
  1187. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1188. .def(py::init<>())
  1189. .def_readwrite("items", &MeshIndexing::items);
  1190. py::class_<NMSKeep, std::shared_ptr<NMSKeep>, OpDef> NMSKeepInst(m, "NMSKeep");
  1191. NMSKeepInst
  1192. .def(py::init<float, uint32_t, std::string>(), py::arg("iou_thresh"), py::arg("max_output"), py::arg("scope") = {})
  1193. .def(py::init<>())
  1194. .def_readwrite("iou_thresh", &NMSKeep::iou_thresh)
  1195. .def_readwrite("max_output", &NMSKeep::max_output);
  1196. py::class_<NvOf, std::shared_ptr<NvOf>, OpDef> NvOfInst(m, "NvOf");
  1197. NvOfInst
  1198. .def(py::init<uint32_t, std::string>(), py::arg("precision") = 1, py::arg("scope") = {})
  1199. .def_readwrite("precision", &NvOf::precision);
  1200. py::class_<Padding, std::shared_ptr<Padding>, OpDef> PaddingInst(m, "Padding");
  1201. py::enum_<Padding::PaddingMode>(PaddingInst, "PaddingMode")
  1202. .value("REPLICATE", Padding::PaddingMode::REPLICATE)
  1203. .value("REFLECT", Padding::PaddingMode::REFLECT)
  1204. .value("CONSTANT", Padding::PaddingMode::CONSTANT)
  1205. .def(py::init([](const std::string& in) {
  1206. auto&& str = normalize_enum(in);
  1207. if (str == "REPLICATE") return Padding::PaddingMode::REPLICATE;
  1208. if (str == "REFLECT") return Padding::PaddingMode::REFLECT;
  1209. if (str == "CONSTANT") return Padding::PaddingMode::CONSTANT;
  1210. throw py::cast_error("invalid enum value " + in);
  1211. }));
  1212. py::implicitly_convertible<std::string, Padding::PaddingMode>();
  1213. PaddingInst
  1214. .def(py::init<uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, float, ::megdnn::param::Padding::PaddingMode, std::string>(), py::arg("front_offset_dim0") = 0, py::arg("front_offset_dim1") = 0, py::arg("front_offset_dim2") = 0, py::arg("front_offset_dim3") = 0, py::arg("front_offset_dim4") = 0, py::arg("front_offset_dim5") = 0, py::arg("front_offset_dim6") = 0, py::arg("back_offset_dim0") = 0, py::arg("back_offset_dim1") = 0, py::arg("back_offset_dim2") = 0, py::arg("back_offset_dim3") = 0, py::arg("back_offset_dim4") = 0, py::arg("back_offset_dim5") = 0, py::arg("back_offset_dim6") = 0, py::arg("padding_val") = 0, py::arg("padding_mode") = ::megdnn::param::Padding::PaddingMode::CONSTANT, py::arg("scope") = {})
  1215. .def_readwrite("front_offset_dim0", &Padding::front_offset_dim0)
  1216. .def_readwrite("front_offset_dim1", &Padding::front_offset_dim1)
  1217. .def_readwrite("front_offset_dim2", &Padding::front_offset_dim2)
  1218. .def_readwrite("front_offset_dim3", &Padding::front_offset_dim3)
  1219. .def_readwrite("front_offset_dim4", &Padding::front_offset_dim4)
  1220. .def_readwrite("front_offset_dim5", &Padding::front_offset_dim5)
  1221. .def_readwrite("front_offset_dim6", &Padding::front_offset_dim6)
  1222. .def_readwrite("back_offset_dim0", &Padding::back_offset_dim0)
  1223. .def_readwrite("back_offset_dim1", &Padding::back_offset_dim1)
  1224. .def_readwrite("back_offset_dim2", &Padding::back_offset_dim2)
  1225. .def_readwrite("back_offset_dim3", &Padding::back_offset_dim3)
  1226. .def_readwrite("back_offset_dim4", &Padding::back_offset_dim4)
  1227. .def_readwrite("back_offset_dim5", &Padding::back_offset_dim5)
  1228. .def_readwrite("back_offset_dim6", &Padding::back_offset_dim6)
  1229. .def_readwrite("padding_val", &Padding::padding_val)
  1230. .def_readwrite("padding_mode", &Padding::padding_mode);
  1231. py::class_<ParamPackConcat, std::shared_ptr<ParamPackConcat>, OpDef> ParamPackConcatInst(m, "ParamPackConcat");
  1232. ParamPackConcatInst
  1233. .def(py::init<std::vector<int32_t>, std::string>(), py::arg("offsets"), py::arg("scope") = {})
  1234. .def(py::init<>())
  1235. .def_readwrite("offsets", &ParamPackConcat::offsets);
  1236. py::class_<ParamPackSplit, std::shared_ptr<ParamPackSplit>, OpDef> ParamPackSplitInst(m, "ParamPackSplit");
  1237. ParamPackSplitInst
  1238. .def(py::init<std::vector<int32_t>, std::vector<std::vector<size_t>>, std::string>(), py::arg("offsets"), py::arg("shapes"), py::arg("scope") = {})
  1239. .def(py::init<>())
  1240. .def_readwrite("offsets", &ParamPackSplit::offsets)
  1241. .def_readwrite("shapes", &ParamPackSplit::shapes);
  1242. py::class_<PermutationRNG, std::shared_ptr<PermutationRNG>, OpDef> PermutationRNGInst(m, "PermutationRNG");
  1243. PermutationRNGInst
  1244. .def(py::init<uint64_t, ::megdnn::DType, size_t, std::string>(), py::arg("seed") = 0, py::arg("dtype") = megdnn::DType::from_enum(megdnn::DTypeEnum::Int32), py::arg("handle"), py::arg("scope") = {})
  1245. .def(py::init<>())
  1246. .def_readwrite("seed", &PermutationRNG::seed)
  1247. .def_readwrite("dtype", &PermutationRNG::dtype)
  1248. .def_readwrite("handle", &PermutationRNG::handle);
  1249. py::class_<PixelShuffle, std::shared_ptr<PixelShuffle>, OpDef> PixelShuffleInst(m, "PixelShuffle");
  1250. PixelShuffleInst
  1251. .def(py::init<int32_t, std::string>(), py::arg("factor"), py::arg("scope") = {})
  1252. .def(py::init<>())
  1253. .def_readwrite("factor", &PixelShuffle::factor);
  1254. py::class_<PixelShuffleBackward, std::shared_ptr<PixelShuffleBackward>, OpDef> PixelShuffleBackwardInst(m, "PixelShuffleBackward");
  1255. PixelShuffleBackwardInst
  1256. .def(py::init<int32_t, std::string>(), py::arg("factor"), py::arg("scope") = {})
  1257. .def(py::init<>())
  1258. .def_readwrite("factor", &PixelShuffleBackward::factor);
  1259. py::class_<PoissonRNG, std::shared_ptr<PoissonRNG>, OpDef> PoissonRNGInst(m, "PoissonRNG");
  1260. PoissonRNGInst
  1261. .def(py::init<uint64_t, size_t, std::string>(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {})
  1262. .def(py::init<>())
  1263. .def_readwrite("seed", &PoissonRNG::seed)
  1264. .def_readwrite("handle", &PoissonRNG::handle);
  1265. py::class_<Pooling, std::shared_ptr<Pooling>, OpDef> PoolingInst(m, "Pooling");
  1266. PoolingInst.attr("Mode") = AdaptivePoolingInst.attr("Mode");
  1267. PoolingInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1268. PoolingInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy");
  1269. PoolingInst
  1270. .def(py::init<::megdnn::param::Pooling::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Pooling::Format, ::megdnn::param::ExecutionPolicy::Strategy, uint64_t, std::string>(), py::arg("mode") = ::megdnn::param::Pooling::Mode::MAX, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 2, py::arg("stride_w") = 2, py::arg("window_h") = 2, py::arg("window_w") = 2, py::arg("format") = ::megdnn::param::Pooling::Format::NCHW, py::arg("strategy") = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1), py::arg("workspace_limit") = 18446744073709551615ull, py::arg("scope") = {})
  1271. .def_readwrite("mode", &Pooling::mode)
  1272. .def_readwrite("pad_h", &Pooling::pad_h)
  1273. .def_readwrite("pad_w", &Pooling::pad_w)
  1274. .def_readwrite("stride_h", &Pooling::stride_h)
  1275. .def_readwrite("stride_w", &Pooling::stride_w)
  1276. .def_readwrite("window_h", &Pooling::window_h)
  1277. .def_readwrite("window_w", &Pooling::window_w)
  1278. .def_readwrite("format", &Pooling::format)
  1279. .def_readwrite("strategy", &Pooling::strategy)
  1280. .def_readwrite("workspace_limit", &Pooling::workspace_limit);
  1281. py::class_<RNN, std::shared_ptr<RNN>, OpDef> RNNInst(m, "RNN");
  1282. py::enum_<RNN::NonlineMode>(RNNInst, "NonlineMode")
  1283. .value("IDENTITY", RNN::NonlineMode::IDENTITY)
  1284. .value("RELU", RNN::NonlineMode::RELU)
  1285. .value("TANH", RNN::NonlineMode::TANH)
  1286. .def(py::init([](const std::string& in) {
  1287. auto&& str = normalize_enum(in);
  1288. if (str == "IDENTITY") return RNN::NonlineMode::IDENTITY;
  1289. if (str == "RELU") return RNN::NonlineMode::RELU;
  1290. if (str == "TANH") return RNN::NonlineMode::TANH;
  1291. throw py::cast_error("invalid enum value " + in);
  1292. }));
  1293. py::implicitly_convertible<std::string, RNN::NonlineMode>();
  1294. RNNInst.attr("FwdMode") = BatchNormInst.attr("FwdMode");
  1295. RNNInst
  1296. .def(py::init<uint32_t, bool, bool, uint32_t, float, ::megdnn::param::RNN::NonlineMode, ::megdnn::param::RNN::FwdMode, std::string>(), py::arg("num_layers") = 1, py::arg("bidirectional") = false, py::arg("bias") = true, py::arg("hidden_size") = 128, py::arg("dropout") = 0.f, py::arg("nonlineMode") = ::megdnn::param::RNN::NonlineMode::IDENTITY, py::arg("fwd_mode") = ::megdnn::param::RNN::FwdMode::TRAINING, py::arg("scope") = {})
  1297. .def_readwrite("num_layers", &RNN::num_layers)
  1298. .def_readwrite("bidirectional", &RNN::bidirectional)
  1299. .def_readwrite("bias", &RNN::bias)
  1300. .def_readwrite("hidden_size", &RNN::hidden_size)
  1301. .def_readwrite("dropout", &RNN::dropout)
  1302. .def_readwrite("nonlineMode", &RNN::nonlineMode)
  1303. .def_readwrite("fwd_mode", &RNN::fwd_mode);
  1304. py::class_<RNNCell, std::shared_ptr<RNNCell>, OpDef> RNNCellInst(m, "RNNCell");
  1305. RNNCellInst.attr("NonlineMode") = RNNInst.attr("NonlineMode");
  1306. RNNCellInst
  1307. .def(py::init<::megdnn::param::RNNCell::NonlineMode, std::string>(), py::arg("nonlineMode") = ::megdnn::param::RNNCell::NonlineMode::IDENTITY, py::arg("scope") = {})
  1308. .def_readwrite("nonlineMode", &RNNCell::nonlineMode);
  1309. py::class_<ROIAlign, std::shared_ptr<ROIAlign>, OpDef> ROIAlignInst(m, "ROIAlign");
  1310. py::enum_<ROIAlign::Mode>(ROIAlignInst, "Mode")
  1311. .value("MAX", ROIAlign::Mode::MAX)
  1312. .value("AVERAGE", ROIAlign::Mode::AVERAGE)
  1313. .def(py::init([](const std::string& in) {
  1314. auto&& str = normalize_enum(in);
  1315. if (str == "MAX") return ROIAlign::Mode::MAX;
  1316. if (str == "AVERAGE") return ROIAlign::Mode::AVERAGE;
  1317. throw py::cast_error("invalid enum value " + in);
  1318. }));
  1319. py::implicitly_convertible<std::string, ROIAlign::Mode>();
  1320. ROIAlignInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1321. ROIAlignInst
  1322. .def(py::init<::megdnn::param::ROIAlign::Mode, ::megdnn::param::ROIAlign::Format, float, float, uint32_t, uint32_t, uint32_t, uint32_t, std::string>(), py::arg("mode") = ::megdnn::param::ROIAlign::Mode::MAX, py::arg("format") = ::megdnn::param::ROIAlign::Format::NCHW, py::arg("spatial_scale") = 1.0, py::arg("offset") = 0.0, py::arg("pooled_height") = 1, py::arg("pooled_width") = 1, py::arg("sample_height") = 2, py::arg("sample_width") = 2, py::arg("scope") = {})
  1323. .def_readwrite("mode", &ROIAlign::mode)
  1324. .def_readwrite("format", &ROIAlign::format)
  1325. .def_readwrite("spatial_scale", &ROIAlign::spatial_scale)
  1326. .def_readwrite("offset", &ROIAlign::offset)
  1327. .def_readwrite("pooled_height", &ROIAlign::pooled_height)
  1328. .def_readwrite("pooled_width", &ROIAlign::pooled_width)
  1329. .def_readwrite("sample_height", &ROIAlign::sample_height)
  1330. .def_readwrite("sample_width", &ROIAlign::sample_width);
  1331. py::class_<ROIPooling, std::shared_ptr<ROIPooling>, OpDef> ROIPoolingInst(m, "ROIPooling");
  1332. py::enum_<ROIPooling::Mode>(ROIPoolingInst, "Mode")
  1333. .value("MAX", ROIPooling::Mode::MAX)
  1334. .value("AVERAGE", ROIPooling::Mode::AVERAGE)
  1335. .def(py::init([](const std::string& in) {
  1336. auto&& str = normalize_enum(in);
  1337. if (str == "MAX") return ROIPooling::Mode::MAX;
  1338. if (str == "AVERAGE") return ROIPooling::Mode::AVERAGE;
  1339. throw py::cast_error("invalid enum value " + in);
  1340. }));
  1341. py::implicitly_convertible<std::string, ROIPooling::Mode>();
  1342. ROIPoolingInst
  1343. .def(py::init<::megdnn::param::ROIPooling::Mode, float, std::string>(), py::arg("mode") = ::megdnn::param::ROIPooling::Mode::MAX, py::arg("scale") = 1.f, py::arg("scope") = {})
  1344. .def_readwrite("mode", &ROIPooling::mode)
  1345. .def_readwrite("scale", &ROIPooling::scale);
  1346. py::class_<Reduce, std::shared_ptr<Reduce>, OpDef> ReduceInst(m, "Reduce");
  1347. py::enum_<Reduce::Mode>(ReduceInst, "Mode")
  1348. .value("SUM", Reduce::Mode::SUM)
  1349. .value("SUM_SQR", Reduce::Mode::SUM_SQR)
  1350. .value("PRODUCT", Reduce::Mode::PRODUCT)
  1351. .value("MIN", Reduce::Mode::MIN)
  1352. .value("MAX", Reduce::Mode::MAX)
  1353. .value("MEAN", Reduce::Mode::MEAN)
  1354. .def(py::init([](const std::string& in) {
  1355. auto&& str = normalize_enum(in);
  1356. if (str == "SUM") return Reduce::Mode::SUM;
  1357. if (str == "SUM_SQR") return Reduce::Mode::SUM_SQR;
  1358. if (str == "PRODUCT") return Reduce::Mode::PRODUCT;
  1359. if (str == "MIN") return Reduce::Mode::MIN;
  1360. if (str == "MAX") return Reduce::Mode::MAX;
  1361. if (str == "MEAN") return Reduce::Mode::MEAN;
  1362. throw py::cast_error("invalid enum value " + in);
  1363. }));
  1364. py::implicitly_convertible<std::string, Reduce::Mode>();
  1365. py::enum_<Reduce::DataType>(ReduceInst, "DataType")
  1366. .value("DEFAULT", Reduce::DataType::DEFAULT)
  1367. .value("FLOAT_IO16xC32", Reduce::DataType::FLOAT_IO16xC32)
  1368. .value("FLOAT_O32xC32", Reduce::DataType::FLOAT_O32xC32)
  1369. .value("FLOAT_O16xC32", Reduce::DataType::FLOAT_O16xC32)
  1370. .value("QUINT_I8xO32", Reduce::DataType::QUINT_I8xO32)
  1371. .value("QINT_I8xO32", Reduce::DataType::QINT_I8xO32)
  1372. .def(py::init([](const std::string& in) {
  1373. auto&& str = normalize_enum(in);
  1374. if (str == "DEFAULT") return Reduce::DataType::DEFAULT;
  1375. if (str == "FLOAT_IO16xC32") return Reduce::DataType::FLOAT_IO16xC32;
  1376. if (str == "FLOAT_O32xC32") return Reduce::DataType::FLOAT_O32xC32;
  1377. if (str == "FLOAT_O16xC32") return Reduce::DataType::FLOAT_O16xC32;
  1378. if (str == "QUINT_I8xO32") return Reduce::DataType::QUINT_I8xO32;
  1379. if (str == "QINT_I8xO32") return Reduce::DataType::QINT_I8xO32;
  1380. throw py::cast_error("invalid enum value " + in);
  1381. }));
  1382. py::implicitly_convertible<std::string, Reduce::DataType>();
  1383. ReduceInst
  1384. .def(py::init<::megdnn::param::Reduce::Mode, int32_t, ::megdnn::param::Reduce::DataType, bool, std::string>(), py::arg("mode") = ::megdnn::param::Reduce::Mode::SUM, py::arg("axis") = 2147483647, py::arg("data_type") = ::megdnn::param::Reduce::DataType::DEFAULT, py::arg("keepdim") = true, py::arg("scope") = {})
  1385. .def_readwrite("mode", &Reduce::mode)
  1386. .def_readwrite("axis", &Reduce::axis)
  1387. .def_readwrite("data_type", &Reduce::data_type)
  1388. .def_readwrite("keepdim", &Reduce::keepdim);
  1389. py::class_<RegionRestrictedConvolution, std::shared_ptr<RegionRestrictedConvolution>, OpDef> RegionRestrictedConvolutionInst(m, "RegionRestrictedConvolution");
  1390. RegionRestrictedConvolutionInst.attr("Mode") = BatchConvBiasInst.attr("Mode");
  1391. RegionRestrictedConvolutionInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse");
  1392. RegionRestrictedConvolutionInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1393. RegionRestrictedConvolutionInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode");
  1394. RegionRestrictedConvolutionInst
  1395. .def(py::init<::megdnn::param::Convolution::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution::Sparse, ::megdnn::param::Convolution::Format, ::megdnn::param::Convolution::ComputeMode, std::string>(), py::arg("mode") = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution::Sparse::DENSE, py::arg("format") = ::megdnn::param::Convolution::Format::NCHW, py::arg("compute_mode") = ::megdnn::param::Convolution::ComputeMode::DEFAULT, py::arg("scope") = {})
  1396. .def_readwrite("mode", &RegionRestrictedConvolution::mode)
  1397. .def_readwrite("pad_h", &RegionRestrictedConvolution::pad_h)
  1398. .def_readwrite("pad_w", &RegionRestrictedConvolution::pad_w)
  1399. .def_readwrite("stride_h", &RegionRestrictedConvolution::stride_h)
  1400. .def_readwrite("stride_w", &RegionRestrictedConvolution::stride_w)
  1401. .def_readwrite("dilate_h", &RegionRestrictedConvolution::dilate_h)
  1402. .def_readwrite("dilate_w", &RegionRestrictedConvolution::dilate_w)
  1403. .def_readwrite("sparse", &RegionRestrictedConvolution::sparse)
  1404. .def_readwrite("format", &RegionRestrictedConvolution::format)
  1405. .def_readwrite("compute_mode", &RegionRestrictedConvolution::compute_mode);
  1406. py::class_<RegionRestrictedConvolutionBackwardData, std::shared_ptr<RegionRestrictedConvolutionBackwardData>, OpDef> RegionRestrictedConvolutionBackwardDataInst(m, "RegionRestrictedConvolutionBackwardData");
  1407. RegionRestrictedConvolutionBackwardDataInst.attr("Mode") = BatchConvBiasInst.attr("Mode");
  1408. RegionRestrictedConvolutionBackwardDataInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse");
  1409. RegionRestrictedConvolutionBackwardDataInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1410. RegionRestrictedConvolutionBackwardDataInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode");
  1411. RegionRestrictedConvolutionBackwardDataInst
  1412. .def(py::init<::megdnn::param::Convolution::Mode, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, ::megdnn::param::Convolution::Sparse, ::megdnn::param::Convolution::Format, ::megdnn::param::Convolution::ComputeMode, std::string>(), py::arg("mode") = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("sparse") = ::megdnn::param::Convolution::Sparse::DENSE, py::arg("format") = ::megdnn::param::Convolution::Format::NCHW, py::arg("compute_mode") = ::megdnn::param::Convolution::ComputeMode::DEFAULT, py::arg("scope") = {})
  1413. .def_readwrite("mode", &RegionRestrictedConvolutionBackwardData::mode)
  1414. .def_readwrite("pad_h", &RegionRestrictedConvolutionBackwardData::pad_h)
  1415. .def_readwrite("pad_w", &RegionRestrictedConvolutionBackwardData::pad_w)
  1416. .def_readwrite("stride_h", &RegionRestrictedConvolutionBackwardData::stride_h)
  1417. .def_readwrite("stride_w", &RegionRestrictedConvolutionBackwardData::stride_w)
  1418. .def_readwrite("dilate_h", &RegionRestrictedConvolutionBackwardData::dilate_h)
  1419. .def_readwrite("dilate_w", &RegionRestrictedConvolutionBackwardData::dilate_w)
  1420. .def_readwrite("sparse", &RegionRestrictedConvolutionBackwardData::sparse)
  1421. .def_readwrite("format", &RegionRestrictedConvolutionBackwardData::format)
  1422. .def_readwrite("compute_mode", &RegionRestrictedConvolutionBackwardData::compute_mode);
  1423. py::class_<Remap, std::shared_ptr<Remap>, OpDef> RemapInst(m, "Remap");
  1424. py::enum_<Remap::InterpolationMode>(RemapInst, "InterpolationMode")
  1425. .value("NEAREST", Remap::InterpolationMode::NEAREST)
  1426. .value("LINEAR", Remap::InterpolationMode::LINEAR)
  1427. .value("AREA", Remap::InterpolationMode::AREA)
  1428. .value("CUBIC", Remap::InterpolationMode::CUBIC)
  1429. .value("LANCZOS4", Remap::InterpolationMode::LANCZOS4)
  1430. .def(py::init([](const std::string& in) {
  1431. auto&& str = normalize_enum(in);
  1432. if (str == "NEAREST") return Remap::InterpolationMode::NEAREST;
  1433. if (str == "LINEAR") return Remap::InterpolationMode::LINEAR;
  1434. if (str == "AREA") return Remap::InterpolationMode::AREA;
  1435. if (str == "CUBIC") return Remap::InterpolationMode::CUBIC;
  1436. if (str == "LANCZOS4") return Remap::InterpolationMode::LANCZOS4;
  1437. throw py::cast_error("invalid enum value " + in);
  1438. }));
  1439. py::implicitly_convertible<std::string, Remap::InterpolationMode>();
  1440. py::enum_<Remap::BorderMode>(RemapInst, "BorderMode")
  1441. .value("REPLICATE", Remap::BorderMode::REPLICATE)
  1442. .value("REFLECT", Remap::BorderMode::REFLECT)
  1443. .value("REFLECT_101", Remap::BorderMode::REFLECT_101)
  1444. .value("WRAP", Remap::BorderMode::WRAP)
  1445. .value("CONSTANT", Remap::BorderMode::CONSTANT)
  1446. .value("TRANSPARENT", Remap::BorderMode::TRANSPARENT)
  1447. .value("ISOLATED", Remap::BorderMode::ISOLATED)
  1448. .def(py::init([](const std::string& in) {
  1449. auto&& str = normalize_enum(in);
  1450. if (str == "REPLICATE") return Remap::BorderMode::REPLICATE;
  1451. if (str == "REFLECT") return Remap::BorderMode::REFLECT;
  1452. if (str == "REFLECT_101") return Remap::BorderMode::REFLECT_101;
  1453. if (str == "WRAP") return Remap::BorderMode::WRAP;
  1454. if (str == "CONSTANT") return Remap::BorderMode::CONSTANT;
  1455. if (str == "TRANSPARENT") return Remap::BorderMode::TRANSPARENT;
  1456. if (str == "ISOLATED") return Remap::BorderMode::ISOLATED;
  1457. throw py::cast_error("invalid enum value " + in);
  1458. }));
  1459. py::implicitly_convertible<std::string, Remap::BorderMode>();
  1460. RemapInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1461. RemapInst
  1462. .def(py::init<::megdnn::param::Remap::InterpolationMode, ::megdnn::param::Remap::BorderMode, ::megdnn::param::Remap::Format, float, std::string>(), py::arg("imode") = ::megdnn::param::Remap::InterpolationMode::LINEAR, py::arg("border_type") = ::megdnn::param::Remap::BorderMode::REPLICATE, py::arg("format") = ::megdnn::param::Remap::Format::NHWC, py::arg("scalar") = 0.f, py::arg("scope") = {})
  1463. .def_readwrite("imode", &Remap::imode)
  1464. .def_readwrite("border_type", &Remap::border_type)
  1465. .def_readwrite("format", &Remap::format)
  1466. .def_readwrite("scalar", &Remap::scalar);
  1467. py::class_<RemoteRecv, std::shared_ptr<RemoteRecv>, OpDef> RemoteRecvInst(m, "RemoteRecv");
  1468. RemoteRecvInst
  1469. .def(py::init<std::string, std::string, uint32_t, uint32_t, ::mgb::CompNode, std::vector<int32_t>, ::megdnn::DType, std::string, std::string>(), py::arg("key"), py::arg("addr"), py::arg("port"), py::arg("rank_from"), py::arg("cn"), py::arg("shape"), py::arg("dtype"), py::arg("backend"), py::arg("scope") = {})
  1470. .def(py::init<>())
  1471. .def_readwrite("key", &RemoteRecv::key)
  1472. .def_readwrite("addr", &RemoteRecv::addr)
  1473. .def_readwrite("port", &RemoteRecv::port)
  1474. .def_readwrite("rank_from", &RemoteRecv::rank_from)
  1475. .def_readwrite("cn", &RemoteRecv::cn)
  1476. .def_readwrite("shape", &RemoteRecv::shape)
  1477. .def_readwrite("dtype", &RemoteRecv::dtype)
  1478. .def_readwrite("backend", &RemoteRecv::backend);
  1479. py::class_<RemoteSend, std::shared_ptr<RemoteSend>, OpDef> RemoteSendInst(m, "RemoteSend");
  1480. RemoteSendInst
  1481. .def(py::init<std::string, std::string, uint32_t, uint32_t, std::string, std::string>(), py::arg("key"), py::arg("addr"), py::arg("port"), py::arg("rank_to"), py::arg("backend"), py::arg("scope") = {})
  1482. .def(py::init<>())
  1483. .def_readwrite("key", &RemoteSend::key)
  1484. .def_readwrite("addr", &RemoteSend::addr)
  1485. .def_readwrite("port", &RemoteSend::port)
  1486. .def_readwrite("rank_to", &RemoteSend::rank_to)
  1487. .def_readwrite("backend", &RemoteSend::backend);
  1488. py::class_<RemoveAxis, std::shared_ptr<RemoveAxis>, OpDef> RemoveAxisInst(m, "RemoveAxis");
  1489. RemoveAxisInst
  1490. .def(py::init<std::vector<int32_t>, std::string>(), py::arg("axis"), py::arg("scope") = {})
  1491. .def(py::init<>())
  1492. .def_readwrite("axis", &RemoveAxis::axis);
  1493. py::class_<Reshape, std::shared_ptr<Reshape>, OpDef> ReshapeInst(m, "Reshape");
  1494. ReshapeInst
  1495. .def(py::init<int32_t, std::vector<int32_t>, std::string>(), py::arg("axis") = ::megdnn::param::OptionalAxisV1::INVALID_AXIS, py::arg("shape"), py::arg("scope") = {})
  1496. .def(py::init<>())
  1497. .def_readwrite("axis", &Reshape::axis)
  1498. .def_readwrite("shape", &Reshape::shape);
  1499. py::class_<Resize, std::shared_ptr<Resize>, OpDef> ResizeInst(m, "Resize");
  1500. ResizeInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode");
  1501. ResizeInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1502. ResizeInst
  1503. .def(py::init<::megdnn::param::Resize::InterpolationMode, ::megdnn::param::Resize::Format, std::string>(), py::arg("imode") = ::megdnn::param::Resize::InterpolationMode::LINEAR, py::arg("format") = ::megdnn::param::Resize::Format::NHWC, py::arg("scope") = {})
  1504. .def_readwrite("imode", &Resize::imode)
  1505. .def_readwrite("format", &Resize::format);
  1506. py::class_<SVD, std::shared_ptr<SVD>, OpDef> SVDInst(m, "SVD");
  1507. SVDInst
  1508. .def(py::init<bool, bool, std::string>(), py::arg("full_matrices") = false, py::arg("compute_uv") = true, py::arg("scope") = {})
  1509. .def_readwrite("full_matrices", &SVD::full_matrices)
  1510. .def_readwrite("compute_uv", &SVD::compute_uv);
  1511. py::class_<SetMeshIndexing, std::shared_ptr<SetMeshIndexing>, OpDef> SetMeshIndexingInst(m, "SetMeshIndexing");
  1512. SetMeshIndexingInst
  1513. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1514. .def(py::init<>())
  1515. .def_readwrite("items", &SetMeshIndexing::items);
  1516. py::class_<SetSubtensor, std::shared_ptr<SetSubtensor>, OpDef> SetSubtensorInst(m, "SetSubtensor");
  1517. SetSubtensorInst
  1518. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1519. .def(py::init<>())
  1520. .def_readwrite("items", &SetSubtensor::items);
  1521. py::class_<ShuffleRNG, std::shared_ptr<ShuffleRNG>, OpDef> ShuffleRNGInst(m, "ShuffleRNG");
  1522. ShuffleRNGInst
  1523. .def(py::init<uint64_t, size_t, std::string>(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {})
  1524. .def(py::init<>())
  1525. .def_readwrite("seed", &ShuffleRNG::seed)
  1526. .def_readwrite("handle", &ShuffleRNG::handle);
  1527. py::class_<SlidingWindowTranspose, std::shared_ptr<SlidingWindowTranspose>, OpDef> SlidingWindowTransposeInst(m, "SlidingWindowTranspose");
  1528. SlidingWindowTransposeInst
  1529. .def(py::init<uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, std::string>(), py::arg("out_h") = 0, py::arg("out_w") = 0, py::arg("pad_h") = 0, py::arg("pad_w") = 0, py::arg("stride_h") = 1, py::arg("stride_w") = 1, py::arg("dilate_h") = 1, py::arg("dilate_w") = 1, py::arg("window_h") = 3, py::arg("window_w") = 3, py::arg("scope") = {})
  1530. .def_readwrite("out_h", &SlidingWindowTranspose::out_h)
  1531. .def_readwrite("out_w", &SlidingWindowTranspose::out_w)
  1532. .def_readwrite("pad_h", &SlidingWindowTranspose::pad_h)
  1533. .def_readwrite("pad_w", &SlidingWindowTranspose::pad_w)
  1534. .def_readwrite("stride_h", &SlidingWindowTranspose::stride_h)
  1535. .def_readwrite("stride_w", &SlidingWindowTranspose::stride_w)
  1536. .def_readwrite("dilate_h", &SlidingWindowTranspose::dilate_h)
  1537. .def_readwrite("dilate_w", &SlidingWindowTranspose::dilate_w)
  1538. .def_readwrite("window_h", &SlidingWindowTranspose::window_h)
  1539. .def_readwrite("window_w", &SlidingWindowTranspose::window_w);
  1540. py::class_<Softmax, std::shared_ptr<Softmax>, OpDef> SoftmaxInst(m, "Softmax");
  1541. SoftmaxInst
  1542. .def(py::init<int32_t, std::string>(), py::arg("axis") = -1, py::arg("scope") = {})
  1543. .def_readwrite("axis", &Softmax::axis);
  1544. py::class_<Split, std::shared_ptr<Split>, OpDef> SplitInst(m, "Split");
  1545. SplitInst
  1546. .def(py::init<int32_t, int32_t, std::string>(), py::arg("axis"), py::arg("nsections"), py::arg("scope") = {})
  1547. .def(py::init<>())
  1548. .def_readwrite("axis", &Split::axis)
  1549. .def_readwrite("nsections", &Split::nsections);
  1550. py::class_<Subtensor, std::shared_ptr<Subtensor>, OpDef> SubtensorInst(m, "Subtensor");
  1551. SubtensorInst
  1552. .def(py::init<std::vector<std::tuple<int8_t, bool, bool, bool, bool>>, std::string>(), py::arg("items"), py::arg("scope") = {})
  1553. .def(py::init<>())
  1554. .def_readwrite("items", &Subtensor::items);
  1555. py::class_<TQT, std::shared_ptr<TQT>, OpDef> TQTInst(m, "TQT");
  1556. TQTInst
  1557. .def(py::init<int32_t, int32_t, std::string>(), py::arg("qmin") = -2147483648, py::arg("qmax") = 2147483647, py::arg("scope") = {})
  1558. .def_readwrite("qmin", &TQT::qmin)
  1559. .def_readwrite("qmax", &TQT::qmax);
  1560. py::class_<TensorRTRuntime, std::shared_ptr<TensorRTRuntime>, OpDef> TensorRTRuntimeInst(m, "TensorRTRuntime");
  1561. TensorRTRuntimeInst
  1562. .def(py::init<std::string, size_t, std::string>(), py::arg("buf"), py::arg("buf_size"), py::arg("scope") = {})
  1563. .def(py::init<>())
  1564. .def_readwrite("buf", &TensorRTRuntime::buf)
  1565. .def_readwrite("buf_size", &TensorRTRuntime::buf_size);
  1566. py::class_<TopK, std::shared_ptr<TopK>, OpDef> TopKInst(m, "TopK");
  1567. py::enum_<TopK::Mode>(TopKInst, "Mode")
  1568. .value("KTH_ONLY", TopK::Mode::KTH_ONLY)
  1569. .value("VALUE_IDX_NOSORT", TopK::Mode::VALUE_IDX_NOSORT)
  1570. .value("VALUE_IDX_SORTED", TopK::Mode::VALUE_IDX_SORTED)
  1571. .def(py::init([](const std::string& in) {
  1572. auto&& str = normalize_enum(in);
  1573. if (str == "KTH_ONLY") return TopK::Mode::KTH_ONLY;
  1574. if (str == "VALUE_IDX_NOSORT") return TopK::Mode::VALUE_IDX_NOSORT;
  1575. if (str == "VALUE_IDX_SORTED") return TopK::Mode::VALUE_IDX_SORTED;
  1576. throw py::cast_error("invalid enum value " + in);
  1577. }));
  1578. py::implicitly_convertible<std::string, TopK::Mode>();
  1579. TopKInst
  1580. .def(py::init<::megdnn::param::TopK::Mode, std::string>(), py::arg("mode") = ::megdnn::param::TopK::Mode::KTH_ONLY, py::arg("scope") = {})
  1581. .def_readwrite("mode", &TopK::mode);
  1582. py::class_<TypeCvt, std::shared_ptr<TypeCvt>, OpDef> TypeCvtInst(m, "TypeCvt");
  1583. TypeCvtInst
  1584. .def(py::init<::megdnn::DType, std::string>(), py::arg("dtype"), py::arg("scope") = {})
  1585. .def(py::init<>())
  1586. .def_readwrite("dtype", &TypeCvt::dtype);
  1587. py::class_<UniformRNG, std::shared_ptr<UniformRNG>, OpDef> UniformRNGInst(m, "UniformRNG");
  1588. UniformRNGInst
  1589. .def(py::init<uint64_t, ::megdnn::DType, size_t, std::string>(), py::arg("seed") = 0, py::arg("dtype") = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32), py::arg("handle"), py::arg("scope") = {})
  1590. .def(py::init<>())
  1591. .def_readwrite("seed", &UniformRNG::seed)
  1592. .def_readwrite("dtype", &UniformRNG::dtype)
  1593. .def_readwrite("handle", &UniformRNG::handle);
  1594. py::class_<WarpAffine, std::shared_ptr<WarpAffine>, OpDef> WarpAffineInst(m, "WarpAffine");
  1595. WarpAffineInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode");
  1596. WarpAffineInst.attr("BorderMode") = RemapInst.attr("BorderMode");
  1597. WarpAffineInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1598. WarpAffineInst
  1599. .def(py::init<::megdnn::param::WarpAffine::InterpolationMode, ::megdnn::param::WarpAffine::BorderMode, float, ::megdnn::param::WarpAffine::Format, std::string>(), py::arg("imode") = ::megdnn::param::WarpAffine::InterpolationMode::LINEAR, py::arg("border_mode") = ::megdnn::param::WarpAffine::BorderMode::REPLICATE, py::arg("border_val") = .0f, py::arg("format") = ::megdnn::param::WarpAffine::Format::NHWC, py::arg("scope") = {})
  1600. .def_readwrite("imode", &WarpAffine::imode)
  1601. .def_readwrite("border_mode", &WarpAffine::border_mode)
  1602. .def_readwrite("border_val", &WarpAffine::border_val)
  1603. .def_readwrite("format", &WarpAffine::format);
  1604. py::class_<WarpPerspective, std::shared_ptr<WarpPerspective>, OpDef> WarpPerspectiveInst(m, "WarpPerspective");
  1605. WarpPerspectiveInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode");
  1606. WarpPerspectiveInst.attr("BorderMode") = RemapInst.attr("BorderMode");
  1607. WarpPerspectiveInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1608. WarpPerspectiveInst
  1609. .def(py::init<::megdnn::param::WarpPerspective::InterpolationMode, ::megdnn::param::WarpPerspective::BorderMode, ::megdnn::param::WarpPerspective::Format, float, std::string>(), py::arg("imode") = ::megdnn::param::WarpPerspective::InterpolationMode::LINEAR, py::arg("bmode") = ::megdnn::param::WarpPerspective::BorderMode::REPLICATE, py::arg("format") = ::megdnn::param::WarpPerspective::Format::NCHW, py::arg("border_val") = .0f, py::arg("scope") = {})
  1610. .def_readwrite("imode", &WarpPerspective::imode)
  1611. .def_readwrite("bmode", &WarpPerspective::bmode)
  1612. .def_readwrite("format", &WarpPerspective::format)
  1613. .def_readwrite("border_val", &WarpPerspective::border_val);
  1614. py::class_<WarpPerspectiveBackwardData, std::shared_ptr<WarpPerspectiveBackwardData>, OpDef> WarpPerspectiveBackwardDataInst(m, "WarpPerspectiveBackwardData");
  1615. WarpPerspectiveBackwardDataInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode");
  1616. WarpPerspectiveBackwardDataInst.attr("BorderMode") = RemapInst.attr("BorderMode");
  1617. WarpPerspectiveBackwardDataInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1618. WarpPerspectiveBackwardDataInst
  1619. .def(py::init<::megdnn::param::WarpPerspective::InterpolationMode, ::megdnn::param::WarpPerspective::BorderMode, ::megdnn::param::WarpPerspective::Format, float, std::string>(), py::arg("imode") = ::megdnn::param::WarpPerspective::InterpolationMode::LINEAR, py::arg("bmode") = ::megdnn::param::WarpPerspective::BorderMode::REPLICATE, py::arg("format") = ::megdnn::param::WarpPerspective::Format::NCHW, py::arg("border_val") = .0f, py::arg("scope") = {})
  1620. .def_readwrite("imode", &WarpPerspectiveBackwardData::imode)
  1621. .def_readwrite("bmode", &WarpPerspectiveBackwardData::bmode)
  1622. .def_readwrite("format", &WarpPerspectiveBackwardData::format)
  1623. .def_readwrite("border_val", &WarpPerspectiveBackwardData::border_val);
  1624. py::class_<WarpPerspectiveBackwardMat, std::shared_ptr<WarpPerspectiveBackwardMat>, OpDef> WarpPerspectiveBackwardMatInst(m, "WarpPerspectiveBackwardMat");
  1625. WarpPerspectiveBackwardMatInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode");
  1626. WarpPerspectiveBackwardMatInst.attr("BorderMode") = RemapInst.attr("BorderMode");
  1627. WarpPerspectiveBackwardMatInst.attr("Format") = AdaptivePoolingInst.attr("Format");
  1628. WarpPerspectiveBackwardMatInst
  1629. .def(py::init<::megdnn::param::WarpPerspective::InterpolationMode, ::megdnn::param::WarpPerspective::BorderMode, ::megdnn::param::WarpPerspective::Format, float, std::string>(), py::arg("imode") = ::megdnn::param::WarpPerspective::InterpolationMode::LINEAR, py::arg("bmode") = ::megdnn::param::WarpPerspective::BorderMode::REPLICATE, py::arg("format") = ::megdnn::param::WarpPerspective::Format::NCHW, py::arg("border_val") = .0f, py::arg("scope") = {})
  1630. .def_readwrite("imode", &WarpPerspectiveBackwardMat::imode)
  1631. .def_readwrite("bmode", &WarpPerspectiveBackwardMat::bmode)
  1632. .def_readwrite("format", &WarpPerspectiveBackwardMat::format)
  1633. .def_readwrite("border_val", &WarpPerspectiveBackwardMat::border_val);
  1634. // clang-format on