From 013bb14fd0983aab51da77a54bd735ae8d08340f Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 13 May 2022 15:38:02 +0800 Subject: [PATCH] build(tablegen): pregen opdef tablegen targets GitOrigin-RevId: ab7564df14099007d188af4ba7cff28a0cda526c --- imperative/CMakeLists.txt | 4 +- imperative/tablegen/CMakeLists.txt | 107 +- imperative/tablegen/autogen.cpp | 27 +- imperative/tablegen/checkhash.cmake | 16 + imperative/tablegen/generated/enum_macro.h | 34 + imperative/tablegen/generated/hash.txt | 7 + imperative/tablegen/generated/opdef.cpp.inl | 6917 ++++++++++ imperative/tablegen/generated/opdef.cpy.inl | 18249 ++++++++++++++++++++++++++ imperative/tablegen/generated/opdef.h.inl | 1789 +++ imperative/tablegen/generated/opdef.py.inl | 1843 +++ imperative/tablegen/genhash.cmake | 12 + imperative/test/CMakeLists.txt | 6 +- 12 files changed, 28978 insertions(+), 33 deletions(-) create mode 100644 imperative/tablegen/checkhash.cmake create mode 100644 imperative/tablegen/generated/enum_macro.h create mode 100644 imperative/tablegen/generated/hash.txt create mode 100644 imperative/tablegen/generated/opdef.cpp.inl create mode 100644 imperative/tablegen/generated/opdef.cpy.inl create mode 100644 imperative/tablegen/generated/opdef.h.inl create mode 100644 imperative/tablegen/generated/opdef.py.inl create mode 100644 imperative/tablegen/genhash.cmake diff --git a/imperative/CMakeLists.txt b/imperative/CMakeLists.txt index 1e94ab20..37e6b86e 100644 --- a/imperative/CMakeLists.txt +++ b/imperative/CMakeLists.txt @@ -66,8 +66,8 @@ target_link_libraries(${MODULE_NAME} PRIVATE nlohmann_json::nlohmann_json) target_include_directories( ${MODULE_NAME} PUBLIC src/include - PRIVATE ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${MGB_OPDEF_OUT_DIR} - ${CPP_REDIS_INCLUDES}) + PRIVATE ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${CPP_REDIS_INCLUDES}) +target_link_libraries(${MODULE_NAME} PRIVATE mgb_opdef_inc) target_compile_definitions(${MODULE_NAME} PRIVATE MODULE_NAME=${MODULE_NAME}) target_compile_options(${MODULE_NAME} PRIVATE -Wno-unused-parameter) if(CXX_SUPPORT_WCLASS_MEMACCESS) diff --git a/imperative/tablegen/CMakeLists.txt b/imperative/tablegen/CMakeLists.txt index f2d3ed76..d4bed631 100644 --- a/imperative/tablegen/CMakeLists.txt +++ b/imperative/tablegen/CMakeLists.txt @@ -1,21 +1,88 @@ -# mgb tablegen executable -set(TABLE_TARGET mgb-mlir-autogen) -file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.h - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -add_executable(${TABLE_TARGET} ${SRCS}) -target_include_directories(${TABLE_TARGET} PRIVATE ${MLIR_LLVM_INCLUDE_DIR}) -target_link_libraries(${TABLE_TARGET} PRIVATE LLVMTableGen MLIRTableGen LLVMSupport) -set(MGB_TABLEGEN_EXE ${TABLE_TARGET}) +set(MGB_OPDEF_OUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/generated) +set(MGB_OPDEF_OPS_SRC ${CMAKE_SOURCE_DIR}/src/core/include/megbrain/ir/ops.td) +set(MGB_OPDEF_PARAMS_SRC ${CMAKE_SOURCE_DIR}/dnn/scripts/opr_param_defs.py) -# generate megbrain opdef c header and python bindings -set(LLVM_TARGET_DEFINITIONS ${MGE_IR_DIR}/ops.td) -tablegen(MGB opdef.h.inl ${MGE_IR_INCLUDE_DIRS} "--gen-cpp-header") -tablegen(MGB opdef.cpp.inl ${MGE_IR_INCLUDE_DIRS} "--gen-cpp-body") -tablegen(MGB opdef.py.inl ${MGE_IR_INCLUDE_DIRS} "--gen-python-binding") -tablegen(MGB opdef.cpy.inl ${MGE_IR_INCLUDE_DIRS} "--gen-python-c-extension") -tablegen(MGB enum_macro.h ${MGE_IR_INCLUDE_DIRS} "--gen-enum-list-macro") -add_custom_target(mgb_opdef ALL DEPENDS opdef.h.inl opdef.cpp.inl opdef.py.inl - opdef.cpy.inl enum_macro.h param_defs_tblgen) -set(MGB_OPDEF_OUT_DIR - ${CMAKE_CURRENT_BINARY_DIR} - PARENT_SCOPE) +# we set CMAKE_CONFIGURE_DEPENDS so that when source files or hash.txt was modified, +# cmake configure would be triggered to update ${MD5_MISMATCH} +execute_process( + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkhash.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ERROR_QUIET + RESULT_VARIABLE MD5_MISMATCH) + +if(${MD5_MISMATCH}) + # mgb tablegen executable + set(TABLE_TARGET mgb-mlir-autogen) + file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.h + ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + add_executable(${TABLE_TARGET} ${SRCS}) + target_include_directories(${TABLE_TARGET} PRIVATE ${MLIR_LLVM_INCLUDE_DIR}) + target_link_libraries(${TABLE_TARGET} PRIVATE LLVMTableGen MLIRTableGen LLVMSupport) + set(MGB_TABLEGEN_EXE ${TABLE_TARGET}) + + # generate megbrain opdef c header and python bindings basically same as + # third_party/llvm-project/llvm/cmake/modules/TableGen.cmake but change output folder + # and add extra dependency + set(LLVM_SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/llvm-project/llvm) + set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR}/third_party/llvm-project/llvm) + set(MLIR_SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/llvm-project/mlir) + set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}/third_party/llvm-project/mlir) + set(MGB_TABLEGEN_INCLUDES + -I${LLVM_SOURCE_DIR}/include + -I${LLVM_BINARY_DIR}/include + -I${MLIR_SOURCE_DIR}/include + -I${MLIR_BINARY_DIR}/include + -I${CMAKE_SOURCE_DIR}/src/core/include/megbrain/ir + -I${CMAKE_BINARY_DIR}/src/core/include/megbrain/ir) + set(MGB_TABLEGEN_FLAGS --write-if-changed) + set(MGB_TABLEGEN_TARGETS) + + function(tablegen_opdef target output) + add_custom_target( + mgb_opdef_${target} + COMMAND + ${MGB_TABLEGEN_EXE} ${MGB_TABLEGEN_INCLUDES} --gen-${target} + ${MGB_OPDEF_OPS_SRC} ${MGB_TABLEGEN_FLAGS} -o ${MGB_OPDEF_OUT_DIR}/${output} + DEPENDS param_defs_tblgen) + set(MGB_TABLEGEN_TARGETS + ${MGB_TABLEGEN_TARGETS} mgb_opdef_${target} + PARENT_SCOPE) + endfunction() + + tablegen_opdef(cpp-header opdef.h.inl) + tablegen_opdef(cpp-body opdef.cpp.inl) + tablegen_opdef(python-binding opdef.py.inl) + tablegen_opdef(python-c-extension opdef.cpy.inl) + tablegen_opdef(enum-list-macro enum_macro.h) + + add_custom_target( + mgb_opdef_genhash + ${CMAKE_COMMAND} -P genhash.cmake + DEPENDS ${MGB_TABLEGEN_TARGETS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_custom_target(mgb_opdef DEPENDS ${MGB_TABLEGEN_TARGETS} mgb_opdef_genhash) +else() + # add extra dependencies for auto reconfiguration + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS + ${MGB_OPDEF_OPS_SRC} + ${MGB_OPDEF_PARAMS_SRC} + generated/opdef.h.inl + generated/opdef.cpp.inl + generated/opdef.py.inl + generated/opdef.cpy.inl + generated/enum_macro + generated/hash.txt) + # additional check for safety + add_custom_target( + mgb_opdef_checkhash + ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkhash.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_custom_target(mgb_opdef DEPENDS mgb_opdef_checkhash) +endif() + +add_library(mgb_opdef_inc INTERFACE) +target_include_directories(mgb_opdef_inc INTERFACE ${MGB_OPDEF_OUT_DIR}) +add_dependencies(mgb_opdef_inc mgb_opdef) diff --git a/imperative/tablegen/autogen.cpp b/imperative/tablegen/autogen.cpp index 9da5a029..5f4a4090 100644 --- a/imperative/tablegen/autogen.cpp +++ b/imperative/tablegen/autogen.cpp @@ -3,8 +3,9 @@ #include "./targets/pybind11.h" #include "./targets/python_c_extension.h" -using llvm::raw_ostream; -using llvm::RecordKeeper; +namespace { + +using namespace mlir::tblgen; enum ActionType { None, CppHeader, CppBody, Pybind, CPython, EnumListMacro }; @@ -24,25 +25,35 @@ llvm::cl::opt action( EnumListMacro, "gen-enum-list-macro", "Generate enum param list macro"))); -using namespace mlir::tblgen; +template +llvm::TableGenMainFn* WrapMain() { + return [](llvm::raw_ostream& os, llvm::RecordKeeper& records) -> bool { + os << "// clang-format off\n"; + auto ret = MainFn(os, records); + os << "// clang-format on\n"; + return ret; + }; +} + +} // namespace int main(int argc, char** argv) { llvm::InitLLVM y(argc, argv); llvm::cl::ParseCommandLineOptions(argc, argv); if (action == ActionType::CppHeader) { - return TableGenMain(argv[0], &gen_op_def_c_header); + return TableGenMain(argv[0], WrapMain<&gen_op_def_c_header>()); } if (action == ActionType::CppBody) { - return TableGenMain(argv[0], &gen_op_def_c_body); + return TableGenMain(argv[0], WrapMain<&gen_op_def_c_body>()); } if (action == ActionType::Pybind) { - return TableGenMain(argv[0], &gen_op_def_pybind11); + return TableGenMain(argv[0], WrapMain<&gen_op_def_pybind11>()); } if (action == ActionType::CPython) { - return TableGenMain(argv[0], &gen_op_def_python_c_extension); + return TableGenMain(argv[0], WrapMain<&gen_op_def_python_c_extension>()); } if (action == ActionType::EnumListMacro) { - return TableGenMain(argv[0], &gen_enum_param_list_macro); + return TableGenMain(argv[0], WrapMain<&gen_enum_param_list_macro>()); } return -1; } diff --git a/imperative/tablegen/checkhash.cmake b/imperative/tablegen/checkhash.cmake new file mode 100644 index 00000000..33fc2225 --- /dev/null +++ b/imperative/tablegen/checkhash.cmake @@ -0,0 +1,16 @@ +set(SOURCES + ../../dnn/scripts/opr_param_defs.py + ../../src/core/include/megbrain/ir/ops.td + generated/opdef.h.inl + generated/opdef.cpp.inl + generated/opdef.py.inl + generated/opdef.cpy.inl + generated/enum_macro.h) +execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum ${SOURCES} + OUTPUT_VARIABLE GENERATED_HASH_CONTENT) + +file(READ generated/hash.txt HASH_CONTENT) + +if(NOT "${GENERATED_HASH_CONTENT}" STREQUAL "${HASH_CONTENT}") + message(FATAL_ERROR "File ops.td was changed, please rerun cmake configure") +endif() diff --git a/imperative/tablegen/generated/enum_macro.h b/imperative/tablegen/generated/enum_macro.h new file mode 100644 index 00000000..56b71baa --- /dev/null +++ b/imperative/tablegen/generated/enum_macro.h @@ -0,0 +1,34 @@ +// clang-format off +#define FOR_EACH_ENUM_PARAM(cb) \ + cb(::megdnn::param::PoolingV0::Mode); \ + cb(::megdnn::param::Convolution::Format); \ + cb(::megdnn::param::Argsort::Order); \ + cb(::megdnn::param::ConvBiasV0::NonlineMode); \ + cb(::megdnn::param::ConvolutionV0::Mode); \ + cb(::megdnn::param::ConvolutionV0::Sparse); \ + cb(::megdnn::param::ConvolutionV1::ComputeMode); \ + cb(::megdnn::param::BN::ParamDim); \ + cb(::megdnn::param::BN::FwdMode); \ + cb(::megdnn::param::MatrixMulV1::ComputeMode); \ + cb(::megdnn::param::MatrixMul::Format); \ + cb(::megdnn::param::CollectiveComm::Mode); \ + cb(::megdnn::param::Convolution3D::Mode); \ + cb(::megdnn::param::Convolution3D::Sparse); \ + cb(::megdnn::param::Convolution3D::DataType); \ + cb(::megdnn::param::Convolution3D::Format); \ + cb(::megdnn::param::ConvolutionV0::Format); \ + cb(::megdnn::param::CvtColor::Mode); \ + cb(::megdnn::param::Elemwise::Mode); \ + cb(::megdnn::param::ElemwiseMultiType::Mode); \ + cb(::megdnn::param::Padding::PaddingMode); \ + cb(::megdnn::param::RNNCell::NonlineMode); \ + cb(::megdnn::param::ROIAlignV0::Mode); \ + cb(::megdnn::param::ROIPooling::Mode); \ + cb(::megdnn::param::Reduce::Mode); \ + cb(::megdnn::param::Reduce::DataType); \ + cb(::megdnn::param::WarpPerspectiveV1::InterpolationMode); \ + cb(::megdnn::param::WarpPerspectiveV1::BorderMode); \ + cb(::megdnn::param::TopK::Mode); +#define FOR_EACH_BIT_COMBINED_ENUM_PARAM(cb) \ + cb(::megdnn::param::ExecutionPolicy::Strategy); +// clang-format on diff --git a/imperative/tablegen/generated/hash.txt b/imperative/tablegen/generated/hash.txt new file mode 100644 index 00000000..813f92c0 --- /dev/null +++ b/imperative/tablegen/generated/hash.txt @@ -0,0 +1,7 @@ +0df57b38e71a4d1882ed6c24f3a26b57 ../../dnn/scripts/opr_param_defs.py +759bfbf27fd3f0dd6b6edf06377e1d6b ../../src/core/include/megbrain/ir/ops.td +c613316001b5f0294ede198f5563f041 generated/opdef.h.inl +a1f7f13c909f9d4c173277f4ed28fb61 generated/opdef.cpp.inl +cf48f9ca352fabaeb6c846c11c6b1662 generated/opdef.py.inl +12365b938f564e5b3639d309f7c83414 generated/opdef.cpy.inl +71e1462bf4d882e2615c3c632cb671cc generated/enum_macro.h diff --git a/imperative/tablegen/generated/opdef.cpp.inl b/imperative/tablegen/generated/opdef.cpp.inl new file mode 100644 index 00000000..ea32b81c --- /dev/null +++ b/imperative/tablegen/generated/opdef.cpp.inl @@ -0,0 +1,6917 @@ +// clang-format off +MGB_DYN_TYPE_OBJ_FINAL_IMPL(AdaptivePooling); + +namespace { +size_t AdaptivePooling_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.shape)); + return val; +} +bool AdaptivePooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.format != b_.format) return false; + if (a_.shape != b_.shape) return false; + return true; +} +std::vector> AdaptivePooling_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case AdaptivePooling::Mode::MAX: + props_.emplace_back("mode", "MAX"); + break; + case AdaptivePooling::Mode::AVERAGE: + props_.emplace_back("mode", "AVERAGE"); + break; + case AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING: + props_.emplace_back("mode", "AVERAGE_COUNT_EXCLUDE_PADDING"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + switch (op_.format){ + case AdaptivePooling::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case AdaptivePooling::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case AdaptivePooling::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case AdaptivePooling::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case AdaptivePooling::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case AdaptivePooling::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case AdaptivePooling::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case AdaptivePooling::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case AdaptivePooling::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case AdaptivePooling::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case AdaptivePooling::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case AdaptivePooling::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case AdaptivePooling::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case AdaptivePooling::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case AdaptivePooling::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case AdaptivePooling::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + props_.emplace_back("shape", "{std::vector}"); + return props_; +} +std::string AdaptivePooling_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "AdaptivePooling"; +} +} // anonymous namespace +OP_TRAIT_REG(AdaptivePooling, AdaptivePooling) + .hash(AdaptivePooling_hash_impl) + .is_same_st(AdaptivePooling_is_same_st_impl) + .props(AdaptivePooling_props_impl) + .make_name(AdaptivePooling_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(AddAxis); + +namespace { +size_t AddAxis_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + return val; +} +bool AddAxis_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + return true; +} +std::vector> AddAxis_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", "{std::vector}"); + return props_; +} +std::string AddAxis_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "AddAxis"; +} +} // anonymous namespace +OP_TRAIT_REG(AddAxis, AddAxis) + .hash(AddAxis_hash_impl) + .is_same_st(AddAxis_is_same_st_impl) + .props(AddAxis_props_impl) + .make_name(AddAxis_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Argmax); + +namespace { +size_t Argmax_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + return val; +} +bool Argmax_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + return true; +} +std::vector> Argmax_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + return props_; +} +std::string Argmax_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Argmax"; +} +} // anonymous namespace +OP_TRAIT_REG(Argmax, Argmax) + .hash(Argmax_hash_impl) + .is_same_st(Argmax_is_same_st_impl) + .props(Argmax_props_impl) + .make_name(Argmax_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Argmin); + +namespace { +size_t Argmin_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + return val; +} +bool Argmin_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + return true; +} +std::vector> Argmin_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + return props_; +} +std::string Argmin_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Argmin"; +} +} // anonymous namespace +OP_TRAIT_REG(Argmin, Argmin) + .hash(Argmin_hash_impl) + .is_same_st(Argmin_is_same_st_impl) + .props(Argmin_props_impl) + .make_name(Argmin_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Argsort); + +namespace { +size_t Argsort_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.order)); + return val; +} +bool Argsort_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.order != b_.order) return false; + return true; +} +std::vector> Argsort_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.order){ + case Argsort::Order::ASCENDING: + props_.emplace_back("order", "ASCENDING"); + break; + case Argsort::Order::DESCENDING: + props_.emplace_back("order", "DESCENDING"); + break; + default: + props_.emplace_back("order", "INVALID"); + break; + } + return props_; +} +std::string Argsort_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Argsort"; +} +} // anonymous namespace +OP_TRAIT_REG(Argsort, Argsort) + .hash(Argsort_hash_impl) + .is_same_st(Argsort_is_same_st_impl) + .props(Argsort_props_impl) + .make_name(Argsort_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(AssertEqual); + +namespace { +size_t AssertEqual_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.maxerr)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.verbose)); + return val; +} +bool AssertEqual_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.maxerr != b_.maxerr) return false; + if (a_.verbose != b_.verbose) return false; + return true; +} +std::vector> AssertEqual_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("maxerr", std::to_string(op_.maxerr)); + props_.emplace_back("verbose", std::to_string(op_.verbose)); + return props_; +} +std::string AssertEqual_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "AssertEqual"; +} +} // anonymous namespace +OP_TRAIT_REG(AssertEqual, AssertEqual) + .hash(AssertEqual_hash_impl) + .is_same_st(AssertEqual_is_same_st_impl) + .props(AssertEqual_props_impl) + .make_name(AssertEqual_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(AtlasRuntime); + +namespace { +size_t AtlasRuntime_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size)); + return val; +} +bool AtlasRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.buf != b_.buf) return false; + if (a_.buf_size != b_.buf_size) return false; + return true; +} +std::vector> AtlasRuntime_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("buf", op_.buf); + props_.emplace_back("buf_size", std::to_string(op_.buf_size)); + return props_; +} +std::string AtlasRuntime_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "AtlasRuntime"; +} +} // anonymous namespace +OP_TRAIT_REG(AtlasRuntime, AtlasRuntime) + .hash(AtlasRuntime_hash_impl) + .is_same_st(AtlasRuntime_is_same_st_impl) + .props(AtlasRuntime_props_impl) + .make_name(AtlasRuntime_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Barrier); + +namespace { +size_t Barrier_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.nr_outputs)); + return val; +} +bool Barrier_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.comp_node != b_.comp_node) return false; + if (a_.nr_outputs != b_.nr_outputs) return false; + return true; +} +std::vector> Barrier_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("comp_node", op_.comp_node.to_string()); + props_.emplace_back("nr_outputs", std::to_string(op_.nr_outputs)); + return props_; +} +std::string Barrier_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Barrier"; +} +} // anonymous namespace +OP_TRAIT_REG(Barrier, Barrier) + .hash(Barrier_hash_impl) + .is_same_st(Barrier_is_same_st_impl) + .props(Barrier_props_impl) + .make_name(Barrier_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchConvBias); + +namespace { +size_t BatchConvBias_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + return val; +} +bool BatchConvBias_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.nonlineMode != b_.nonlineMode) return false; + if (a_.mode != b_.mode) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.format != b_.format) return false; + if (a_.compute_mode != b_.compute_mode) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + if (a_.dtype != b_.dtype) return false; + return true; +} +std::vector> BatchConvBias_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.nonlineMode){ + case BatchConvBias::NonlineMode::IDENTITY: + props_.emplace_back("nonlineMode", "IDENTITY"); + break; + case BatchConvBias::NonlineMode::RELU: + props_.emplace_back("nonlineMode", "RELU"); + break; + case BatchConvBias::NonlineMode::SIGMOID: + props_.emplace_back("nonlineMode", "SIGMOID"); + break; + case BatchConvBias::NonlineMode::H_SWISH: + props_.emplace_back("nonlineMode", "H_SWISH"); + break; + default: + props_.emplace_back("nonlineMode", "INVALID"); + break; + } + switch (op_.mode){ + case BatchConvBias::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case BatchConvBias::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.sparse){ + case BatchConvBias::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case BatchConvBias::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.format){ + case BatchConvBias::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case BatchConvBias::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case BatchConvBias::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case BatchConvBias::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case BatchConvBias::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case BatchConvBias::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case BatchConvBias::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case BatchConvBias::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case BatchConvBias::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case BatchConvBias::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case BatchConvBias::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case BatchConvBias::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case BatchConvBias::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case BatchConvBias::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case BatchConvBias::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case BatchConvBias::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case BatchConvBias::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case BatchConvBias::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.compute_mode){ + case BatchConvBias::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case BatchConvBias::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + switch (op_.strategy){ + case BatchConvBias::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case BatchConvBias::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case BatchConvBias::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case BatchConvBias::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + props_.emplace_back("dtype", op_.dtype.name()); + return props_; +} +std::string BatchConvBias_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BatchConvBias"; +} +} // anonymous namespace +OP_TRAIT_REG(BatchConvBias, BatchConvBias) + .hash(BatchConvBias_hash_impl) + .is_same_st(BatchConvBias_is_same_st_impl) + .props(BatchConvBias_props_impl) + .make_name(BatchConvBias_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchNorm); + +namespace { +size_t BatchNorm_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.param_dim)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.epsilon)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.avg_factor)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.scale)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.bias)); + return val; +} +bool BatchNorm_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.param_dim != b_.param_dim) return false; + if (a_.fwd_mode != b_.fwd_mode) return false; + if (a_.epsilon != b_.epsilon) return false; + if (a_.avg_factor != b_.avg_factor) return false; + if (a_.scale != b_.scale) return false; + if (a_.bias != b_.bias) return false; + return true; +} +std::vector> BatchNorm_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.param_dim){ + case BatchNorm::ParamDim::DIM_11HW: + props_.emplace_back("param_dim", "DIM_11HW"); + break; + case BatchNorm::ParamDim::DIM_1CHW: + props_.emplace_back("param_dim", "DIM_1CHW"); + break; + case BatchNorm::ParamDim::DIM_1C11: + props_.emplace_back("param_dim", "DIM_1C11"); + break; + case BatchNorm::ParamDim::DIM_111C: + props_.emplace_back("param_dim", "DIM_111C"); + break; + default: + props_.emplace_back("param_dim", "INVALID"); + break; + } + switch (op_.fwd_mode){ + case BatchNorm::FwdMode::TRAINING: + props_.emplace_back("fwd_mode", "TRAINING"); + break; + case BatchNorm::FwdMode::INFERENCE: + props_.emplace_back("fwd_mode", "INFERENCE"); + break; + default: + props_.emplace_back("fwd_mode", "INVALID"); + break; + } + props_.emplace_back("epsilon", std::to_string(op_.epsilon)); + props_.emplace_back("avg_factor", std::to_string(op_.avg_factor)); + props_.emplace_back("scale", std::to_string(op_.scale)); + props_.emplace_back("bias", std::to_string(op_.bias)); + return props_; +} +std::string BatchNorm_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BatchNorm"; +} +} // anonymous namespace +OP_TRAIT_REG(BatchNorm, BatchNorm) + .hash(BatchNorm_hash_impl) + .is_same_st(BatchNorm_is_same_st_impl) + .props(BatchNorm_props_impl) + .make_name(BatchNorm_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchNormBackward); + +namespace { +size_t BatchNormBackward_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.param_dim)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.epsilon)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.avg_factor)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.scale)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.bias)); + return val; +} +bool BatchNormBackward_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.param_dim != b_.param_dim) return false; + if (a_.fwd_mode != b_.fwd_mode) return false; + if (a_.epsilon != b_.epsilon) return false; + if (a_.avg_factor != b_.avg_factor) return false; + if (a_.scale != b_.scale) return false; + if (a_.bias != b_.bias) return false; + return true; +} +std::vector> BatchNormBackward_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.param_dim){ + case BatchNormBackward::ParamDim::DIM_11HW: + props_.emplace_back("param_dim", "DIM_11HW"); + break; + case BatchNormBackward::ParamDim::DIM_1CHW: + props_.emplace_back("param_dim", "DIM_1CHW"); + break; + case BatchNormBackward::ParamDim::DIM_1C11: + props_.emplace_back("param_dim", "DIM_1C11"); + break; + case BatchNormBackward::ParamDim::DIM_111C: + props_.emplace_back("param_dim", "DIM_111C"); + break; + default: + props_.emplace_back("param_dim", "INVALID"); + break; + } + switch (op_.fwd_mode){ + case BatchNormBackward::FwdMode::TRAINING: + props_.emplace_back("fwd_mode", "TRAINING"); + break; + case BatchNormBackward::FwdMode::INFERENCE: + props_.emplace_back("fwd_mode", "INFERENCE"); + break; + default: + props_.emplace_back("fwd_mode", "INVALID"); + break; + } + props_.emplace_back("epsilon", std::to_string(op_.epsilon)); + props_.emplace_back("avg_factor", std::to_string(op_.avg_factor)); + props_.emplace_back("scale", std::to_string(op_.scale)); + props_.emplace_back("bias", std::to_string(op_.bias)); + return props_; +} +std::string BatchNormBackward_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BatchNormBackward"; +} +} // anonymous namespace +OP_TRAIT_REG(BatchNormBackward, BatchNormBackward) + .hash(BatchNormBackward_hash_impl) + .is_same_st(BatchNormBackward_is_same_st_impl) + .props(BatchNormBackward_props_impl) + .make_name(BatchNormBackward_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedIncrMeshIndexing); + +namespace { +size_t BatchedIncrMeshIndexing_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool BatchedIncrMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> BatchedIncrMeshIndexing_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string BatchedIncrMeshIndexing_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BatchedIncrMeshIndexing"; +} +} // anonymous namespace +OP_TRAIT_REG(BatchedIncrMeshIndexing, BatchedIncrMeshIndexing) + .hash(BatchedIncrMeshIndexing_hash_impl) + .is_same_st(BatchedIncrMeshIndexing_is_same_st_impl) + .props(BatchedIncrMeshIndexing_props_impl) + .make_name(BatchedIncrMeshIndexing_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedMatrixMul); + +namespace { +size_t BatchedMatrixMul_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeA)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeB)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dimA)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dimB)); + return val; +} +bool BatchedMatrixMul_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.transposeA != b_.transposeA) return false; + if (a_.transposeB != b_.transposeB) return false; + if (a_.compute_mode != b_.compute_mode) return false; + if (a_.format != b_.format) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + if (a_.dimA != b_.dimA) return false; + if (a_.dimB != b_.dimB) return false; + return true; +} +std::vector> BatchedMatrixMul_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("transposeA", std::to_string(op_.transposeA)); + props_.emplace_back("transposeB", std::to_string(op_.transposeB)); + switch (op_.compute_mode){ + case BatchedMatrixMul::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case BatchedMatrixMul::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + switch (op_.format){ + case BatchedMatrixMul::Format::DEFAULT: + props_.emplace_back("format", "DEFAULT"); + break; + case BatchedMatrixMul::Format::MK4: + props_.emplace_back("format", "MK4"); + break; + case BatchedMatrixMul::Format::MK8: + props_.emplace_back("format", "MK8"); + break; + case BatchedMatrixMul::Format::MK4_DOT: + props_.emplace_back("format", "MK4_DOT"); + break; + case BatchedMatrixMul::Format::N32K4_DOT: + props_.emplace_back("format", "N32K4_DOT"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.strategy){ + case BatchedMatrixMul::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case BatchedMatrixMul::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case BatchedMatrixMul::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case BatchedMatrixMul::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + props_.emplace_back("dimA", std::to_string(op_.dimA)); + props_.emplace_back("dimB", std::to_string(op_.dimB)); + return props_; +} +std::string BatchedMatrixMul_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BatchedMatrixMul"; +} +} // anonymous namespace +OP_TRAIT_REG(BatchedMatrixMul, BatchedMatrixMul) + .hash(BatchedMatrixMul_hash_impl) + .is_same_st(BatchedMatrixMul_is_same_st_impl) + .props(BatchedMatrixMul_props_impl) + .make_name(BatchedMatrixMul_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedMeshIndexing); + +namespace { +size_t BatchedMeshIndexing_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool BatchedMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> BatchedMeshIndexing_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string BatchedMeshIndexing_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BatchedMeshIndexing"; +} +} // anonymous namespace +OP_TRAIT_REG(BatchedMeshIndexing, BatchedMeshIndexing) + .hash(BatchedMeshIndexing_hash_impl) + .is_same_st(BatchedMeshIndexing_is_same_st_impl) + .props(BatchedMeshIndexing_props_impl) + .make_name(BatchedMeshIndexing_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BatchedSetMeshIndexing); + +namespace { +size_t BatchedSetMeshIndexing_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool BatchedSetMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> BatchedSetMeshIndexing_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string BatchedSetMeshIndexing_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BatchedSetMeshIndexing"; +} +} // anonymous namespace +OP_TRAIT_REG(BatchedSetMeshIndexing, BatchedSetMeshIndexing) + .hash(BatchedSetMeshIndexing_hash_impl) + .is_same_st(BatchedSetMeshIndexing_is_same_st_impl) + .props(BatchedSetMeshIndexing_props_impl) + .make_name(BatchedSetMeshIndexing_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(BetaRNG); + +namespace { +size_t BetaRNG_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash(op_.handle) + ); + } +bool BetaRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle;} +std::vector> BetaRNG_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string BetaRNG_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "BetaRNG"; +} +} // anonymous namespace +OP_TRAIT_REG(BetaRNG, BetaRNG) + .hash(BetaRNG_hash_impl) + .is_same_st(BetaRNG_is_same_st_impl) + .props(BetaRNG_props_impl) + .make_name(BetaRNG_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Borrow); + +namespace { +size_t Borrow_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node)); + return val; +} +bool Borrow_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.comp_node != b_.comp_node) return false; + return true; +} +std::vector> Borrow_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("comp_node", op_.comp_node.to_string()); + return props_; +} +std::string Borrow_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Borrow"; +} +} // anonymous namespace +OP_TRAIT_REG(Borrow, Borrow) + .hash(Borrow_hash_impl) + .is_same_st(Borrow_is_same_st_impl) + .props(Borrow_props_impl) + .make_name(Borrow_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Broadcast); + +namespace { +size_t Broadcast_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.shape)); + return val; +} +bool Broadcast_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.shape != b_.shape) return false; + return true; +} +std::vector> Broadcast_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("shape", "{std::vector}"); + return props_; +} +std::string Broadcast_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Broadcast"; +} +} // anonymous namespace +OP_TRAIT_REG(Broadcast, Broadcast) + .hash(Broadcast_hash_impl) + .is_same_st(Broadcast_is_same_st_impl) + .props(Broadcast_props_impl) + .make_name(Broadcast_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(CambriconRuntime); + +namespace { +size_t CambriconRuntime_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.symbol)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.tensor_dim_mutable)); + return val; +} +bool CambriconRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.buf != b_.buf) return false; + if (a_.buf_size != b_.buf_size) return false; + if (a_.symbol != b_.symbol) return false; + if (a_.tensor_dim_mutable != b_.tensor_dim_mutable) return false; + return true; +} +std::vector> CambriconRuntime_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("buf", op_.buf); + props_.emplace_back("buf_size", std::to_string(op_.buf_size)); + props_.emplace_back("symbol", op_.symbol); + props_.emplace_back("tensor_dim_mutable", std::to_string(op_.tensor_dim_mutable)); + return props_; +} +std::string CambriconRuntime_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "CambriconRuntime"; +} +} // anonymous namespace +OP_TRAIT_REG(CambriconRuntime, CambriconRuntime) + .hash(CambriconRuntime_hash_impl) + .is_same_st(CambriconRuntime_is_same_st_impl) + .props(CambriconRuntime_props_impl) + .make_name(CambriconRuntime_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(CheckNonFinite); + +namespace { +size_t CheckNonFinite_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.scale)); + return val; +} +bool CheckNonFinite_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.scale != b_.scale) return false; + return true; +} +std::vector> CheckNonFinite_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("scale", std::to_string(op_.scale)); + return props_; +} +std::string CheckNonFinite_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "CheckNonFinite"; +} +} // anonymous namespace +OP_TRAIT_REG(CheckNonFinite, CheckNonFinite) + .hash(CheckNonFinite_hash_impl) + .is_same_st(CheckNonFinite_is_same_st_impl) + .props(CheckNonFinite_props_impl) + .make_name(CheckNonFinite_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(CollectiveComm); + +namespace { +size_t CollectiveComm_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.key)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.nr_devices)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.rank)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.is_root)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.local_grad)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.addr)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.port)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + val = mgb::hash_pair_combine(val, mgb::hash(op_.backend)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node)); + return val; +} +bool CollectiveComm_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.key != b_.key) return false; + if (a_.nr_devices != b_.nr_devices) return false; + if (a_.rank != b_.rank) return false; + if (a_.is_root != b_.is_root) return false; + if (a_.local_grad != b_.local_grad) return false; + if (a_.addr != b_.addr) return false; + if (a_.port != b_.port) return false; + if (a_.dtype != b_.dtype) return false; + if (a_.backend != b_.backend) return false; + if (a_.comp_node != b_.comp_node) return false; + return true; +} +std::vector> CollectiveComm_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case CollectiveComm::Mode::REDUCE_SUM: + props_.emplace_back("mode", "REDUCE_SUM"); + break; + case CollectiveComm::Mode::BROADCAST: + props_.emplace_back("mode", "BROADCAST"); + break; + case CollectiveComm::Mode::ALL_GATHER: + props_.emplace_back("mode", "ALL_GATHER"); + break; + case CollectiveComm::Mode::REDUCE_SCATTER_SUM: + props_.emplace_back("mode", "REDUCE_SCATTER_SUM"); + break; + case CollectiveComm::Mode::ALL_REDUCE_SUM: + props_.emplace_back("mode", "ALL_REDUCE_SUM"); + break; + case CollectiveComm::Mode::ALL_REDUCE_MAX: + props_.emplace_back("mode", "ALL_REDUCE_MAX"); + break; + case CollectiveComm::Mode::ALL_REDUCE_MIN: + props_.emplace_back("mode", "ALL_REDUCE_MIN"); + break; + case CollectiveComm::Mode::ALL_REDUCE_PROD: + props_.emplace_back("mode", "ALL_REDUCE_PROD"); + break; + case CollectiveComm::Mode::GATHER: + props_.emplace_back("mode", "GATHER"); + break; + case CollectiveComm::Mode::SCATTER: + props_.emplace_back("mode", "SCATTER"); + break; + case CollectiveComm::Mode::ALL_TO_ALL: + props_.emplace_back("mode", "ALL_TO_ALL"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("key", op_.key); + props_.emplace_back("nr_devices", std::to_string(op_.nr_devices)); + props_.emplace_back("rank", std::to_string(op_.rank)); + props_.emplace_back("is_root", std::to_string(op_.is_root)); + props_.emplace_back("local_grad", std::to_string(op_.local_grad)); + props_.emplace_back("addr", op_.addr); + props_.emplace_back("port", std::to_string(op_.port)); + props_.emplace_back("dtype", op_.dtype.name()); + props_.emplace_back("backend", op_.backend); + props_.emplace_back("comp_node", op_.comp_node); + return props_; +} +std::string CollectiveComm_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "CollectiveComm"; +} +} // anonymous namespace +OP_TRAIT_REG(CollectiveComm, CollectiveComm) + .hash(CollectiveComm_hash_impl) + .is_same_st(CollectiveComm_is_same_st_impl) + .props(CollectiveComm_props_impl) + .make_name(CollectiveComm_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Concat); + +namespace { +size_t Concat_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node)); + return val; +} +bool Concat_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + if (a_.comp_node != b_.comp_node) return false; + return true; +} +std::vector> Concat_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + props_.emplace_back("comp_node", op_.comp_node.to_string()); + return props_; +} +std::string Concat_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Concat"; +} +} // anonymous namespace +OP_TRAIT_REG(Concat, Concat) + .hash(Concat_hash_impl) + .is_same_st(Concat_is_same_st_impl) + .props(Concat_props_impl) + .make_name(Concat_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(CondTake); + +namespace { +size_t CondTake_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + return val; +} +bool CondTake_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + return true; +} +std::vector> CondTake_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + return props_; +} +std::string CondTake_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "CondTake"; +} +} // anonymous namespace +OP_TRAIT_REG(CondTake, CondTake) + .hash(CondTake_hash_impl) + .is_same_st(CondTake_is_same_st_impl) + .props(CondTake_props_impl) + .make_name(CondTake_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ConvBias); + +namespace { +size_t ConvBias_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + return val; +} +bool ConvBias_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.nonlineMode != b_.nonlineMode) return false; + if (a_.mode != b_.mode) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.format != b_.format) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.compute_mode != b_.compute_mode) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + if (a_.dtype != b_.dtype) return false; + return true; +} +std::vector> ConvBias_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.nonlineMode){ + case ConvBias::NonlineMode::IDENTITY: + props_.emplace_back("nonlineMode", "IDENTITY"); + break; + case ConvBias::NonlineMode::RELU: + props_.emplace_back("nonlineMode", "RELU"); + break; + case ConvBias::NonlineMode::SIGMOID: + props_.emplace_back("nonlineMode", "SIGMOID"); + break; + case ConvBias::NonlineMode::H_SWISH: + props_.emplace_back("nonlineMode", "H_SWISH"); + break; + default: + props_.emplace_back("nonlineMode", "INVALID"); + break; + } + switch (op_.mode){ + case ConvBias::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case ConvBias::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + switch (op_.sparse){ + case ConvBias::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case ConvBias::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.format){ + case ConvBias::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case ConvBias::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case ConvBias::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case ConvBias::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case ConvBias::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case ConvBias::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case ConvBias::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case ConvBias::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case ConvBias::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case ConvBias::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case ConvBias::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case ConvBias::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case ConvBias::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case ConvBias::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case ConvBias::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case ConvBias::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case ConvBias::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case ConvBias::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.compute_mode){ + case ConvBias::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case ConvBias::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + switch (op_.strategy){ + case ConvBias::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case ConvBias::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case ConvBias::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case ConvBias::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + props_.emplace_back("dtype", op_.dtype.name()); + return props_; +} +std::string ConvBias_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ConvBias"; +} +} // anonymous namespace +OP_TRAIT_REG(ConvBias, ConvBias) + .hash(ConvBias_hash_impl) + .is_same_st(ConvBias_is_same_st_impl) + .props(ConvBias_props_impl) + .make_name(ConvBias_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Convolution); + +namespace { +size_t Convolution_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + return val; +} +bool Convolution_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.format != b_.format) return false; + if (a_.compute_mode != b_.compute_mode) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + return true; +} +std::vector> Convolution_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case Convolution::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case Convolution::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.sparse){ + case Convolution::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case Convolution::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.format){ + case Convolution::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case Convolution::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case Convolution::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case Convolution::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case Convolution::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case Convolution::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case Convolution::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case Convolution::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case Convolution::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case Convolution::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case Convolution::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case Convolution::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case Convolution::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case Convolution::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case Convolution::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case Convolution::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case Convolution::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case Convolution::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.compute_mode){ + case Convolution::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case Convolution::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + switch (op_.strategy){ + case Convolution::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case Convolution::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case Convolution::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case Convolution::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + return props_; +} +std::string Convolution_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Convolution"; +} +} // anonymous namespace +OP_TRAIT_REG(Convolution, Convolution) + .hash(Convolution_hash_impl) + .is_same_st(Convolution_is_same_st_impl) + .props(Convolution_props_impl) + .make_name(Convolution_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Convolution3D); + +namespace { +size_t Convolution3D_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_d)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_d)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_d)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.data_type)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + return val; +} +bool Convolution3D_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.pad_d != b_.pad_d) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_d != b_.stride_d) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_d != b_.dilate_d) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.data_type != b_.data_type) return false; + if (a_.format != b_.format) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + return true; +} +std::vector> Convolution3D_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case Convolution3D::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case Convolution3D::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_d", std::to_string(op_.pad_d)); + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_d", std::to_string(op_.stride_d)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_d", std::to_string(op_.dilate_d)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.sparse){ + case Convolution3D::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case Convolution3D::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.data_type){ + case Convolution3D::DataType::FLOAT: + props_.emplace_back("data_type", "FLOAT"); + break; + case Convolution3D::DataType::FLOAT_IO16xC32: + props_.emplace_back("data_type", "FLOAT_IO16xC32"); + break; + default: + props_.emplace_back("data_type", "INVALID"); + break; + } + switch (op_.format){ + case Convolution3D::Format::NCDHW: + props_.emplace_back("format", "NCDHW"); + break; + case Convolution3D::Format::NDHWC: + props_.emplace_back("format", "NDHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.strategy){ + case Convolution3D::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case Convolution3D::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case Convolution3D::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case Convolution3D::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + return props_; +} +std::string Convolution3D_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Convolution3D"; +} +} // anonymous namespace +OP_TRAIT_REG(Convolution3D, Convolution3D) + .hash(Convolution3D_hash_impl) + .is_same_st(Convolution3D_is_same_st_impl) + .props(Convolution3D_props_impl) + .make_name(Convolution3D_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Convolution3DBackwardData); + +namespace { +size_t Convolution3DBackwardData_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_d)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_d)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_d)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.data_type)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + return val; +} +bool Convolution3DBackwardData_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.pad_d != b_.pad_d) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_d != b_.stride_d) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_d != b_.dilate_d) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.data_type != b_.data_type) return false; + if (a_.format != b_.format) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + return true; +} +std::vector> Convolution3DBackwardData_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case Convolution3DBackwardData::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case Convolution3DBackwardData::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_d", std::to_string(op_.pad_d)); + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_d", std::to_string(op_.stride_d)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_d", std::to_string(op_.dilate_d)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.sparse){ + case Convolution3DBackwardData::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case Convolution3DBackwardData::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.data_type){ + case Convolution3DBackwardData::DataType::FLOAT: + props_.emplace_back("data_type", "FLOAT"); + break; + case Convolution3DBackwardData::DataType::FLOAT_IO16xC32: + props_.emplace_back("data_type", "FLOAT_IO16xC32"); + break; + default: + props_.emplace_back("data_type", "INVALID"); + break; + } + switch (op_.format){ + case Convolution3DBackwardData::Format::NCDHW: + props_.emplace_back("format", "NCDHW"); + break; + case Convolution3DBackwardData::Format::NDHWC: + props_.emplace_back("format", "NDHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.strategy){ + case Convolution3DBackwardData::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case Convolution3DBackwardData::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case Convolution3DBackwardData::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case Convolution3DBackwardData::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + return props_; +} +std::string Convolution3DBackwardData_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Convolution3DBackwardData"; +} +} // anonymous namespace +OP_TRAIT_REG(Convolution3DBackwardData, Convolution3DBackwardData) + .hash(Convolution3DBackwardData_hash_impl) + .is_same_st(Convolution3DBackwardData_is_same_st_impl) + .props(Convolution3DBackwardData_props_impl) + .make_name(Convolution3DBackwardData_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ConvolutionBackwardData); + +namespace { +size_t ConvolutionBackwardData_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + return val; +} +bool ConvolutionBackwardData_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.format != b_.format) return false; + if (a_.compute_mode != b_.compute_mode) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + if (a_.dtype != b_.dtype) return false; + return true; +} +std::vector> ConvolutionBackwardData_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case ConvolutionBackwardData::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case ConvolutionBackwardData::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.sparse){ + case ConvolutionBackwardData::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case ConvolutionBackwardData::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.format){ + case ConvolutionBackwardData::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case ConvolutionBackwardData::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case ConvolutionBackwardData::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case ConvolutionBackwardData::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case ConvolutionBackwardData::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case ConvolutionBackwardData::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case ConvolutionBackwardData::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case ConvolutionBackwardData::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case ConvolutionBackwardData::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case ConvolutionBackwardData::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case ConvolutionBackwardData::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case ConvolutionBackwardData::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case ConvolutionBackwardData::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case ConvolutionBackwardData::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case ConvolutionBackwardData::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case ConvolutionBackwardData::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case ConvolutionBackwardData::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case ConvolutionBackwardData::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.compute_mode){ + case ConvolutionBackwardData::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case ConvolutionBackwardData::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + switch (op_.strategy){ + case ConvolutionBackwardData::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case ConvolutionBackwardData::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case ConvolutionBackwardData::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case ConvolutionBackwardData::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + props_.emplace_back("dtype", op_.dtype.name()); + return props_; +} +std::string ConvolutionBackwardData_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ConvolutionBackwardData"; +} +} // anonymous namespace +OP_TRAIT_REG(ConvolutionBackwardData, ConvolutionBackwardData) + .hash(ConvolutionBackwardData_hash_impl) + .is_same_st(ConvolutionBackwardData_is_same_st_impl) + .props(ConvolutionBackwardData_props_impl) + .make_name(ConvolutionBackwardData_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Copy); + +namespace { +size_t Copy_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node)); + return val; +} +bool Copy_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.comp_node != b_.comp_node) return false; + return true; +} +std::vector> Copy_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("comp_node", op_.comp_node.to_string()); + return props_; +} +std::string Copy_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Copy"; +} +} // anonymous namespace +OP_TRAIT_REG(Copy, Copy) + .hash(Copy_hash_impl) + .is_same_st(Copy_is_same_st_impl) + .props(Copy_props_impl) + .make_name(Copy_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Correlation); + +namespace { +size_t Correlation_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.kernel_size)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.max_displacement)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride1)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride2)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_size)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.is_multiply)); + return val; +} +bool Correlation_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.format != b_.format) return false; + if (a_.kernel_size != b_.kernel_size) return false; + if (a_.max_displacement != b_.max_displacement) return false; + if (a_.stride1 != b_.stride1) return false; + if (a_.stride2 != b_.stride2) return false; + if (a_.pad_size != b_.pad_size) return false; + if (a_.is_multiply != b_.is_multiply) return false; + return true; +} +std::vector> Correlation_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.format){ + case Correlation::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case Correlation::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case Correlation::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case Correlation::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case Correlation::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case Correlation::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case Correlation::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case Correlation::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case Correlation::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case Correlation::Format::NCHW_WINOGRAD: + props_.emplace_back("format", "NCHW_WINOGRAD"); + break; + case Correlation::Format::NCHW88_WINOGRAD: + props_.emplace_back("format", "NCHW88_WINOGRAD"); + break; + case Correlation::Format::NCHW44_WINOGRAD: + props_.emplace_back("format", "NCHW44_WINOGRAD"); + break; + case Correlation::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case Correlation::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case Correlation::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case Correlation::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case Correlation::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case Correlation::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case Correlation::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case Correlation::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + props_.emplace_back("kernel_size", std::to_string(op_.kernel_size)); + props_.emplace_back("max_displacement", std::to_string(op_.max_displacement)); + props_.emplace_back("stride1", std::to_string(op_.stride1)); + props_.emplace_back("stride2", std::to_string(op_.stride2)); + props_.emplace_back("pad_size", std::to_string(op_.pad_size)); + props_.emplace_back("is_multiply", std::to_string(op_.is_multiply)); + return props_; +} +std::string Correlation_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Correlation"; +} +} // anonymous namespace +OP_TRAIT_REG(Correlation, Correlation) + .hash(Correlation_hash_impl) + .is_same_st(Correlation_is_same_st_impl) + .props(Correlation_props_impl) + .make_name(Correlation_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Cumsum); + +namespace { +size_t Cumsum_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.exclusive)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.reverse)); + return val; +} +bool Cumsum_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + if (a_.exclusive != b_.exclusive) return false; + if (a_.reverse != b_.reverse) return false; + return true; +} +std::vector> Cumsum_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + props_.emplace_back("exclusive", std::to_string(op_.exclusive)); + props_.emplace_back("reverse", std::to_string(op_.reverse)); + return props_; +} +std::string Cumsum_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Cumsum"; +} +} // anonymous namespace +OP_TRAIT_REG(Cumsum, Cumsum) + .hash(Cumsum_hash_impl) + .is_same_st(Cumsum_is_same_st_impl) + .props(Cumsum_props_impl) + .make_name(Cumsum_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(CvtColor); + +namespace { +size_t CvtColor_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + return val; +} +bool CvtColor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + return true; +} +std::vector> CvtColor_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case CvtColor::Mode::RGB2GRAY: + props_.emplace_back("mode", "RGB2GRAY"); + break; + case CvtColor::Mode::RGB2YUV: + props_.emplace_back("mode", "RGB2YUV"); + break; + case CvtColor::Mode::YUV2RGB: + props_.emplace_back("mode", "YUV2RGB"); + break; + case CvtColor::Mode::GRAY2RGB: + props_.emplace_back("mode", "GRAY2RGB"); + break; + case CvtColor::Mode::RGBA2RGB: + props_.emplace_back("mode", "RGBA2RGB"); + break; + case CvtColor::Mode::RGBA2BGR: + props_.emplace_back("mode", "RGBA2BGR"); + break; + case CvtColor::Mode::RGBA2GRAY: + props_.emplace_back("mode", "RGBA2GRAY"); + break; + case CvtColor::Mode::RGB2BGR: + props_.emplace_back("mode", "RGB2BGR"); + break; + case CvtColor::Mode::BGR2GRAY: + props_.emplace_back("mode", "BGR2GRAY"); + break; + case CvtColor::Mode::BGR2RGB: + props_.emplace_back("mode", "BGR2RGB"); + break; + case CvtColor::Mode::YUV2GRAY_NV21: + props_.emplace_back("mode", "YUV2GRAY_NV21"); + break; + case CvtColor::Mode::YUV2RGB_NV21: + props_.emplace_back("mode", "YUV2RGB_NV21"); + break; + case CvtColor::Mode::YUV2BGR_NV21: + props_.emplace_back("mode", "YUV2BGR_NV21"); + break; + case CvtColor::Mode::YUV2GRAY_NV12: + props_.emplace_back("mode", "YUV2GRAY_NV12"); + break; + case CvtColor::Mode::YUV2RGB_NV12: + props_.emplace_back("mode", "YUV2RGB_NV12"); + break; + case CvtColor::Mode::YUV2BGR_NV12: + props_.emplace_back("mode", "YUV2BGR_NV12"); + break; + case CvtColor::Mode::YUV2GRAY_YV12: + props_.emplace_back("mode", "YUV2GRAY_YV12"); + break; + case CvtColor::Mode::YUV2RGB_YV12: + props_.emplace_back("mode", "YUV2RGB_YV12"); + break; + case CvtColor::Mode::YUV2BGR_YV12: + props_.emplace_back("mode", "YUV2BGR_YV12"); + break; + case CvtColor::Mode::YUV2GRAY_YU12: + props_.emplace_back("mode", "YUV2GRAY_YU12"); + break; + case CvtColor::Mode::YUV2RGB_YU12: + props_.emplace_back("mode", "YUV2RGB_YU12"); + break; + case CvtColor::Mode::YUV2BGR_YU12: + props_.emplace_back("mode", "YUV2BGR_YU12"); + break; + case CvtColor::Mode::YCrCb2RGB: + props_.emplace_back("mode", "YCrCb2RGB"); + break; + case CvtColor::Mode::YCrCb2BGR: + props_.emplace_back("mode", "YCrCb2BGR"); + break; + case CvtColor::Mode::BT601_YUV2RGB_NV21: + props_.emplace_back("mode", "BT601_YUV2RGB_NV21"); + break; + case CvtColor::Mode::BT601_YUV2BGR_NV21: + props_.emplace_back("mode", "BT601_YUV2BGR_NV21"); + break; + case CvtColor::Mode::BT601_YUV2RGB_NV12: + props_.emplace_back("mode", "BT601_YUV2RGB_NV12"); + break; + case CvtColor::Mode::BT601_YUV2BGR_NV12: + props_.emplace_back("mode", "BT601_YUV2BGR_NV12"); + break; + case CvtColor::Mode::BT601_YUV2RGB_YV12: + props_.emplace_back("mode", "BT601_YUV2RGB_YV12"); + break; + case CvtColor::Mode::BT601_YUV2BGR_YV12: + props_.emplace_back("mode", "BT601_YUV2BGR_YV12"); + break; + case CvtColor::Mode::BT601_YUV2RGB_YU12: + props_.emplace_back("mode", "BT601_YUV2RGB_YU12"); + break; + case CvtColor::Mode::BT601_YUV2BGR_YU12: + props_.emplace_back("mode", "BT601_YUV2BGR_YU12"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + return props_; +} +std::string CvtColor_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "CvtColor"; +} +} // anonymous namespace +OP_TRAIT_REG(CvtColor, CvtColor) + .hash(CvtColor_hash_impl) + .is_same_st(CvtColor_is_same_st_impl) + .props(CvtColor_props_impl) + .make_name(CvtColor_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(DeformableConv); + +namespace { +size_t DeformableConv_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + return val; +} +bool DeformableConv_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.format != b_.format) return false; + if (a_.compute_mode != b_.compute_mode) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + return true; +} +std::vector> DeformableConv_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case DeformableConv::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case DeformableConv::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.sparse){ + case DeformableConv::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case DeformableConv::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.format){ + case DeformableConv::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case DeformableConv::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case DeformableConv::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case DeformableConv::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case DeformableConv::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case DeformableConv::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case DeformableConv::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case DeformableConv::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case DeformableConv::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case DeformableConv::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case DeformableConv::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case DeformableConv::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case DeformableConv::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case DeformableConv::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case DeformableConv::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case DeformableConv::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case DeformableConv::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case DeformableConv::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.compute_mode){ + case DeformableConv::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case DeformableConv::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + switch (op_.strategy){ + case DeformableConv::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case DeformableConv::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case DeformableConv::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case DeformableConv::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + return props_; +} +std::string DeformableConv_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "DeformableConv"; +} +} // anonymous namespace +OP_TRAIT_REG(DeformableConv, DeformableConv) + .hash(DeformableConv_hash_impl) + .is_same_st(DeformableConv_is_same_st_impl) + .props(DeformableConv_props_impl) + .make_name(DeformableConv_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(DeformablePSROIPooling); + +namespace { +size_t DeformablePSROIPooling_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.no_trans)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.spatial_scale)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.trans_std)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.part_size)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_per_part)); + return val; +} +bool DeformablePSROIPooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.no_trans != b_.no_trans) return false; + if (a_.spatial_scale != b_.spatial_scale) return false; + if (a_.trans_std != b_.trans_std) return false; + if (a_.pooled_h != b_.pooled_h) return false; + if (a_.pooled_w != b_.pooled_w) return false; + if (a_.part_size != b_.part_size) return false; + if (a_.sample_per_part != b_.sample_per_part) return false; + return true; +} +std::vector> DeformablePSROIPooling_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("no_trans", std::to_string(op_.no_trans)); + props_.emplace_back("spatial_scale", std::to_string(op_.spatial_scale)); + props_.emplace_back("trans_std", std::to_string(op_.trans_std)); + props_.emplace_back("pooled_h", std::to_string(op_.pooled_h)); + props_.emplace_back("pooled_w", std::to_string(op_.pooled_w)); + props_.emplace_back("part_size", std::to_string(op_.part_size)); + props_.emplace_back("sample_per_part", std::to_string(op_.sample_per_part)); + return props_; +} +std::string DeformablePSROIPooling_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "DeformablePSROIPooling"; +} +} // anonymous namespace +OP_TRAIT_REG(DeformablePSROIPooling, DeformablePSROIPooling) + .hash(DeformablePSROIPooling_hash_impl) + .is_same_st(DeformablePSROIPooling_is_same_st_impl) + .props(DeformablePSROIPooling_props_impl) + .make_name(DeformablePSROIPooling_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Diag); + +namespace { +size_t Diag_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.k)); + return val; +} +bool Diag_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.k != b_.k) return false; + return true; +} +std::vector> Diag_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("k", std::to_string(op_.k)); + return props_; +} +std::string Diag_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Diag"; +} +} // anonymous namespace +OP_TRAIT_REG(Diag, Diag) + .hash(Diag_hash_impl) + .is_same_st(Diag_is_same_st_impl) + .props(Diag_props_impl) + .make_name(Diag_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Dimshuffle); + +namespace { +size_t Dimshuffle_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pattern)); + return val; +} +bool Dimshuffle_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.pattern != b_.pattern) return false; + return true; +} +std::vector> Dimshuffle_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("pattern", "{std::vector}"); + return props_; +} +std::string Dimshuffle_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Dimshuffle"; +} +} // anonymous namespace +OP_TRAIT_REG(Dimshuffle, Dimshuffle) + .hash(Dimshuffle_hash_impl) + .is_same_st(Dimshuffle_is_same_st_impl) + .props(Dimshuffle_props_impl) + .make_name(Dimshuffle_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Dot); + +namespace { +size_t Dot_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + return val; +} +bool Dot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + return true; +} +std::vector> Dot_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + return props_; +} +std::string Dot_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Dot"; +} +} // anonymous namespace +OP_TRAIT_REG(Dot, Dot) + .hash(Dot_hash_impl) + .is_same_st(Dot_is_same_st_impl) + .props(Dot_props_impl) + .make_name(Dot_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Dropout); + +namespace { +size_t Dropout_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash_pair_combine( + mgb::hash(op_.drop_prob), + mgb::hash(op_.handle)) + ); + } +bool Dropout_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle && a_.drop_prob == b_.drop_prob;} +std::vector> Dropout_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("drop_prob", std::to_string(op_.drop_prob)); + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string Dropout_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Dropout"; +} +} // anonymous namespace +OP_TRAIT_REG(Dropout, Dropout) + .hash(Dropout_hash_impl) + .is_same_st(Dropout_is_same_st_impl) + .props(Dropout_props_impl) + .make_name(Dropout_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Elemwise); + +namespace { +size_t Elemwise_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + return val; +} +bool Elemwise_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + return true; +} +std::vector> Elemwise_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case Elemwise::Mode::RELU: + props_.emplace_back("mode", "RELU"); + break; + case Elemwise::Mode::ABS: + props_.emplace_back("mode", "ABS"); + break; + case Elemwise::Mode::ACOS: + props_.emplace_back("mode", "ACOS"); + break; + case Elemwise::Mode::ASIN: + props_.emplace_back("mode", "ASIN"); + break; + case Elemwise::Mode::CEIL: + props_.emplace_back("mode", "CEIL"); + break; + case Elemwise::Mode::COS: + props_.emplace_back("mode", "COS"); + break; + case Elemwise::Mode::EXP: + props_.emplace_back("mode", "EXP"); + break; + case Elemwise::Mode::EXPM1: + props_.emplace_back("mode", "EXPM1"); + break; + case Elemwise::Mode::FLOOR: + props_.emplace_back("mode", "FLOOR"); + break; + case Elemwise::Mode::LOG: + props_.emplace_back("mode", "LOG"); + break; + case Elemwise::Mode::LOG1P: + props_.emplace_back("mode", "LOG1P"); + break; + case Elemwise::Mode::NEGATE: + props_.emplace_back("mode", "NEGATE"); + break; + case Elemwise::Mode::SIGMOID: + props_.emplace_back("mode", "SIGMOID"); + break; + case Elemwise::Mode::SIN: + props_.emplace_back("mode", "SIN"); + break; + case Elemwise::Mode::TANH: + props_.emplace_back("mode", "TANH"); + break; + case Elemwise::Mode::ABS_GRAD: + props_.emplace_back("mode", "ABS_GRAD"); + break; + case Elemwise::Mode::ADD: + props_.emplace_back("mode", "ADD"); + break; + case Elemwise::Mode::FLOOR_DIV: + props_.emplace_back("mode", "FLOOR_DIV"); + break; + case Elemwise::Mode::MAX: + props_.emplace_back("mode", "MAX"); + break; + case Elemwise::Mode::MIN: + props_.emplace_back("mode", "MIN"); + break; + case Elemwise::Mode::MOD: + props_.emplace_back("mode", "MOD"); + break; + case Elemwise::Mode::MUL: + props_.emplace_back("mode", "MUL"); + break; + case Elemwise::Mode::POW: + props_.emplace_back("mode", "POW"); + break; + case Elemwise::Mode::SIGMOID_GRAD: + props_.emplace_back("mode", "SIGMOID_GRAD"); + break; + case Elemwise::Mode::SUB: + props_.emplace_back("mode", "SUB"); + break; + case Elemwise::Mode::SWITCH_GT0: + props_.emplace_back("mode", "SWITCH_GT0"); + break; + case Elemwise::Mode::TANH_GRAD: + props_.emplace_back("mode", "TANH_GRAD"); + break; + case Elemwise::Mode::TRUE_DIV: + props_.emplace_back("mode", "TRUE_DIV"); + break; + case Elemwise::Mode::LOG_SUM_EXP: + props_.emplace_back("mode", "LOG_SUM_EXP"); + break; + case Elemwise::Mode::LT: + props_.emplace_back("mode", "LT"); + break; + case Elemwise::Mode::LEQ: + props_.emplace_back("mode", "LEQ"); + break; + case Elemwise::Mode::EQ: + props_.emplace_back("mode", "EQ"); + break; + case Elemwise::Mode::SHL: + props_.emplace_back("mode", "SHL"); + break; + case Elemwise::Mode::SHR: + props_.emplace_back("mode", "SHR"); + break; + case Elemwise::Mode::COND_LEQ_MOV: + props_.emplace_back("mode", "COND_LEQ_MOV"); + break; + case Elemwise::Mode::FUSE_MUL_ADD3: + props_.emplace_back("mode", "FUSE_MUL_ADD3"); + break; + case Elemwise::Mode::FUSE_MUL_ADD4: + props_.emplace_back("mode", "FUSE_MUL_ADD4"); + break; + case Elemwise::Mode::FUSE_ADD_RELU: + props_.emplace_back("mode", "FUSE_ADD_RELU"); + break; + case Elemwise::Mode::FUSE_ADD_SIGMOID: + props_.emplace_back("mode", "FUSE_ADD_SIGMOID"); + break; + case Elemwise::Mode::FUSE_ADD_TANH: + props_.emplace_back("mode", "FUSE_ADD_TANH"); + break; + case Elemwise::Mode::FAST_TANH: + props_.emplace_back("mode", "FAST_TANH"); + break; + case Elemwise::Mode::FAST_TANH_GRAD: + props_.emplace_back("mode", "FAST_TANH_GRAD"); + break; + case Elemwise::Mode::ROUND: + props_.emplace_back("mode", "ROUND"); + break; + case Elemwise::Mode::RMULH: + props_.emplace_back("mode", "RMULH"); + break; + case Elemwise::Mode::ATAN2: + props_.emplace_back("mode", "ATAN2"); + break; + case Elemwise::Mode::ERF: + props_.emplace_back("mode", "ERF"); + break; + case Elemwise::Mode::ERFINV: + props_.emplace_back("mode", "ERFINV"); + break; + case Elemwise::Mode::ERFC: + props_.emplace_back("mode", "ERFC"); + break; + case Elemwise::Mode::ERFCINV: + props_.emplace_back("mode", "ERFCINV"); + break; + case Elemwise::Mode::H_SWISH: + props_.emplace_back("mode", "H_SWISH"); + break; + case Elemwise::Mode::H_SWISH_GRAD: + props_.emplace_back("mode", "H_SWISH_GRAD"); + break; + case Elemwise::Mode::FUSE_ADD_H_SWISH: + props_.emplace_back("mode", "FUSE_ADD_H_SWISH"); + break; + case Elemwise::Mode::NOT: + props_.emplace_back("mode", "NOT"); + break; + case Elemwise::Mode::AND: + props_.emplace_back("mode", "AND"); + break; + case Elemwise::Mode::OR: + props_.emplace_back("mode", "OR"); + break; + case Elemwise::Mode::XOR: + props_.emplace_back("mode", "XOR"); + break; + case Elemwise::Mode::SILU: + props_.emplace_back("mode", "SILU"); + break; + case Elemwise::Mode::SILU_GRAD: + props_.emplace_back("mode", "SILU_GRAD"); + break; + case Elemwise::Mode::GELU: + props_.emplace_back("mode", "GELU"); + break; + case Elemwise::Mode::GELU_GRAD: + props_.emplace_back("mode", "GELU_GRAD"); + break; + case Elemwise::Mode::COND_LT_MOV: + props_.emplace_back("mode", "COND_LT_MOV"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + return props_; +} +std::string Elemwise_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return to_string(op_.mode); + } +} // anonymous namespace +OP_TRAIT_REG(Elemwise, Elemwise) + .hash(Elemwise_hash_impl) + .is_same_st(Elemwise_is_same_st_impl) + .props(Elemwise_props_impl) + .make_name(Elemwise_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ElemwiseMultiType); + +namespace { +size_t ElemwiseMultiType_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + return val; +} +bool ElemwiseMultiType_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.dtype != b_.dtype) return false; + return true; +} +std::vector> ElemwiseMultiType_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32: + props_.emplace_back("mode", "FUSE_MUL_ADD3_INT16x32x32x32"); + break; + case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8: + props_.emplace_back("mode", "FUSE_MUL_ADD3_IXxF32xF32xI8"); + break; + case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8: + props_.emplace_back("mode", "ROUND_SHR_SATURATE_IXxI8xI8"); + break; + case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8: + props_.emplace_back("mode", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8"); + break; + case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8: + props_.emplace_back("mode", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8"); + break; + case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16: + props_.emplace_back("mode", "ROUND_SHR_SATURATE_IXxI8xI16"); + break; + case ElemwiseMultiType::Mode::QADD: + props_.emplace_back("mode", "QADD"); + break; + case ElemwiseMultiType::Mode::QFUSE_ADD_RELU: + props_.emplace_back("mode", "QFUSE_ADD_RELU"); + break; + case ElemwiseMultiType::Mode::QMUL: + props_.emplace_back("mode", "QMUL"); + break; + case ElemwiseMultiType::Mode::QMIN: + props_.emplace_back("mode", "QMIN"); + break; + case ElemwiseMultiType::Mode::QMAX: + props_.emplace_back("mode", "QMAX"); + break; + case ElemwiseMultiType::Mode::QSUB: + props_.emplace_back("mode", "QSUB"); + break; + case ElemwiseMultiType::Mode::QTRUE_DIV: + props_.emplace_back("mode", "QTRUE_DIV"); + break; + case ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID: + props_.emplace_back("mode", "QFUSE_ADD_SIGMOID"); + break; + case ElemwiseMultiType::Mode::QFUSE_ADD_TANH: + props_.emplace_back("mode", "QFUSE_ADD_TANH"); + break; + case ElemwiseMultiType::Mode::QRELU: + props_.emplace_back("mode", "QRELU"); + break; + case ElemwiseMultiType::Mode::QABS: + props_.emplace_back("mode", "QABS"); + break; + case ElemwiseMultiType::Mode::QSIGMOID: + props_.emplace_back("mode", "QSIGMOID"); + break; + case ElemwiseMultiType::Mode::QEXP: + props_.emplace_back("mode", "QEXP"); + break; + case ElemwiseMultiType::Mode::QTANH: + props_.emplace_back("mode", "QTANH"); + break; + case ElemwiseMultiType::Mode::QFUSE_MUL_ADD3: + props_.emplace_back("mode", "QFUSE_MUL_ADD3"); + break; + case ElemwiseMultiType::Mode::QFAST_TANH: + props_.emplace_back("mode", "QFAST_TANH"); + break; + case ElemwiseMultiType::Mode::QNEGATE: + props_.emplace_back("mode", "QNEGATE"); + break; + case ElemwiseMultiType::Mode::QACOS: + props_.emplace_back("mode", "QACOS"); + break; + case ElemwiseMultiType::Mode::QASIN: + props_.emplace_back("mode", "QASIN"); + break; + case ElemwiseMultiType::Mode::QCEIL: + props_.emplace_back("mode", "QCEIL"); + break; + case ElemwiseMultiType::Mode::QCOS: + props_.emplace_back("mode", "QCOS"); + break; + case ElemwiseMultiType::Mode::QEXPM1: + props_.emplace_back("mode", "QEXPM1"); + break; + case ElemwiseMultiType::Mode::QFLOOR: + props_.emplace_back("mode", "QFLOOR"); + break; + case ElemwiseMultiType::Mode::QLOG: + props_.emplace_back("mode", "QLOG"); + break; + case ElemwiseMultiType::Mode::QLOG1P: + props_.emplace_back("mode", "QLOG1P"); + break; + case ElemwiseMultiType::Mode::QSIN: + props_.emplace_back("mode", "QSIN"); + break; + case ElemwiseMultiType::Mode::QROUND: + props_.emplace_back("mode", "QROUND"); + break; + case ElemwiseMultiType::Mode::QERF: + props_.emplace_back("mode", "QERF"); + break; + case ElemwiseMultiType::Mode::QERFINV: + props_.emplace_back("mode", "QERFINV"); + break; + case ElemwiseMultiType::Mode::QERFC: + props_.emplace_back("mode", "QERFC"); + break; + case ElemwiseMultiType::Mode::QERFCINV: + props_.emplace_back("mode", "QERFCINV"); + break; + case ElemwiseMultiType::Mode::QABS_GRAD: + props_.emplace_back("mode", "QABS_GRAD"); + break; + case ElemwiseMultiType::Mode::QFLOOR_DIV: + props_.emplace_back("mode", "QFLOOR_DIV"); + break; + case ElemwiseMultiType::Mode::QMOD: + props_.emplace_back("mode", "QMOD"); + break; + case ElemwiseMultiType::Mode::QSIGMOID_GRAD: + props_.emplace_back("mode", "QSIGMOID_GRAD"); + break; + case ElemwiseMultiType::Mode::QSWITCH_GT0: + props_.emplace_back("mode", "QSWITCH_GT0"); + break; + case ElemwiseMultiType::Mode::QTANH_GRAD: + props_.emplace_back("mode", "QTANH_GRAD"); + break; + case ElemwiseMultiType::Mode::QLT: + props_.emplace_back("mode", "QLT"); + break; + case ElemwiseMultiType::Mode::QLEQ: + props_.emplace_back("mode", "QLEQ"); + break; + case ElemwiseMultiType::Mode::QEQ: + props_.emplace_back("mode", "QEQ"); + break; + case ElemwiseMultiType::Mode::QPOW: + props_.emplace_back("mode", "QPOW"); + break; + case ElemwiseMultiType::Mode::QLOG_SUM_EXP: + props_.emplace_back("mode", "QLOG_SUM_EXP"); + break; + case ElemwiseMultiType::Mode::QFAST_TANH_GRAD: + props_.emplace_back("mode", "QFAST_TANH_GRAD"); + break; + case ElemwiseMultiType::Mode::QATAN2: + props_.emplace_back("mode", "QATAN2"); + break; + case ElemwiseMultiType::Mode::QCOND_LEQ_MOV: + props_.emplace_back("mode", "QCOND_LEQ_MOV"); + break; + case ElemwiseMultiType::Mode::QH_SWISH: + props_.emplace_back("mode", "QH_SWISH"); + break; + case ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH: + props_.emplace_back("mode", "QFUSE_ADD_H_SWISH"); + break; + case ElemwiseMultiType::Mode::QH_SWISH_GRAD: + props_.emplace_back("mode", "QH_SWISH_GRAD"); + break; + case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32: + props_.emplace_back("mode", "FUSE_MUL_ADD3_INT16xF32xF32xF32"); + break; + case ElemwiseMultiType::Mode::MUL_INT16xF32xF32: + props_.emplace_back("mode", "MUL_INT16xF32xF32"); + break; + case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32: + props_.emplace_back("mode", "FUSE_MUL_ADD3_UINT8xF32xF32xF32"); + break; + case ElemwiseMultiType::Mode::QCOND_LT_MOV: + props_.emplace_back("mode", "QCOND_LT_MOV"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("dtype", op_.dtype.name()); + return props_; +} +std::string ElemwiseMultiType_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return to_string(op_.mode); + } +} // anonymous namespace +OP_TRAIT_REG(ElemwiseMultiType, ElemwiseMultiType) + .hash(ElemwiseMultiType_hash_impl) + .is_same_st(ElemwiseMultiType_is_same_st_impl) + .props(ElemwiseMultiType_props_impl) + .make_name(ElemwiseMultiType_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ExternOpr); + +namespace { +size_t ExternOpr_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash_pair_combine( + mgb::hash(op_.name), + mgb::hash(op_.data)) + ); + } +bool ExternOpr_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.output_shapes != b_.output_shapes) return false; + if (a_.name != b_.name) return false; + if (a_.data != b_.data) return false; + if (a_.data_len != b_.data_len) return false; + if (a_.output_dtypes != b_.output_dtypes) return false; + return true; +} +std::vector> ExternOpr_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("output_shapes", "{std::vector}"); + props_.emplace_back("name", op_.name); + props_.emplace_back("data", op_.data); + props_.emplace_back("data_len", std::to_string(op_.data_len)); + props_.emplace_back("output_dtypes", "{std::vector}"); + return props_; +} +std::string ExternOpr_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ExternOpr"; +} +} // anonymous namespace +OP_TRAIT_REG(ExternOpr, ExternOpr) + .hash(ExternOpr_hash_impl) + .is_same_st(ExternOpr_is_same_st_impl) + .props(ExternOpr_props_impl) + .make_name(ExternOpr_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Eye); + +namespace { +size_t Eye_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.k)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node)); + return val; +} +bool Eye_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.k != b_.k) return false; + if (a_.dtype != b_.dtype) return false; + if (a_.comp_node != b_.comp_node) return false; + return true; +} +std::vector> Eye_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("k", std::to_string(op_.k)); + props_.emplace_back("dtype", op_.dtype.name()); + props_.emplace_back("comp_node", op_.comp_node.to_string()); + return props_; +} +std::string Eye_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Eye"; +} +} // anonymous namespace +OP_TRAIT_REG(Eye, Eye) + .hash(Eye_hash_impl) + .is_same_st(Eye_is_same_st_impl) + .props(Eye_props_impl) + .make_name(Eye_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(FakeQuant); + +namespace { +size_t FakeQuant_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax)); + return val; +} +bool FakeQuant_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.qmin != b_.qmin) return false; + if (a_.qmax != b_.qmax) return false; + return true; +} +std::vector> FakeQuant_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("qmin", std::to_string(op_.qmin)); + props_.emplace_back("qmax", std::to_string(op_.qmax)); + return props_; +} +std::string FakeQuant_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "FakeQuant"; +} +} // anonymous namespace +OP_TRAIT_REG(FakeQuant, FakeQuant) + .hash(FakeQuant_hash_impl) + .is_same_st(FakeQuant_is_same_st_impl) + .props(FakeQuant_props_impl) + .make_name(FakeQuant_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(FastpathCopy); + +namespace { +size_t FastpathCopy_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + return val; +} +bool FastpathCopy_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + return true; +} +std::vector> FastpathCopy_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + return props_; +} +std::string FastpathCopy_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "FastpathCopy"; +} +} // anonymous namespace +OP_TRAIT_REG(FastpathCopy, FastpathCopy) + .hash(FastpathCopy_hash_impl) + .is_same_st(FastpathCopy_is_same_st_impl) + .props(FastpathCopy_props_impl) + .make_name(FastpathCopy_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(GammaRNG); + +namespace { +size_t GammaRNG_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash(op_.handle) + ); + } +bool GammaRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle;} +std::vector> GammaRNG_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string GammaRNG_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "GammaRNG"; +} +} // anonymous namespace +OP_TRAIT_REG(GammaRNG, GammaRNG) + .hash(GammaRNG_hash_impl) + .is_same_st(GammaRNG_is_same_st_impl) + .props(GammaRNG_props_impl) + .make_name(GammaRNG_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(GaussianRNG); + +namespace { +size_t GaussianRNG_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash_pair_combine( + mgb::hash(op_.handle), + mgb::hash_pair_combine( + mgb::hash(op_.mean), + mgb::hash_pair_combine( + mgb::hash(op_.std), + mgb::hash(op_.dtype.enumv()) + ) + ) + ) + ); + } +bool GaussianRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle && a_.mean == b_.mean && a_.std == b_.std && a_.dtype == b_.dtype;} +std::vector> GaussianRNG_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("mean", std::to_string(op_.mean)); + props_.emplace_back("std", std::to_string(op_.std)); + props_.emplace_back("dtype", op_.dtype.name()); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string GaussianRNG_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "GaussianRNG"; +} +} // anonymous namespace +OP_TRAIT_REG(GaussianRNG, GaussianRNG) + .hash(GaussianRNG_hash_impl) + .is_same_st(GaussianRNG_is_same_st_impl) + .props(GaussianRNG_props_impl) + .make_name(GaussianRNG_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(GetVarShape); + +namespace { +size_t GetVarShape_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + return val; +} +bool GetVarShape_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + return true; +} +std::vector> GetVarShape_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + return props_; +} +std::string GetVarShape_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "GetVarShape"; +} +} // anonymous namespace +OP_TRAIT_REG(GetVarShape, GetVarShape) + .hash(GetVarShape_hash_impl) + .is_same_st(GetVarShape_is_same_st_impl) + .props(GetVarShape_props_impl) + .make_name(GetVarShape_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(GroupLocal); + +namespace { +size_t GroupLocal_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.sparse)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + return val; +} +bool GroupLocal_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.sparse != b_.sparse) return false; + if (a_.format != b_.format) return false; + if (a_.compute_mode != b_.compute_mode) return false; + return true; +} +std::vector> GroupLocal_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case GroupLocal::Mode::CROSS_CORRELATION: + props_.emplace_back("mode", "CROSS_CORRELATION"); + break; + case GroupLocal::Mode::CONVOLUTION: + props_.emplace_back("mode", "CONVOLUTION"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + switch (op_.sparse){ + case GroupLocal::Sparse::DENSE: + props_.emplace_back("sparse", "DENSE"); + break; + case GroupLocal::Sparse::GROUP: + props_.emplace_back("sparse", "GROUP"); + break; + default: + props_.emplace_back("sparse", "INVALID"); + break; + } + switch (op_.format){ + case GroupLocal::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case GroupLocal::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case GroupLocal::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case GroupLocal::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case GroupLocal::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case GroupLocal::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case GroupLocal::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case GroupLocal::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case GroupLocal::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case GroupLocal::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case GroupLocal::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case GroupLocal::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case GroupLocal::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case GroupLocal::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case GroupLocal::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case GroupLocal::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case GroupLocal::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case GroupLocal::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.compute_mode){ + case GroupLocal::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case GroupLocal::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + return props_; +} +std::string GroupLocal_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "GroupLocal"; +} +} // anonymous namespace +OP_TRAIT_REG(GroupLocal, GroupLocal) + .hash(GroupLocal_hash_impl) + .is_same_st(GroupLocal_is_same_st_impl) + .props(GroupLocal_props_impl) + .make_name(GroupLocal_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Identity); + +namespace { +size_t Identity_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + return val; +} +bool Identity_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + return true; +} +std::vector> Identity_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + return props_; +} +std::string Identity_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Identity"; +} +} // anonymous namespace +OP_TRAIT_REG(Identity, Identity) + .hash(Identity_hash_impl) + .is_same_st(Identity_is_same_st_impl) + .props(Identity_props_impl) + .make_name(Identity_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Images2Neibs); + +namespace { +size_t Images2Neibs_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w)); + return val; +} +bool Images2Neibs_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.window_h != b_.window_h) return false; + if (a_.window_w != b_.window_w) return false; + return true; +} +std::vector> Images2Neibs_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + props_.emplace_back("window_h", std::to_string(op_.window_h)); + props_.emplace_back("window_w", std::to_string(op_.window_w)); + return props_; +} +std::string Images2Neibs_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Images2Neibs"; +} +} // anonymous namespace +OP_TRAIT_REG(Images2Neibs, Images2Neibs) + .hash(Images2Neibs_hash_impl) + .is_same_st(Images2Neibs_is_same_st_impl) + .props(Images2Neibs_props_impl) + .make_name(Images2Neibs_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(IncrMeshIndexing); + +namespace { +size_t IncrMeshIndexing_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool IncrMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> IncrMeshIndexing_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string IncrMeshIndexing_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "IncrMeshIndexing"; +} +} // anonymous namespace +OP_TRAIT_REG(IncrMeshIndexing, IncrMeshIndexing) + .hash(IncrMeshIndexing_hash_impl) + .is_same_st(IncrMeshIndexing_is_same_st_impl) + .props(IncrMeshIndexing_props_impl) + .make_name(IncrMeshIndexing_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(IncrSubtensor); + +namespace { +size_t IncrSubtensor_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool IncrSubtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> IncrSubtensor_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string IncrSubtensor_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "IncrSubtensor"; +} +} // anonymous namespace +OP_TRAIT_REG(IncrSubtensor, IncrSubtensor) + .hash(IncrSubtensor_hash_impl) + .is_same_st(IncrSubtensor_is_same_st_impl) + .props(IncrSubtensor_props_impl) + .make_name(IncrSubtensor_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingIncrMultiAxisVec); + +namespace { +size_t IndexingIncrMultiAxisVec_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool IndexingIncrMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> IndexingIncrMultiAxisVec_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string IndexingIncrMultiAxisVec_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "IndexingIncrMultiAxisVec"; +} +} // anonymous namespace +OP_TRAIT_REG(IndexingIncrMultiAxisVec, IndexingIncrMultiAxisVec) + .hash(IndexingIncrMultiAxisVec_hash_impl) + .is_same_st(IndexingIncrMultiAxisVec_is_same_st_impl) + .props(IndexingIncrMultiAxisVec_props_impl) + .make_name(IndexingIncrMultiAxisVec_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingMultiAxisVec); + +namespace { +size_t IndexingMultiAxisVec_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool IndexingMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> IndexingMultiAxisVec_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string IndexingMultiAxisVec_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "IndexingMultiAxisVec"; +} +} // anonymous namespace +OP_TRAIT_REG(IndexingMultiAxisVec, IndexingMultiAxisVec) + .hash(IndexingMultiAxisVec_hash_impl) + .is_same_st(IndexingMultiAxisVec_is_same_st_impl) + .props(IndexingMultiAxisVec_props_impl) + .make_name(IndexingMultiAxisVec_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingOneHot); + +namespace { +size_t IndexingOneHot_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.ndim)); + return val; +} +bool IndexingOneHot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + if (a_.ndim != b_.ndim) return false; + return true; +} +std::vector> IndexingOneHot_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + props_.emplace_back("ndim", std::to_string(op_.ndim)); + return props_; +} +std::string IndexingOneHot_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "IndexingOneHot"; +} +} // anonymous namespace +OP_TRAIT_REG(IndexingOneHot, IndexingOneHot) + .hash(IndexingOneHot_hash_impl) + .is_same_st(IndexingOneHot_is_same_st_impl) + .props(IndexingOneHot_props_impl) + .make_name(IndexingOneHot_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingSetMultiAxisVec); + +namespace { +size_t IndexingSetMultiAxisVec_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool IndexingSetMultiAxisVec_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> IndexingSetMultiAxisVec_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string IndexingSetMultiAxisVec_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "IndexingSetMultiAxisVec"; +} +} // anonymous namespace +OP_TRAIT_REG(IndexingSetMultiAxisVec, IndexingSetMultiAxisVec) + .hash(IndexingSetMultiAxisVec_hash_impl) + .is_same_st(IndexingSetMultiAxisVec_is_same_st_impl) + .props(IndexingSetMultiAxisVec_props_impl) + .make_name(IndexingSetMultiAxisVec_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(IndexingSetOneHot); + +namespace { +size_t IndexingSetOneHot_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.ndim)); + return val; +} +bool IndexingSetOneHot_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + if (a_.ndim != b_.ndim) return false; + return true; +} +std::vector> IndexingSetOneHot_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + props_.emplace_back("ndim", std::to_string(op_.ndim)); + return props_; +} +std::string IndexingSetOneHot_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "IndexingSetOneHot"; +} +} // anonymous namespace +OP_TRAIT_REG(IndexingSetOneHot, IndexingSetOneHot) + .hash(IndexingSetOneHot_hash_impl) + .is_same_st(IndexingSetOneHot_is_same_st_impl) + .props(IndexingSetOneHot_props_impl) + .make_name(IndexingSetOneHot_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(InplaceAdd); + +namespace { +size_t InplaceAdd_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + return val; +} +bool InplaceAdd_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + return true; +} +std::vector> InplaceAdd_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + return props_; +} +std::string InplaceAdd_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "InplaceAdd"; +} +} // anonymous namespace +OP_TRAIT_REG(InplaceAdd, InplaceAdd) + .hash(InplaceAdd_hash_impl) + .is_same_st(InplaceAdd_is_same_st_impl) + .props(InplaceAdd_props_impl) + .make_name(InplaceAdd_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(LAMBUpdate); + +namespace { +size_t LAMBUpdate_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.beta_1)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.beta_2)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.step)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.lr)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.weight_decay)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.eps)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.bias_correction)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.always_adapt)); + return val; +} +bool LAMBUpdate_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.beta_1 != b_.beta_1) return false; + if (a_.beta_2 != b_.beta_2) return false; + if (a_.step != b_.step) return false; + if (a_.lr != b_.lr) return false; + if (a_.weight_decay != b_.weight_decay) return false; + if (a_.eps != b_.eps) return false; + if (a_.bias_correction != b_.bias_correction) return false; + if (a_.always_adapt != b_.always_adapt) return false; + return true; +} +std::vector> LAMBUpdate_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("beta_1", std::to_string(op_.beta_1)); + props_.emplace_back("beta_2", std::to_string(op_.beta_2)); + props_.emplace_back("step", std::to_string(op_.step)); + props_.emplace_back("lr", std::to_string(op_.lr)); + props_.emplace_back("weight_decay", std::to_string(op_.weight_decay)); + props_.emplace_back("eps", std::to_string(op_.eps)); + props_.emplace_back("bias_correction", std::to_string(op_.bias_correction)); + props_.emplace_back("always_adapt", std::to_string(op_.always_adapt)); + return props_; +} +std::string LAMBUpdate_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "LAMBUpdate"; +} +} // anonymous namespace +OP_TRAIT_REG(LAMBUpdate, LAMBUpdate) + .hash(LAMBUpdate_hash_impl) + .is_same_st(LAMBUpdate_is_same_st_impl) + .props(LAMBUpdate_props_impl) + .make_name(LAMBUpdate_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(LRN); + +namespace { +size_t LRN_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.n)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.k)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.alpha)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.beta)); + return val; +} +bool LRN_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.n != b_.n) return false; + if (a_.k != b_.k) return false; + if (a_.alpha != b_.alpha) return false; + if (a_.beta != b_.beta) return false; + return true; +} +std::vector> LRN_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("n", std::to_string(op_.n)); + props_.emplace_back("k", std::to_string(op_.k)); + props_.emplace_back("alpha", std::to_string(op_.alpha)); + props_.emplace_back("beta", std::to_string(op_.beta)); + return props_; +} +std::string LRN_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "LRN"; +} +} // anonymous namespace +OP_TRAIT_REG(LRN, LRN) + .hash(LRN_hash_impl) + .is_same_st(LRN_is_same_st_impl) + .props(LRN_props_impl) + .make_name(LRN_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSQ); + +namespace { +size_t LSQ_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax)); + return val; +} +bool LSQ_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.qmin != b_.qmin) return false; + if (a_.qmax != b_.qmax) return false; + return true; +} +std::vector> LSQ_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("qmin", std::to_string(op_.qmin)); + props_.emplace_back("qmax", std::to_string(op_.qmax)); + return props_; +} +std::string LSQ_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "LSQ"; +} +} // anonymous namespace +OP_TRAIT_REG(LSQ, LSQ) + .hash(LSQ_hash_impl) + .is_same_st(LSQ_is_same_st_impl) + .props(LSQ_props_impl) + .make_name(LSQ_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSTM); + +namespace { +size_t LSTM_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.num_layers)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.bidirectional)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.bias)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.hidden_size)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.proj_size)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dropout)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode)); + return val; +} +bool LSTM_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.num_layers != b_.num_layers) return false; + if (a_.bidirectional != b_.bidirectional) return false; + if (a_.bias != b_.bias) return false; + if (a_.hidden_size != b_.hidden_size) return false; + if (a_.proj_size != b_.proj_size) return false; + if (a_.dropout != b_.dropout) return false; + if (a_.fwd_mode != b_.fwd_mode) return false; + return true; +} +std::vector> LSTM_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("num_layers", std::to_string(op_.num_layers)); + props_.emplace_back("bidirectional", std::to_string(op_.bidirectional)); + props_.emplace_back("bias", std::to_string(op_.bias)); + props_.emplace_back("hidden_size", std::to_string(op_.hidden_size)); + props_.emplace_back("proj_size", std::to_string(op_.proj_size)); + props_.emplace_back("dropout", std::to_string(op_.dropout)); + switch (op_.fwd_mode){ + case LSTM::FwdMode::TRAINING: + props_.emplace_back("fwd_mode", "TRAINING"); + break; + case LSTM::FwdMode::INFERENCE: + props_.emplace_back("fwd_mode", "INFERENCE"); + break; + default: + props_.emplace_back("fwd_mode", "INVALID"); + break; + } + return props_; +} +std::string LSTM_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "LSTM"; +} +} // anonymous namespace +OP_TRAIT_REG(LSTM, LSTM) + .hash(LSTM_hash_impl) + .is_same_st(LSTM_is_same_st_impl) + .props(LSTM_props_impl) + .make_name(LSTM_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(LSTMCell); + +namespace { +size_t LSTMCell_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + return val; +} +bool LSTMCell_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + return true; +} +std::vector> LSTMCell_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + return props_; +} +std::string LSTMCell_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "LSTMCell"; +} +} // anonymous namespace +OP_TRAIT_REG(LSTMCell, LSTMCell) + .hash(LSTMCell_hash_impl) + .is_same_st(LSTMCell_is_same_st_impl) + .props(LSTMCell_props_impl) + .make_name(LSTMCell_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(LayerNorm); + +namespace { +size_t LayerNorm_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.affine)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.eps)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.normalized_dim)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.normalized_size)); + return val; +} +bool LayerNorm_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.affine != b_.affine) return false; + if (a_.eps != b_.eps) return false; + if (a_.normalized_dim != b_.normalized_dim) return false; + if (a_.normalized_size != b_.normalized_size) return false; + return true; +} +std::vector> LayerNorm_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("affine", std::to_string(op_.affine)); + props_.emplace_back("eps", std::to_string(op_.eps)); + props_.emplace_back("normalized_dim", std::to_string(op_.normalized_dim)); + props_.emplace_back("normalized_size", std::to_string(op_.normalized_size)); + return props_; +} +std::string LayerNorm_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "LayerNorm"; +} +} // anonymous namespace +OP_TRAIT_REG(LayerNorm, LayerNorm) + .hash(LayerNorm_hash_impl) + .is_same_st(LayerNorm_is_same_st_impl) + .props(LayerNorm_props_impl) + .make_name(LayerNorm_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Linspace); + +namespace { +size_t Linspace_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.endpoint)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.comp_node)); + return val; +} +bool Linspace_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.endpoint != b_.endpoint) return false; + if (a_.comp_node != b_.comp_node) return false; + return true; +} +std::vector> Linspace_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("endpoint", std::to_string(op_.endpoint)); + props_.emplace_back("comp_node", op_.comp_node.to_string()); + return props_; +} +std::string Linspace_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Linspace"; +} +} // anonymous namespace +OP_TRAIT_REG(Linspace, Linspace) + .hash(Linspace_hash_impl) + .is_same_st(Linspace_is_same_st_impl) + .props(Linspace_props_impl) + .make_name(Linspace_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(MagicMindRuntime); + +namespace { +size_t MagicMindRuntime_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size)); + return val; +} +bool MagicMindRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.buf != b_.buf) return false; + if (a_.buf_size != b_.buf_size) return false; + return true; +} +std::vector> MagicMindRuntime_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("buf", op_.buf); + props_.emplace_back("buf_size", std::to_string(op_.buf_size)); + return props_; +} +std::string MagicMindRuntime_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "MagicMindRuntime"; +} +} // anonymous namespace +OP_TRAIT_REG(MagicMindRuntime, MagicMindRuntime) + .hash(MagicMindRuntime_hash_impl) + .is_same_st(MagicMindRuntime_is_same_st_impl) + .props(MagicMindRuntime_props_impl) + .make_name(MagicMindRuntime_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(MatrixInverse); + +namespace { +size_t MatrixInverse_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + return val; +} +bool MatrixInverse_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + return true; +} +std::vector> MatrixInverse_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + return props_; +} +std::string MatrixInverse_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "MatrixInverse"; +} +} // anonymous namespace +OP_TRAIT_REG(MatrixInverse, MatrixInverse) + .hash(MatrixInverse_hash_impl) + .is_same_st(MatrixInverse_is_same_st_impl) + .props(MatrixInverse_props_impl) + .make_name(MatrixInverse_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(MatrixMul); + +namespace { +size_t MatrixMul_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeA)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.transposeB)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.compute_mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dimA)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dimB)); + return val; +} +bool MatrixMul_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.transposeA != b_.transposeA) return false; + if (a_.transposeB != b_.transposeB) return false; + if (a_.compute_mode != b_.compute_mode) return false; + if (a_.format != b_.format) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + if (a_.dimA != b_.dimA) return false; + if (a_.dimB != b_.dimB) return false; + return true; +} +std::vector> MatrixMul_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("transposeA", std::to_string(op_.transposeA)); + props_.emplace_back("transposeB", std::to_string(op_.transposeB)); + switch (op_.compute_mode){ + case MatrixMul::ComputeMode::DEFAULT: + props_.emplace_back("compute_mode", "DEFAULT"); + break; + case MatrixMul::ComputeMode::FLOAT32: + props_.emplace_back("compute_mode", "FLOAT32"); + break; + default: + props_.emplace_back("compute_mode", "INVALID"); + break; + } + switch (op_.format){ + case MatrixMul::Format::DEFAULT: + props_.emplace_back("format", "DEFAULT"); + break; + case MatrixMul::Format::MK4: + props_.emplace_back("format", "MK4"); + break; + case MatrixMul::Format::MK8: + props_.emplace_back("format", "MK8"); + break; + case MatrixMul::Format::MK4_DOT: + props_.emplace_back("format", "MK4_DOT"); + break; + case MatrixMul::Format::N32K4_DOT: + props_.emplace_back("format", "N32K4_DOT"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.strategy){ + case MatrixMul::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case MatrixMul::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case MatrixMul::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case MatrixMul::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + props_.emplace_back("dimA", std::to_string(op_.dimA)); + props_.emplace_back("dimB", std::to_string(op_.dimB)); + return props_; +} +std::string MatrixMul_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "MatrixMul"; +} +} // anonymous namespace +OP_TRAIT_REG(MatrixMul, MatrixMul) + .hash(MatrixMul_hash_impl) + .is_same_st(MatrixMul_is_same_st_impl) + .props(MatrixMul_props_impl) + .make_name(MatrixMul_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(MeshIndexing); + +namespace { +size_t MeshIndexing_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool MeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> MeshIndexing_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string MeshIndexing_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "MeshIndexing"; +} +} // anonymous namespace +OP_TRAIT_REG(MeshIndexing, MeshIndexing) + .hash(MeshIndexing_hash_impl) + .is_same_st(MeshIndexing_is_same_st_impl) + .props(MeshIndexing_props_impl) + .make_name(MeshIndexing_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(NMSKeep); + +namespace { +size_t NMSKeep_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.iou_thresh)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.max_output)); + return val; +} +bool NMSKeep_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.iou_thresh != b_.iou_thresh) return false; + if (a_.max_output != b_.max_output) return false; + return true; +} +std::vector> NMSKeep_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("iou_thresh", std::to_string(op_.iou_thresh)); + props_.emplace_back("max_output", std::to_string(op_.max_output)); + return props_; +} +std::string NMSKeep_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "NMSKeep"; +} +} // anonymous namespace +OP_TRAIT_REG(NMSKeep, NMSKeep) + .hash(NMSKeep_hash_impl) + .is_same_st(NMSKeep_is_same_st_impl) + .props(NMSKeep_props_impl) + .make_name(NMSKeep_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(NvOf); + +namespace { +size_t NvOf_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.precision)); + return val; +} +bool NvOf_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.precision != b_.precision) return false; + return true; +} +std::vector> NvOf_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("precision", std::to_string(op_.precision)); + return props_; +} +std::string NvOf_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "NvOf"; +} +} // anonymous namespace +OP_TRAIT_REG(NvOf, NvOf) + .hash(NvOf_hash_impl) + .is_same_st(NvOf_is_same_st_impl) + .props(NvOf_props_impl) + .make_name(NvOf_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Padding); + +namespace { +size_t Padding_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim0)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim1)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim2)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim3)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim4)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim5)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.front_offset_dim6)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim0)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim1)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim2)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim3)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim4)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim5)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.back_offset_dim6)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.padding_val)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.padding_mode)); + return val; +} +bool Padding_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.front_offset_dim0 != b_.front_offset_dim0) return false; + if (a_.front_offset_dim1 != b_.front_offset_dim1) return false; + if (a_.front_offset_dim2 != b_.front_offset_dim2) return false; + if (a_.front_offset_dim3 != b_.front_offset_dim3) return false; + if (a_.front_offset_dim4 != b_.front_offset_dim4) return false; + if (a_.front_offset_dim5 != b_.front_offset_dim5) return false; + if (a_.front_offset_dim6 != b_.front_offset_dim6) return false; + if (a_.back_offset_dim0 != b_.back_offset_dim0) return false; + if (a_.back_offset_dim1 != b_.back_offset_dim1) return false; + if (a_.back_offset_dim2 != b_.back_offset_dim2) return false; + if (a_.back_offset_dim3 != b_.back_offset_dim3) return false; + if (a_.back_offset_dim4 != b_.back_offset_dim4) return false; + if (a_.back_offset_dim5 != b_.back_offset_dim5) return false; + if (a_.back_offset_dim6 != b_.back_offset_dim6) return false; + if (a_.padding_val != b_.padding_val) return false; + if (a_.padding_mode != b_.padding_mode) return false; + return true; +} +std::vector> Padding_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("front_offset_dim0", std::to_string(op_.front_offset_dim0)); + props_.emplace_back("front_offset_dim1", std::to_string(op_.front_offset_dim1)); + props_.emplace_back("front_offset_dim2", std::to_string(op_.front_offset_dim2)); + props_.emplace_back("front_offset_dim3", std::to_string(op_.front_offset_dim3)); + props_.emplace_back("front_offset_dim4", std::to_string(op_.front_offset_dim4)); + props_.emplace_back("front_offset_dim5", std::to_string(op_.front_offset_dim5)); + props_.emplace_back("front_offset_dim6", std::to_string(op_.front_offset_dim6)); + props_.emplace_back("back_offset_dim0", std::to_string(op_.back_offset_dim0)); + props_.emplace_back("back_offset_dim1", std::to_string(op_.back_offset_dim1)); + props_.emplace_back("back_offset_dim2", std::to_string(op_.back_offset_dim2)); + props_.emplace_back("back_offset_dim3", std::to_string(op_.back_offset_dim3)); + props_.emplace_back("back_offset_dim4", std::to_string(op_.back_offset_dim4)); + props_.emplace_back("back_offset_dim5", std::to_string(op_.back_offset_dim5)); + props_.emplace_back("back_offset_dim6", std::to_string(op_.back_offset_dim6)); + props_.emplace_back("padding_val", std::to_string(op_.padding_val)); + switch (op_.padding_mode){ + case Padding::PaddingMode::REPLICATE: + props_.emplace_back("padding_mode", "REPLICATE"); + break; + case Padding::PaddingMode::REFLECT: + props_.emplace_back("padding_mode", "REFLECT"); + break; + case Padding::PaddingMode::CONSTANT: + props_.emplace_back("padding_mode", "CONSTANT"); + break; + default: + props_.emplace_back("padding_mode", "INVALID"); + break; + } + return props_; +} +std::string Padding_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Padding"; +} +} // anonymous namespace +OP_TRAIT_REG(Padding, Padding) + .hash(Padding_hash_impl) + .is_same_st(Padding_is_same_st_impl) + .props(Padding_props_impl) + .make_name(Padding_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ParamPackConcat); + +namespace { +size_t ParamPackConcat_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.offsets)); + return val; +} +bool ParamPackConcat_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.offsets != b_.offsets) return false; + return true; +} +std::vector> ParamPackConcat_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("offsets", "{std::vector}"); + return props_; +} +std::string ParamPackConcat_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ParamPackConcat"; +} +} // anonymous namespace +OP_TRAIT_REG(ParamPackConcat, ParamPackConcat) + .hash(ParamPackConcat_hash_impl) + .is_same_st(ParamPackConcat_is_same_st_impl) + .props(ParamPackConcat_props_impl) + .make_name(ParamPackConcat_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ParamPackSplit); + +namespace { +size_t ParamPackSplit_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.offsets)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.shapes)); + return val; +} +bool ParamPackSplit_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.offsets != b_.offsets) return false; + if (a_.shapes != b_.shapes) return false; + return true; +} +std::vector> ParamPackSplit_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("offsets", "{std::vector}"); + props_.emplace_back("shapes", "{std::vector}"); + return props_; +} +std::string ParamPackSplit_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ParamPackSplit"; +} +} // anonymous namespace +OP_TRAIT_REG(ParamPackSplit, ParamPackSplit) + .hash(ParamPackSplit_hash_impl) + .is_same_st(ParamPackSplit_is_same_st_impl) + .props(ParamPackSplit_props_impl) + .make_name(ParamPackSplit_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(PermutationRNG); + +namespace { +size_t PermutationRNG_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash_pair_combine( + mgb::hash(op_.handle), + mgb::hash(op_.dtype.enumv()) + ) + ); + } +bool PermutationRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle && a_.dtype == b_.dtype;} +std::vector> PermutationRNG_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("dtype", op_.dtype.name()); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string PermutationRNG_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "PermutationRNG"; +} +} // anonymous namespace +OP_TRAIT_REG(PermutationRNG, PermutationRNG) + .hash(PermutationRNG_hash_impl) + .is_same_st(PermutationRNG_is_same_st_impl) + .props(PermutationRNG_props_impl) + .make_name(PermutationRNG_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(PixelShuffle); + +namespace { +size_t PixelShuffle_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.factor)); + return val; +} +bool PixelShuffle_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.factor != b_.factor) return false; + return true; +} +std::vector> PixelShuffle_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("factor", std::to_string(op_.factor)); + return props_; +} +std::string PixelShuffle_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "PixelShuffle"; +} +} // anonymous namespace +OP_TRAIT_REG(PixelShuffle, PixelShuffle) + .hash(PixelShuffle_hash_impl) + .is_same_st(PixelShuffle_is_same_st_impl) + .props(PixelShuffle_props_impl) + .make_name(PixelShuffle_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(PixelShuffleBackward); + +namespace { +size_t PixelShuffleBackward_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.factor)); + return val; +} +bool PixelShuffleBackward_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.factor != b_.factor) return false; + return true; +} +std::vector> PixelShuffleBackward_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("factor", std::to_string(op_.factor)); + return props_; +} +std::string PixelShuffleBackward_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "PixelShuffleBackward"; +} +} // anonymous namespace +OP_TRAIT_REG(PixelShuffleBackward, PixelShuffleBackward) + .hash(PixelShuffleBackward_hash_impl) + .is_same_st(PixelShuffleBackward_is_same_st_impl) + .props(PixelShuffleBackward_props_impl) + .make_name(PixelShuffleBackward_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(PoissonRNG); + +namespace { +size_t PoissonRNG_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash(op_.handle) + ); + } +bool PoissonRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle;} +std::vector> PoissonRNG_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string PoissonRNG_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "PoissonRNG"; +} +} // anonymous namespace +OP_TRAIT_REG(PoissonRNG, PoissonRNG) + .hash(PoissonRNG_hash_impl) + .is_same_st(PoissonRNG_is_same_st_impl) + .props(PoissonRNG_props_impl) + .make_name(PoissonRNG_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Pooling); + +namespace { +size_t Pooling_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.strategy)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.workspace_limit)); + return val; +} +bool Pooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.window_h != b_.window_h) return false; + if (a_.window_w != b_.window_w) return false; + if (a_.format != b_.format) return false; + if (a_.strategy != b_.strategy) return false; + if (a_.workspace_limit != b_.workspace_limit) return false; + return true; +} +std::vector> Pooling_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case Pooling::Mode::MAX: + props_.emplace_back("mode", "MAX"); + break; + case Pooling::Mode::AVERAGE: + props_.emplace_back("mode", "AVERAGE"); + break; + case Pooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING: + props_.emplace_back("mode", "AVERAGE_COUNT_EXCLUDE_PADDING"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("window_h", std::to_string(op_.window_h)); + props_.emplace_back("window_w", std::to_string(op_.window_w)); + switch (op_.format){ + case Pooling::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case Pooling::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case Pooling::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case Pooling::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case Pooling::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case Pooling::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case Pooling::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case Pooling::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case Pooling::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case Pooling::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case Pooling::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case Pooling::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case Pooling::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case Pooling::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case Pooling::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case Pooling::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case Pooling::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case Pooling::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + switch (op_.strategy){ + case Pooling::Strategy::HEURISTIC: + props_.emplace_back("strategy", "HEURISTIC"); + break; + case Pooling::Strategy::PROFILE: + props_.emplace_back("strategy", "PROFILE"); + break; + case Pooling::Strategy::REPRODUCIBLE: + props_.emplace_back("strategy", "REPRODUCIBLE"); + break; + case Pooling::Strategy::OPTIMIZED: + props_.emplace_back("strategy", "OPTIMIZED"); + break; + default: + props_.emplace_back("strategy", "INVALID"); + break; + } + props_.emplace_back("workspace_limit", std::to_string(op_.workspace_limit)); + return props_; +} +std::string Pooling_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Pooling"; +} +} // anonymous namespace +OP_TRAIT_REG(Pooling, Pooling) + .hash(Pooling_hash_impl) + .is_same_st(Pooling_is_same_st_impl) + .props(Pooling_props_impl) + .make_name(Pooling_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(RNN); + +namespace { +size_t RNN_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.num_layers)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.bidirectional)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.bias)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.hidden_size)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dropout)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.fwd_mode)); + return val; +} +bool RNN_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.num_layers != b_.num_layers) return false; + if (a_.bidirectional != b_.bidirectional) return false; + if (a_.bias != b_.bias) return false; + if (a_.hidden_size != b_.hidden_size) return false; + if (a_.dropout != b_.dropout) return false; + if (a_.nonlineMode != b_.nonlineMode) return false; + if (a_.fwd_mode != b_.fwd_mode) return false; + return true; +} +std::vector> RNN_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("num_layers", std::to_string(op_.num_layers)); + props_.emplace_back("bidirectional", std::to_string(op_.bidirectional)); + props_.emplace_back("bias", std::to_string(op_.bias)); + props_.emplace_back("hidden_size", std::to_string(op_.hidden_size)); + props_.emplace_back("dropout", std::to_string(op_.dropout)); + switch (op_.nonlineMode){ + case RNN::NonlineMode::IDENTITY: + props_.emplace_back("nonlineMode", "IDENTITY"); + break; + case RNN::NonlineMode::RELU: + props_.emplace_back("nonlineMode", "RELU"); + break; + case RNN::NonlineMode::TANH: + props_.emplace_back("nonlineMode", "TANH"); + break; + default: + props_.emplace_back("nonlineMode", "INVALID"); + break; + } + switch (op_.fwd_mode){ + case RNN::FwdMode::TRAINING: + props_.emplace_back("fwd_mode", "TRAINING"); + break; + case RNN::FwdMode::INFERENCE: + props_.emplace_back("fwd_mode", "INFERENCE"); + break; + default: + props_.emplace_back("fwd_mode", "INVALID"); + break; + } + return props_; +} +std::string RNN_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "RNN"; +} +} // anonymous namespace +OP_TRAIT_REG(RNN, RNN) + .hash(RNN_hash_impl) + .is_same_st(RNN_is_same_st_impl) + .props(RNN_props_impl) + .make_name(RNN_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(RNNCell); + +namespace { +size_t RNNCell_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.nonlineMode)); + return val; +} +bool RNNCell_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.nonlineMode != b_.nonlineMode) return false; + return true; +} +std::vector> RNNCell_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.nonlineMode){ + case RNNCell::NonlineMode::IDENTITY: + props_.emplace_back("nonlineMode", "IDENTITY"); + break; + case RNNCell::NonlineMode::RELU: + props_.emplace_back("nonlineMode", "RELU"); + break; + case RNNCell::NonlineMode::TANH: + props_.emplace_back("nonlineMode", "TANH"); + break; + default: + props_.emplace_back("nonlineMode", "INVALID"); + break; + } + return props_; +} +std::string RNNCell_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "RNNCell"; +} +} // anonymous namespace +OP_TRAIT_REG(RNNCell, RNNCell) + .hash(RNNCell_hash_impl) + .is_same_st(RNNCell_is_same_st_impl) + .props(RNNCell_props_impl) + .make_name(RNNCell_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ROIAlign); + +namespace { +size_t ROIAlign_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.spatial_scale)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.offset)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_height)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pooled_width)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_height)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.sample_width)); + return val; +} +bool ROIAlign_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.format != b_.format) return false; + if (a_.spatial_scale != b_.spatial_scale) return false; + if (a_.offset != b_.offset) return false; + if (a_.pooled_height != b_.pooled_height) return false; + if (a_.pooled_width != b_.pooled_width) return false; + if (a_.sample_height != b_.sample_height) return false; + if (a_.sample_width != b_.sample_width) return false; + return true; +} +std::vector> ROIAlign_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case ROIAlign::Mode::MAX: + props_.emplace_back("mode", "MAX"); + break; + case ROIAlign::Mode::AVERAGE: + props_.emplace_back("mode", "AVERAGE"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + switch (op_.format){ + case ROIAlign::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case ROIAlign::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case ROIAlign::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case ROIAlign::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case ROIAlign::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case ROIAlign::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case ROIAlign::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case ROIAlign::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case ROIAlign::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case ROIAlign::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case ROIAlign::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case ROIAlign::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case ROIAlign::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case ROIAlign::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case ROIAlign::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case ROIAlign::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case ROIAlign::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case ROIAlign::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + props_.emplace_back("spatial_scale", std::to_string(op_.spatial_scale)); + props_.emplace_back("offset", std::to_string(op_.offset)); + props_.emplace_back("pooled_height", std::to_string(op_.pooled_height)); + props_.emplace_back("pooled_width", std::to_string(op_.pooled_width)); + props_.emplace_back("sample_height", std::to_string(op_.sample_height)); + props_.emplace_back("sample_width", std::to_string(op_.sample_width)); + return props_; +} +std::string ROIAlign_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ROIAlign"; +} +} // anonymous namespace +OP_TRAIT_REG(ROIAlign, ROIAlign) + .hash(ROIAlign_hash_impl) + .is_same_st(ROIAlign_is_same_st_impl) + .props(ROIAlign_props_impl) + .make_name(ROIAlign_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ROIPooling); + +namespace { +size_t ROIPooling_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.scale)); + return val; +} +bool ROIPooling_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.scale != b_.scale) return false; + return true; +} +std::vector> ROIPooling_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case ROIPooling::Mode::MAX: + props_.emplace_back("mode", "MAX"); + break; + case ROIPooling::Mode::AVERAGE: + props_.emplace_back("mode", "AVERAGE"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("scale", std::to_string(op_.scale)); + return props_; +} +std::string ROIPooling_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ROIPooling"; +} +} // anonymous namespace +OP_TRAIT_REG(ROIPooling, ROIPooling) + .hash(ROIPooling_hash_impl) + .is_same_st(ROIPooling_is_same_st_impl) + .props(ROIPooling_props_impl) + .make_name(ROIPooling_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Reduce); + +namespace { +size_t Reduce_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.data_type)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.keepdim)); + return val; +} +bool Reduce_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + if (a_.axis != b_.axis) return false; + if (a_.data_type != b_.data_type) return false; + if (a_.keepdim != b_.keepdim) return false; + return true; +} +std::vector> Reduce_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case Reduce::Mode::SUM: + props_.emplace_back("mode", "SUM"); + break; + case Reduce::Mode::SUM_SQR: + props_.emplace_back("mode", "SUM_SQR"); + break; + case Reduce::Mode::PRODUCT: + props_.emplace_back("mode", "PRODUCT"); + break; + case Reduce::Mode::MIN: + props_.emplace_back("mode", "MIN"); + break; + case Reduce::Mode::MAX: + props_.emplace_back("mode", "MAX"); + break; + case Reduce::Mode::MEAN: + props_.emplace_back("mode", "MEAN"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + props_.emplace_back("axis", std::to_string(op_.axis)); + switch (op_.data_type){ + case Reduce::DataType::DEFAULT: + props_.emplace_back("data_type", "DEFAULT"); + break; + case Reduce::DataType::FLOAT_IO16xC32: + props_.emplace_back("data_type", "FLOAT_IO16xC32"); + break; + case Reduce::DataType::FLOAT_O32xC32: + props_.emplace_back("data_type", "FLOAT_O32xC32"); + break; + case Reduce::DataType::FLOAT_O16xC32: + props_.emplace_back("data_type", "FLOAT_O16xC32"); + break; + case Reduce::DataType::QUINT_I8xO32: + props_.emplace_back("data_type", "QUINT_I8xO32"); + break; + case Reduce::DataType::QINT_I8xO32: + props_.emplace_back("data_type", "QINT_I8xO32"); + break; + default: + props_.emplace_back("data_type", "INVALID"); + break; + } + props_.emplace_back("keepdim", std::to_string(op_.keepdim)); + return props_; +} +std::string Reduce_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Reduce"; +} +} // anonymous namespace +OP_TRAIT_REG(Reduce, Reduce) + .hash(Reduce_hash_impl) + .is_same_st(Reduce_is_same_st_impl) + .props(Reduce_props_impl) + .make_name(Reduce_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Remap); + +namespace { +size_t Remap_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.border_type)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.scalar)); + return val; +} +bool Remap_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.imode != b_.imode) return false; + if (a_.border_type != b_.border_type) return false; + if (a_.format != b_.format) return false; + if (a_.scalar != b_.scalar) return false; + return true; +} +std::vector> Remap_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.imode){ + case Remap::InterpolationMode::NEAREST: + props_.emplace_back("imode", "NEAREST"); + break; + case Remap::InterpolationMode::LINEAR: + props_.emplace_back("imode", "LINEAR"); + break; + case Remap::InterpolationMode::AREA: + props_.emplace_back("imode", "AREA"); + break; + case Remap::InterpolationMode::CUBIC: + props_.emplace_back("imode", "CUBIC"); + break; + case Remap::InterpolationMode::LANCZOS4: + props_.emplace_back("imode", "LANCZOS4"); + break; + default: + props_.emplace_back("imode", "INVALID"); + break; + } + switch (op_.border_type){ + case Remap::BorderMode::REPLICATE: + props_.emplace_back("border_type", "REPLICATE"); + break; + case Remap::BorderMode::REFLECT: + props_.emplace_back("border_type", "REFLECT"); + break; + case Remap::BorderMode::REFLECT_101: + props_.emplace_back("border_type", "REFLECT_101"); + break; + case Remap::BorderMode::WRAP: + props_.emplace_back("border_type", "WRAP"); + break; + case Remap::BorderMode::CONSTANT: + props_.emplace_back("border_type", "CONSTANT"); + break; + case Remap::BorderMode::TRANSPARENT: + props_.emplace_back("border_type", "TRANSPARENT"); + break; + case Remap::BorderMode::ISOLATED: + props_.emplace_back("border_type", "ISOLATED"); + break; + default: + props_.emplace_back("border_type", "INVALID"); + break; + } + switch (op_.format){ + case Remap::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case Remap::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case Remap::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case Remap::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case Remap::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case Remap::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case Remap::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case Remap::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case Remap::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case Remap::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case Remap::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case Remap::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case Remap::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case Remap::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case Remap::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case Remap::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case Remap::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case Remap::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + props_.emplace_back("scalar", std::to_string(op_.scalar)); + return props_; +} +std::string Remap_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Remap"; +} +} // anonymous namespace +OP_TRAIT_REG(Remap, Remap) + .hash(Remap_hash_impl) + .is_same_st(Remap_is_same_st_impl) + .props(Remap_props_impl) + .make_name(Remap_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoteRecv); + +namespace { +size_t RemoteRecv_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.key)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.addr)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.port)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.rank_from)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.cn)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.shape)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + val = mgb::hash_pair_combine(val, mgb::hash(op_.backend)); + return val; +} +bool RemoteRecv_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.key != b_.key) return false; + if (a_.addr != b_.addr) return false; + if (a_.port != b_.port) return false; + if (a_.rank_from != b_.rank_from) return false; + if (a_.cn != b_.cn) return false; + if (a_.shape != b_.shape) return false; + if (a_.dtype != b_.dtype) return false; + if (a_.backend != b_.backend) return false; + return true; +} +std::vector> RemoteRecv_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("key", op_.key); + props_.emplace_back("addr", op_.addr); + props_.emplace_back("port", std::to_string(op_.port)); + props_.emplace_back("rank_from", std::to_string(op_.rank_from)); + props_.emplace_back("cn", op_.cn.to_string()); + props_.emplace_back("shape", "{std::vector}"); + props_.emplace_back("dtype", op_.dtype.name()); + props_.emplace_back("backend", op_.backend); + return props_; +} +std::string RemoteRecv_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "RemoteRecv"; +} +} // anonymous namespace +OP_TRAIT_REG(RemoteRecv, RemoteRecv) + .hash(RemoteRecv_hash_impl) + .is_same_st(RemoteRecv_is_same_st_impl) + .props(RemoteRecv_props_impl) + .make_name(RemoteRecv_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoteSend); + +namespace { +size_t RemoteSend_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.key)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.addr)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.port)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.rank_to)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.backend)); + return val; +} +bool RemoteSend_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.key != b_.key) return false; + if (a_.addr != b_.addr) return false; + if (a_.port != b_.port) return false; + if (a_.rank_to != b_.rank_to) return false; + if (a_.backend != b_.backend) return false; + return true; +} +std::vector> RemoteSend_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("key", op_.key); + props_.emplace_back("addr", op_.addr); + props_.emplace_back("port", std::to_string(op_.port)); + props_.emplace_back("rank_to", std::to_string(op_.rank_to)); + props_.emplace_back("backend", op_.backend); + return props_; +} +std::string RemoteSend_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "RemoteSend"; +} +} // anonymous namespace +OP_TRAIT_REG(RemoteSend, RemoteSend) + .hash(RemoteSend_hash_impl) + .is_same_st(RemoteSend_is_same_st_impl) + .props(RemoteSend_props_impl) + .make_name(RemoteSend_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(RemoveAxis); + +namespace { +size_t RemoveAxis_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + return val; +} +bool RemoveAxis_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + return true; +} +std::vector> RemoveAxis_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", "{std::vector}"); + return props_; +} +std::string RemoveAxis_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "RemoveAxis"; +} +} // anonymous namespace +OP_TRAIT_REG(RemoveAxis, RemoveAxis) + .hash(RemoveAxis_hash_impl) + .is_same_st(RemoveAxis_is_same_st_impl) + .props(RemoveAxis_props_impl) + .make_name(RemoveAxis_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Reshape); + +namespace { +size_t Reshape_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.shape)); + return val; +} +bool Reshape_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + if (a_.shape != b_.shape) return false; + return true; +} +std::vector> Reshape_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + props_.emplace_back("shape", "{std::vector}"); + return props_; +} +std::string Reshape_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Reshape"; +} +} // anonymous namespace +OP_TRAIT_REG(Reshape, Reshape) + .hash(Reshape_hash_impl) + .is_same_st(Reshape_is_same_st_impl) + .props(Reshape_props_impl) + .make_name(Reshape_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Resize); + +namespace { +size_t Resize_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + return val; +} +bool Resize_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.imode != b_.imode) return false; + if (a_.format != b_.format) return false; + return true; +} +std::vector> Resize_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.imode){ + case Resize::InterpolationMode::NEAREST: + props_.emplace_back("imode", "NEAREST"); + break; + case Resize::InterpolationMode::LINEAR: + props_.emplace_back("imode", "LINEAR"); + break; + case Resize::InterpolationMode::AREA: + props_.emplace_back("imode", "AREA"); + break; + case Resize::InterpolationMode::CUBIC: + props_.emplace_back("imode", "CUBIC"); + break; + case Resize::InterpolationMode::LANCZOS4: + props_.emplace_back("imode", "LANCZOS4"); + break; + default: + props_.emplace_back("imode", "INVALID"); + break; + } + switch (op_.format){ + case Resize::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case Resize::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case Resize::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case Resize::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case Resize::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case Resize::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case Resize::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case Resize::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case Resize::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case Resize::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case Resize::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case Resize::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case Resize::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case Resize::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case Resize::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case Resize::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case Resize::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case Resize::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + return props_; +} +std::string Resize_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Resize"; +} +} // anonymous namespace +OP_TRAIT_REG(Resize, Resize) + .hash(Resize_hash_impl) + .is_same_st(Resize_is_same_st_impl) + .props(Resize_props_impl) + .make_name(Resize_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(SVD); + +namespace { +size_t SVD_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.full_matrices)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.compute_uv)); + return val; +} +bool SVD_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.full_matrices != b_.full_matrices) return false; + if (a_.compute_uv != b_.compute_uv) return false; + return true; +} +std::vector> SVD_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("full_matrices", std::to_string(op_.full_matrices)); + props_.emplace_back("compute_uv", std::to_string(op_.compute_uv)); + return props_; +} +std::string SVD_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "SVD"; +} +} // anonymous namespace +OP_TRAIT_REG(SVD, SVD) + .hash(SVD_hash_impl) + .is_same_st(SVD_is_same_st_impl) + .props(SVD_props_impl) + .make_name(SVD_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(SetMeshIndexing); + +namespace { +size_t SetMeshIndexing_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool SetMeshIndexing_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> SetMeshIndexing_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string SetMeshIndexing_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "SetMeshIndexing"; +} +} // anonymous namespace +OP_TRAIT_REG(SetMeshIndexing, SetMeshIndexing) + .hash(SetMeshIndexing_hash_impl) + .is_same_st(SetMeshIndexing_is_same_st_impl) + .props(SetMeshIndexing_props_impl) + .make_name(SetMeshIndexing_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(SetSubtensor); + +namespace { +size_t SetSubtensor_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool SetSubtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> SetSubtensor_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string SetSubtensor_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "SetSubtensor"; +} +} // anonymous namespace +OP_TRAIT_REG(SetSubtensor, SetSubtensor) + .hash(SetSubtensor_hash_impl) + .is_same_st(SetSubtensor_is_same_st_impl) + .props(SetSubtensor_props_impl) + .make_name(SetSubtensor_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(ShuffleRNG); + +namespace { +size_t ShuffleRNG_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash(op_.handle) + ); + } +bool ShuffleRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle;} +std::vector> ShuffleRNG_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string ShuffleRNG_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "ShuffleRNG"; +} +} // anonymous namespace +OP_TRAIT_REG(ShuffleRNG, ShuffleRNG) + .hash(ShuffleRNG_hash_impl) + .is_same_st(ShuffleRNG_is_same_st_impl) + .props(ShuffleRNG_props_impl) + .make_name(ShuffleRNG_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(SlidingWindowTranspose); + +namespace { +size_t SlidingWindowTranspose_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.out_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.out_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.pad_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.stride_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dilate_w)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.window_h)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.window_w)); + return val; +} +bool SlidingWindowTranspose_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.out_h != b_.out_h) return false; + if (a_.out_w != b_.out_w) return false; + if (a_.pad_h != b_.pad_h) return false; + if (a_.pad_w != b_.pad_w) return false; + if (a_.stride_h != b_.stride_h) return false; + if (a_.stride_w != b_.stride_w) return false; + if (a_.dilate_h != b_.dilate_h) return false; + if (a_.dilate_w != b_.dilate_w) return false; + if (a_.window_h != b_.window_h) return false; + if (a_.window_w != b_.window_w) return false; + return true; +} +std::vector> SlidingWindowTranspose_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("out_h", std::to_string(op_.out_h)); + props_.emplace_back("out_w", std::to_string(op_.out_w)); + props_.emplace_back("pad_h", std::to_string(op_.pad_h)); + props_.emplace_back("pad_w", std::to_string(op_.pad_w)); + props_.emplace_back("stride_h", std::to_string(op_.stride_h)); + props_.emplace_back("stride_w", std::to_string(op_.stride_w)); + props_.emplace_back("dilate_h", std::to_string(op_.dilate_h)); + props_.emplace_back("dilate_w", std::to_string(op_.dilate_w)); + props_.emplace_back("window_h", std::to_string(op_.window_h)); + props_.emplace_back("window_w", std::to_string(op_.window_w)); + return props_; +} +std::string SlidingWindowTranspose_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "SlidingWindowTranspose"; +} +} // anonymous namespace +OP_TRAIT_REG(SlidingWindowTranspose, SlidingWindowTranspose) + .hash(SlidingWindowTranspose_hash_impl) + .is_same_st(SlidingWindowTranspose_is_same_st_impl) + .props(SlidingWindowTranspose_props_impl) + .make_name(SlidingWindowTranspose_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Softmax); + +namespace { +size_t Softmax_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + return val; +} +bool Softmax_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + return true; +} +std::vector> Softmax_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + return props_; +} +std::string Softmax_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Softmax"; +} +} // anonymous namespace +OP_TRAIT_REG(Softmax, Softmax) + .hash(Softmax_hash_impl) + .is_same_st(Softmax_is_same_st_impl) + .props(Softmax_props_impl) + .make_name(Softmax_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Split); + +namespace { +size_t Split_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.axis)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.nsections)); + return val; +} +bool Split_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.axis != b_.axis) return false; + if (a_.nsections != b_.nsections) return false; + return true; +} +std::vector> Split_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("axis", std::to_string(op_.axis)); + props_.emplace_back("nsections", std::to_string(op_.nsections)); + return props_; +} +std::string Split_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Split"; +} +} // anonymous namespace +OP_TRAIT_REG(Split, Split) + .hash(Split_hash_impl) + .is_same_st(Split_is_same_st_impl) + .props(Split_props_impl) + .make_name(Split_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(Subtensor); + +namespace { +size_t Subtensor_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.items)); + return val; +} +bool Subtensor_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.items != b_.items) return false; + return true; +} +std::vector> Subtensor_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("items", "{std::vector}"); + return props_; +} +std::string Subtensor_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "Subtensor"; +} +} // anonymous namespace +OP_TRAIT_REG(Subtensor, Subtensor) + .hash(Subtensor_hash_impl) + .is_same_st(Subtensor_is_same_st_impl) + .props(Subtensor_props_impl) + .make_name(Subtensor_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(TQT); + +namespace { +size_t TQT_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.qmin)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.qmax)); + return val; +} +bool TQT_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.qmin != b_.qmin) return false; + if (a_.qmax != b_.qmax) return false; + return true; +} +std::vector> TQT_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("qmin", std::to_string(op_.qmin)); + props_.emplace_back("qmax", std::to_string(op_.qmax)); + return props_; +} +std::string TQT_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "TQT"; +} +} // anonymous namespace +OP_TRAIT_REG(TQT, TQT) + .hash(TQT_hash_impl) + .is_same_st(TQT_is_same_st_impl) + .props(TQT_props_impl) + .make_name(TQT_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(TensorRTRuntime); + +namespace { +size_t TensorRTRuntime_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.buf_size)); + return val; +} +bool TensorRTRuntime_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.buf != b_.buf) return false; + if (a_.buf_size != b_.buf_size) return false; + return true; +} +std::vector> TensorRTRuntime_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("buf", op_.buf); + props_.emplace_back("buf_size", std::to_string(op_.buf_size)); + return props_; +} +std::string TensorRTRuntime_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "TensorRTRuntime"; +} +} // anonymous namespace +OP_TRAIT_REG(TensorRTRuntime, TensorRTRuntime) + .hash(TensorRTRuntime_hash_impl) + .is_same_st(TensorRTRuntime_is_same_st_impl) + .props(TensorRTRuntime_props_impl) + .make_name(TensorRTRuntime_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(TopK); + +namespace { +size_t TopK_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.mode)); + return val; +} +bool TopK_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.mode != b_.mode) return false; + return true; +} +std::vector> TopK_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.mode){ + case TopK::Mode::KTH_ONLY: + props_.emplace_back("mode", "KTH_ONLY"); + break; + case TopK::Mode::VALUE_IDX_NOSORT: + props_.emplace_back("mode", "VALUE_IDX_NOSORT"); + break; + case TopK::Mode::VALUE_IDX_SORTED: + props_.emplace_back("mode", "VALUE_IDX_SORTED"); + break; + default: + props_.emplace_back("mode", "INVALID"); + break; + } + return props_; +} +std::string TopK_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "TopK"; +} +} // anonymous namespace +OP_TRAIT_REG(TopK, TopK) + .hash(TopK_hash_impl) + .is_same_st(TopK_is_same_st_impl) + .props(TopK_props_impl) + .make_name(TopK_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(TypeCvt); + +namespace { +size_t TypeCvt_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::hash(op_.dtype.handle())); + return val; +} +bool TypeCvt_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.dtype != b_.dtype) return false; + return true; +} +std::vector> TypeCvt_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("dtype", op_.dtype.name()); + return props_; +} +std::string TypeCvt_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "TypeCvt"; +} +} // anonymous namespace +OP_TRAIT_REG(TypeCvt, TypeCvt) + .hash(TypeCvt_hash_impl) + .is_same_st(TypeCvt_is_same_st_impl) + .props(TypeCvt_props_impl) + .make_name(TypeCvt_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(UniformRNG); + +namespace { +size_t UniformRNG_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + + return mgb::hash_pair_combine( + mgb::hash(op_.dyn_typeinfo()), + mgb::hash_pair_combine( + mgb::hash(op_.handle), + mgb::hash(op_.dtype.enumv()) + ) + ); + } +bool UniformRNG_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); +return a_.handle == b_.handle && a_.dtype == b_.dtype;} +std::vector> UniformRNG_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + props_.emplace_back("seed", std::to_string(op_.seed)); + props_.emplace_back("dtype", op_.dtype.name()); + props_.emplace_back("handle", std::to_string(op_.handle)); + return props_; +} +std::string UniformRNG_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "UniformRNG"; +} +} // anonymous namespace +OP_TRAIT_REG(UniformRNG, UniformRNG) + .hash(UniformRNG_hash_impl) + .is_same_st(UniformRNG_is_same_st_impl) + .props(UniformRNG_props_impl) + .make_name(UniformRNG_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(WarpAffine); + +namespace { +size_t WarpAffine_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.border_mode)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.border_val)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + return val; +} +bool WarpAffine_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.imode != b_.imode) return false; + if (a_.border_mode != b_.border_mode) return false; + if (a_.border_val != b_.border_val) return false; + if (a_.format != b_.format) return false; + return true; +} +std::vector> WarpAffine_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.imode){ + case WarpAffine::InterpolationMode::NEAREST: + props_.emplace_back("imode", "NEAREST"); + break; + case WarpAffine::InterpolationMode::LINEAR: + props_.emplace_back("imode", "LINEAR"); + break; + case WarpAffine::InterpolationMode::AREA: + props_.emplace_back("imode", "AREA"); + break; + case WarpAffine::InterpolationMode::CUBIC: + props_.emplace_back("imode", "CUBIC"); + break; + case WarpAffine::InterpolationMode::LANCZOS4: + props_.emplace_back("imode", "LANCZOS4"); + break; + default: + props_.emplace_back("imode", "INVALID"); + break; + } + switch (op_.border_mode){ + case WarpAffine::BorderMode::REPLICATE: + props_.emplace_back("border_mode", "REPLICATE"); + break; + case WarpAffine::BorderMode::REFLECT: + props_.emplace_back("border_mode", "REFLECT"); + break; + case WarpAffine::BorderMode::REFLECT_101: + props_.emplace_back("border_mode", "REFLECT_101"); + break; + case WarpAffine::BorderMode::WRAP: + props_.emplace_back("border_mode", "WRAP"); + break; + case WarpAffine::BorderMode::CONSTANT: + props_.emplace_back("border_mode", "CONSTANT"); + break; + case WarpAffine::BorderMode::TRANSPARENT: + props_.emplace_back("border_mode", "TRANSPARENT"); + break; + case WarpAffine::BorderMode::ISOLATED: + props_.emplace_back("border_mode", "ISOLATED"); + break; + default: + props_.emplace_back("border_mode", "INVALID"); + break; + } + props_.emplace_back("border_val", std::to_string(op_.border_val)); + switch (op_.format){ + case WarpAffine::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case WarpAffine::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case WarpAffine::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case WarpAffine::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case WarpAffine::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case WarpAffine::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case WarpAffine::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case WarpAffine::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case WarpAffine::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case WarpAffine::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case WarpAffine::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case WarpAffine::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case WarpAffine::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case WarpAffine::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case WarpAffine::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case WarpAffine::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case WarpAffine::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case WarpAffine::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + return props_; +} +std::string WarpAffine_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "WarpAffine"; +} +} // anonymous namespace +OP_TRAIT_REG(WarpAffine, WarpAffine) + .hash(WarpAffine_hash_impl) + .is_same_st(WarpAffine_is_same_st_impl) + .props(WarpAffine_props_impl) + .make_name(WarpAffine_make_name_impl); + +MGB_DYN_TYPE_OBJ_FINAL_IMPL(WarpPerspective); + +namespace { +size_t WarpPerspective_hash_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + size_t val = mgb::hash(op_.dyn_typeinfo()); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.imode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.bmode)); + val = mgb::hash_pair_combine(val, mgb::enumhash()(op_.format)); + val = mgb::hash_pair_combine(val, mgb::hash(op_.border_val)); + return val; +} +bool WarpPerspective_is_same_st_impl(const OpDef& lhs_, const OpDef& rhs_) { + auto &&a_ = lhs_.cast_final_safe(), + &&b_ = rhs_.cast_final_safe(); + static_cast(a_); + static_cast(b_); + if (a_.imode != b_.imode) return false; + if (a_.bmode != b_.bmode) return false; + if (a_.format != b_.format) return false; + if (a_.border_val != b_.border_val) return false; + return true; +} +std::vector> WarpPerspective_props_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + std::vector> props_; + switch (op_.imode){ + case WarpPerspective::InterpolationMode::NEAREST: + props_.emplace_back("imode", "NEAREST"); + break; + case WarpPerspective::InterpolationMode::LINEAR: + props_.emplace_back("imode", "LINEAR"); + break; + case WarpPerspective::InterpolationMode::AREA: + props_.emplace_back("imode", "AREA"); + break; + case WarpPerspective::InterpolationMode::CUBIC: + props_.emplace_back("imode", "CUBIC"); + break; + case WarpPerspective::InterpolationMode::LANCZOS4: + props_.emplace_back("imode", "LANCZOS4"); + break; + default: + props_.emplace_back("imode", "INVALID"); + break; + } + switch (op_.bmode){ + case WarpPerspective::BorderMode::REPLICATE: + props_.emplace_back("bmode", "REPLICATE"); + break; + case WarpPerspective::BorderMode::REFLECT: + props_.emplace_back("bmode", "REFLECT"); + break; + case WarpPerspective::BorderMode::REFLECT_101: + props_.emplace_back("bmode", "REFLECT_101"); + break; + case WarpPerspective::BorderMode::WRAP: + props_.emplace_back("bmode", "WRAP"); + break; + case WarpPerspective::BorderMode::CONSTANT: + props_.emplace_back("bmode", "CONSTANT"); + break; + case WarpPerspective::BorderMode::TRANSPARENT: + props_.emplace_back("bmode", "TRANSPARENT"); + break; + case WarpPerspective::BorderMode::ISOLATED: + props_.emplace_back("bmode", "ISOLATED"); + break; + default: + props_.emplace_back("bmode", "INVALID"); + break; + } + switch (op_.format){ + case WarpPerspective::Format::NCHW: + props_.emplace_back("format", "NCHW"); + break; + case WarpPerspective::Format::NHWC: + props_.emplace_back("format", "NHWC"); + break; + case WarpPerspective::Format::NHWCD4: + props_.emplace_back("format", "NHWCD4"); + break; + case WarpPerspective::Format::NCHW4: + props_.emplace_back("format", "NCHW4"); + break; + case WarpPerspective::Format::NCHW8: + props_.emplace_back("format", "NCHW8"); + break; + case WarpPerspective::Format::NCHW32: + props_.emplace_back("format", "NCHW32"); + break; + case WarpPerspective::Format::NCHW88: + props_.emplace_back("format", "NCHW88"); + break; + case WarpPerspective::Format::NCHW44: + props_.emplace_back("format", "NCHW44"); + break; + case WarpPerspective::Format::NCHW44_DOT: + props_.emplace_back("format", "NCHW44_DOT"); + break; + case WarpPerspective::Format::NCHW4_NCHW32: + props_.emplace_back("format", "NCHW4_NCHW32"); + break; + case WarpPerspective::Format::NCHW32_NCHW4: + props_.emplace_back("format", "NCHW32_NCHW4"); + break; + case WarpPerspective::Format::NCHW4_NCHW: + props_.emplace_back("format", "NCHW4_NCHW"); + break; + case WarpPerspective::Format::NHWC_NCHW: + props_.emplace_back("format", "NHWC_NCHW"); + break; + case WarpPerspective::Format::NHWC_NCHW4_IC_SMALL: + props_.emplace_back("format", "NHWC_NCHW4_IC_SMALL"); + break; + case WarpPerspective::Format::NCHW_NCHW4_IC_SMALL: + props_.emplace_back("format", "NCHW_NCHW4_IC_SMALL"); + break; + case WarpPerspective::Format::CHWN4: + props_.emplace_back("format", "CHWN4"); + break; + case WarpPerspective::Format::NCHW64: + props_.emplace_back("format", "NCHW64"); + break; + case WarpPerspective::Format::NCHW4_NHWC: + props_.emplace_back("format", "NCHW4_NHWC"); + break; + default: + props_.emplace_back("format", "INVALID"); + break; + } + props_.emplace_back("border_val", std::to_string(op_.border_val)); + return props_; +} +std::string WarpPerspective_make_name_impl(const OpDef& def_) { + auto&& op_ = def_.cast_final_safe(); + static_cast(op_); + return "WarpPerspective"; +} +} // anonymous namespace +OP_TRAIT_REG(WarpPerspective, WarpPerspective) + .hash(WarpPerspective_hash_impl) + .is_same_st(WarpPerspective_is_same_st_impl) + .props(WarpPerspective_props_impl) + .make_name(WarpPerspective_make_name_impl); + +// clang-format on diff --git a/imperative/tablegen/generated/opdef.cpy.inl b/imperative/tablegen/generated/opdef.cpy.inl new file mode 100644 index 00000000..c19b251b --- /dev/null +++ b/imperative/tablegen/generated/opdef.cpy.inl @@ -0,0 +1,18249 @@ +// clang-format off + +template<> struct EnumTrait { + static constexpr const char *name = "AdaptivePooling.Mode"; + static constexpr std::underlying_type_t max = 3 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"MAX", "AVERAGE", "AVERAGE_COUNT_EXCLUDE_PADDING"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("MAX"), AdaptivePooling::Mode::MAX}, {normalize_enum("AVERAGE"), AdaptivePooling::Mode::AVERAGE}, {normalize_enum("AVERAGE_COUNT_EXCLUDE_PADDING"), AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING}}; +template<> PyObject* EnumWrapper::pyobj_insts[3] = {nullptr}; + +void _init_py_AdaptivePooling_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.AdaptivePooling.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("AdaptivePooling.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Mode::MAX; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Mode::AVERAGE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE_COUNT_EXCLUDE_PADDING", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "AdaptivePooling.Format"; + static constexpr std::underlying_type_t max = 18 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"NCHW", "NHWC", "NHWCD4", "NCHW4", "NCHW8", "NCHW32", "NCHW88", "NCHW44", "NCHW44_DOT", "NCHW4_NCHW32", "NCHW32_NCHW4", "NCHW4_NCHW", "NHWC_NCHW", "NHWC_NCHW4_IC_SMALL", "NCHW_NCHW4_IC_SMALL", "CHWN4", "NCHW64", "NCHW4_NHWC"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("NCHW"), AdaptivePooling::Format::NCHW}, {normalize_enum("NHWC"), AdaptivePooling::Format::NHWC}, {normalize_enum("NHWCD4"), AdaptivePooling::Format::NHWCD4}, {normalize_enum("NCHW4"), AdaptivePooling::Format::NCHW4}, {normalize_enum("NCHW8"), AdaptivePooling::Format::NCHW8}, {normalize_enum("NCHW32"), AdaptivePooling::Format::NCHW32}, {normalize_enum("NCHW88"), AdaptivePooling::Format::NCHW88}, {normalize_enum("NCHW44"), AdaptivePooling::Format::NCHW44}, {normalize_enum("NCHW44_DOT"), AdaptivePooling::Format::NCHW44_DOT}, {normalize_enum("NCHW4_NCHW32"), AdaptivePooling::Format::NCHW4_NCHW32}, {normalize_enum("NCHW32_NCHW4"), AdaptivePooling::Format::NCHW32_NCHW4}, {normalize_enum("NCHW4_NCHW"), AdaptivePooling::Format::NCHW4_NCHW}, {normalize_enum("NHWC_NCHW"), AdaptivePooling::Format::NHWC_NCHW}, {normalize_enum("NHWC_NCHW4_IC_SMALL"), AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL}, {normalize_enum("NCHW_NCHW4_IC_SMALL"), AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL}, {normalize_enum("CHWN4"), AdaptivePooling::Format::CHWN4}, {normalize_enum("NCHW64"), AdaptivePooling::Format::NCHW64}, {normalize_enum("NCHW4_NHWC"), AdaptivePooling::Format::NCHW4_NHWC}}; +template<> PyObject* EnumWrapper::pyobj_insts[18] = {nullptr}; + +void _init_py_AdaptivePooling_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.AdaptivePooling.Format", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Format").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("AdaptivePooling.Format").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NHWC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NHWCD4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWCD4", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW8; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW8", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW88; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88", inst) >= 0); + EnumWrapper::pyobj_insts[6] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW44; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44", inst) >= 0); + EnumWrapper::pyobj_insts[7] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW44_DOT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_DOT", inst) >= 0); + EnumWrapper::pyobj_insts[8] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW4_NCHW32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW32", inst) >= 0); + EnumWrapper::pyobj_insts[9] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW32_NCHW4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32_NCHW4", inst) >= 0); + EnumWrapper::pyobj_insts[10] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW4_NCHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW", inst) >= 0); + EnumWrapper::pyobj_insts[11] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NHWC_NCHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW", inst) >= 0); + EnumWrapper::pyobj_insts[12] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW4_IC_SMALL", inst) >= 0); + EnumWrapper::pyobj_insts[13] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_NCHW4_IC_SMALL", inst) >= 0); + EnumWrapper::pyobj_insts[14] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::CHWN4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CHWN4", inst) >= 0); + EnumWrapper::pyobj_insts[15] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW64; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW64", inst) >= 0); + EnumWrapper::pyobj_insts[16] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = AdaptivePooling::Format::NCHW4_NHWC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NHWC", inst) >= 0); + EnumWrapper::pyobj_insts[17] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(AdaptivePooling) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"format", serialization::dump(opdef.format)}, + {"shape", serialization::dump(opdef.shape)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("shape"); + if (iter != state.end()) { + opdef.shape = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(AdaptivePooling) + +int PyOp(AdaptivePooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "format", "shape", "scope", NULL}; + PyObject *mode = NULL, *format = NULL, *shape = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast(kwlist), &mode, &format, &shape, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (shape) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().shape = + py::cast(py::handle(shape)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(AdaptivePooling)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(AdaptivePooling, mode), py_set_generic(AdaptivePooling, mode), const_cast("mode"), NULL}, + {const_cast("format"), py_get_generic(AdaptivePooling, format), py_set_generic(AdaptivePooling, format), const_cast("format"), NULL}, + {const_cast("shape"), py_get_generic(AdaptivePooling, shape), py_set_generic(AdaptivePooling, shape), const_cast("shape"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(AdaptivePooling)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(AdaptivePooling)::getstate, METH_NOARGS, "AdaptivePooling getstate"}, + {const_cast("__setstate__"), PyOp(AdaptivePooling)::setstate, METH_VARARGS, "AdaptivePooling setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_AdaptivePooling(py::module m) { + using py_op = PyOp(AdaptivePooling); + auto& py_type = PyOpType(AdaptivePooling); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.AdaptivePooling"; + py_type.tp_basicsize = sizeof(PyOp(AdaptivePooling)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "AdaptivePooling"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_AdaptivePooling_Mode(py_type); + _init_py_AdaptivePooling_Format(py_type); + + PyType_Modified(&py_type); + m.add_object("AdaptivePooling", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AdaptivePooling::typeinfo(), &py_type).second); +} + +PyOpDefBegin(AddAxis) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(AddAxis) + +int PyOp(AddAxis)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "scope", NULL}; + PyObject *axis = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &axis, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(AddAxis)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(AddAxis, axis), py_set_generic(AddAxis, axis), const_cast("axis"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(AddAxis)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(AddAxis)::getstate, METH_NOARGS, "AddAxis getstate"}, + {const_cast("__setstate__"), PyOp(AddAxis)::setstate, METH_VARARGS, "AddAxis setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_AddAxis(py::module m) { + using py_op = PyOp(AddAxis); + auto& py_type = PyOpType(AddAxis); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.AddAxis"; + py_type.tp_basicsize = sizeof(PyOp(AddAxis)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "AddAxis"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("AddAxis", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AddAxis::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Argmax) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Argmax) + +int PyOp(Argmax)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "scope", NULL}; + PyObject *axis = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &axis, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Argmax)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(Argmax, axis), py_set_generic(Argmax, axis), const_cast("axis"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Argmax)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Argmax)::getstate, METH_NOARGS, "Argmax getstate"}, + {const_cast("__setstate__"), PyOp(Argmax)::setstate, METH_VARARGS, "Argmax setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Argmax(py::module m) { + using py_op = PyOp(Argmax); + auto& py_type = PyOpType(Argmax); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Argmax"; + py_type.tp_basicsize = sizeof(PyOp(Argmax)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Argmax"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Argmax", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argmax::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Argmin) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Argmin) + +int PyOp(Argmin)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "scope", NULL}; + PyObject *axis = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &axis, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Argmin)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(Argmin, axis), py_set_generic(Argmin, axis), const_cast("axis"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Argmin)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Argmin)::getstate, METH_NOARGS, "Argmin getstate"}, + {const_cast("__setstate__"), PyOp(Argmin)::setstate, METH_VARARGS, "Argmin setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Argmin(py::module m) { + using py_op = PyOp(Argmin); + auto& py_type = PyOpType(Argmin); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Argmin"; + py_type.tp_basicsize = sizeof(PyOp(Argmin)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Argmin"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Argmin", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argmin::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Argsort.Order"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"ASCENDING", "DESCENDING"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("ASCENDING"), Argsort::Order::ASCENDING}, {normalize_enum("DESCENDING"), Argsort::Order::DESCENDING}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_Argsort_Order(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Argsort.Order", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Order").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Argsort.Order").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Argsort::Order::ASCENDING; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASCENDING", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Argsort::Order::DESCENDING; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DESCENDING", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Order", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Argsort) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"order", serialization::dump(opdef.order)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("order"); + if (iter != state.end()) { + opdef.order = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Argsort) + +int PyOp(Argsort)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"order", "scope", NULL}; + PyObject *order = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &order, &scope)) + return -1; + + if (order) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().order = + py::cast(py::handle(order)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Argsort)::py_getsetters[] = { + {const_cast("order"), py_get_generic(Argsort, order), py_set_generic(Argsort, order), const_cast("order"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Argsort)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Argsort)::getstate, METH_NOARGS, "Argsort getstate"}, + {const_cast("__setstate__"), PyOp(Argsort)::setstate, METH_VARARGS, "Argsort setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Argsort(py::module m) { + using py_op = PyOp(Argsort); + auto& py_type = PyOpType(Argsort); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Argsort"; + py_type.tp_basicsize = sizeof(PyOp(Argsort)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Argsort"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Argsort_Order(py_type); + + PyType_Modified(&py_type); + m.add_object("Argsort", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Argsort::typeinfo(), &py_type).second); +} + +PyOpDefBegin(AssertEqual) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"maxerr", serialization::dump(opdef.maxerr)}, + {"verbose", serialization::dump(opdef.verbose)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("maxerr"); + if (iter != state.end()) { + opdef.maxerr = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("verbose"); + if (iter != state.end()) { + opdef.verbose = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(AssertEqual) + +int PyOp(AssertEqual)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"maxerr", "verbose", "scope", NULL}; + PyObject *maxerr = NULL, *verbose = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &maxerr, &verbose, &scope)) + return -1; + + if (maxerr) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().maxerr = + py::cast(py::handle(maxerr)); + } CATCH_ALL(-1) + } + + if (verbose) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().verbose = + py::cast(py::handle(verbose)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(AssertEqual)::py_getsetters[] = { + {const_cast("maxerr"), py_get_generic(AssertEqual, maxerr), py_set_generic(AssertEqual, maxerr), const_cast("maxerr"), NULL}, + {const_cast("verbose"), py_get_generic(AssertEqual, verbose), py_set_generic(AssertEqual, verbose), const_cast("verbose"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(AssertEqual)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(AssertEqual)::getstate, METH_NOARGS, "AssertEqual getstate"}, + {const_cast("__setstate__"), PyOp(AssertEqual)::setstate, METH_VARARGS, "AssertEqual setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_AssertEqual(py::module m) { + using py_op = PyOp(AssertEqual); + auto& py_type = PyOpType(AssertEqual); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.AssertEqual"; + py_type.tp_basicsize = sizeof(PyOp(AssertEqual)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "AssertEqual"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("AssertEqual", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AssertEqual::typeinfo(), &py_type).second); +} + +PyOpDefBegin(AtlasRuntime) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"buf", serialization::dump(opdef.buf)}, + {"buf_size", serialization::dump(opdef.buf_size)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("buf"); + if (iter != state.end()) { + opdef.buf = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("buf_size"); + if (iter != state.end()) { + opdef.buf_size = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(AtlasRuntime) + +int PyOp(AtlasRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"buf", "buf_size", "scope", NULL}; + PyObject *buf = NULL, *buf_size = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &buf, &buf_size, &scope)) + return -1; + + if (buf) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf = + py::cast(py::handle(buf)); + } CATCH_ALL(-1) + } + + if (buf_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf_size = + py::cast(py::handle(buf_size)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(AtlasRuntime)::py_getsetters[] = { + {const_cast("buf"), py_get_generic(AtlasRuntime, buf), py_set_generic(AtlasRuntime, buf), const_cast("buf"), NULL}, + {const_cast("buf_size"), py_get_generic(AtlasRuntime, buf_size), py_set_generic(AtlasRuntime, buf_size), const_cast("buf_size"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(AtlasRuntime)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(AtlasRuntime)::getstate, METH_NOARGS, "AtlasRuntime getstate"}, + {const_cast("__setstate__"), PyOp(AtlasRuntime)::setstate, METH_VARARGS, "AtlasRuntime setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_AtlasRuntime(py::module m) { + using py_op = PyOp(AtlasRuntime); + auto& py_type = PyOpType(AtlasRuntime); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.AtlasRuntime"; + py_type.tp_basicsize = sizeof(PyOp(AtlasRuntime)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "AtlasRuntime"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("AtlasRuntime", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(AtlasRuntime::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Barrier) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"comp_node", serialization::dump(opdef.comp_node)}, + {"nr_outputs", serialization::dump(opdef.nr_outputs)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("comp_node"); + if (iter != state.end()) { + opdef.comp_node = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("nr_outputs"); + if (iter != state.end()) { + opdef.nr_outputs = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Barrier) + +int PyOp(Barrier)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"comp_node", "nr_outputs", "scope", NULL}; + PyObject *comp_node = NULL, *nr_outputs = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &comp_node, &nr_outputs, &scope)) + return -1; + + if (comp_node) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().comp_node = + py::cast(py::handle(comp_node)); + } CATCH_ALL(-1) + } + + if (nr_outputs) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().nr_outputs = + py::cast(py::handle(nr_outputs)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Barrier)::py_getsetters[] = { + {const_cast("comp_node"), py_get_generic(Barrier, comp_node), py_set_generic(Barrier, comp_node), const_cast("comp_node"), NULL}, + {const_cast("nr_outputs"), py_get_generic(Barrier, nr_outputs), py_set_generic(Barrier, nr_outputs), const_cast("nr_outputs"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Barrier)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Barrier)::getstate, METH_NOARGS, "Barrier getstate"}, + {const_cast("__setstate__"), PyOp(Barrier)::setstate, METH_VARARGS, "Barrier setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Barrier(py::module m) { + using py_op = PyOp(Barrier); + auto& py_type = PyOpType(Barrier); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Barrier"; + py_type.tp_basicsize = sizeof(PyOp(Barrier)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Barrier"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Barrier", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Barrier::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchConvBias.NonlineMode"; + static constexpr std::underlying_type_t max = 4 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"IDENTITY", "RELU", "SIGMOID", "H_SWISH"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("IDENTITY"), BatchConvBias::NonlineMode::IDENTITY}, {normalize_enum("RELU"), BatchConvBias::NonlineMode::RELU}, {normalize_enum("SIGMOID"), BatchConvBias::NonlineMode::SIGMOID}, {normalize_enum("H_SWISH"), BatchConvBias::NonlineMode::H_SWISH}}; +template<> PyObject* EnumWrapper::pyobj_insts[4] = {nullptr}; + +void _init_py_BatchConvBias_NonlineMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchConvBias.NonlineMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("NonlineMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchConvBias.NonlineMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::NonlineMode::IDENTITY; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "IDENTITY", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::NonlineMode::RELU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::NonlineMode::SIGMOID; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::NonlineMode::H_SWISH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "NonlineMode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchConvBias.Mode"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"CROSS_CORRELATION", "CONVOLUTION"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("CROSS_CORRELATION"), BatchConvBias::Mode::CROSS_CORRELATION}, {normalize_enum("CONVOLUTION"), BatchConvBias::Mode::CONVOLUTION}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_BatchConvBias_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchConvBias.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchConvBias.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Mode::CROSS_CORRELATION; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CROSS_CORRELATION", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Mode::CONVOLUTION; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONVOLUTION", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchConvBias.Sparse"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"DENSE", "GROUP"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("DENSE"), BatchConvBias::Sparse::DENSE}, {normalize_enum("GROUP"), BatchConvBias::Sparse::GROUP}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_BatchConvBias_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchConvBias.Sparse", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Sparse").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchConvBias.Sparse").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Sparse::DENSE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DENSE", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Sparse::GROUP; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GROUP", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_BatchConvBias_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchConvBias.ComputeMode"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"DEFAULT", "FLOAT32"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("DEFAULT"), BatchConvBias::ComputeMode::DEFAULT}, {normalize_enum("FLOAT32"), BatchConvBias::ComputeMode::FLOAT32}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_BatchConvBias_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchConvBias.ComputeMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("ComputeMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchConvBias.ComputeMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::ComputeMode::DEFAULT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::ComputeMode::FLOAT32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT32", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchConvBias.Strategy"; + static constexpr std::underlying_type_t max = (1llu << 4) - 1; +}; +template<> PyTypeObject* BitCombinedEnumWrapper::type = nullptr; + +template<> const char* +BitCombinedEnumWrapper::members[] = {"HEURISTIC", "PROFILE", "REPRODUCIBLE", "OPTIMIZED"}; + +template<> std::unordered_map +BitCombinedEnumWrapper::mem2value = {{normalize_enum("HEURISTIC"), BatchConvBias::Strategy::HEURISTIC}, {normalize_enum("PROFILE"), BatchConvBias::Strategy::PROFILE}, {normalize_enum("REPRODUCIBLE"), BatchConvBias::Strategy::REPRODUCIBLE}, {normalize_enum("OPTIMIZED"), BatchConvBias::Strategy::OPTIMIZED}}; +template<> PyObject* BitCombinedEnumWrapper::pyobj_insts[4] = {nullptr}; + +void _init_py_BatchConvBias_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)BitCombinedEnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)BitCombinedEnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)BitCombinedEnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {Py_tp_new, (void*)BitCombinedEnumWrapper::py_new_combined_enum}, + {Py_nb_or, (void*)BitCombinedEnumWrapper::py_or}, + {Py_nb_and, (void*)BitCombinedEnumWrapper::py_and}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchConvBias.Strategy", + // basicsize + sizeof(BitCombinedEnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Strategy").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchConvBias.Strategy").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Strategy::HEURISTIC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "HEURISTIC", inst) >= 0); + BitCombinedEnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Strategy::PROFILE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PROFILE", inst) >= 0); + BitCombinedEnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Strategy::REPRODUCIBLE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPRODUCIBLE", inst) >= 0); + BitCombinedEnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchConvBias::Strategy::OPTIMIZED; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "OPTIMIZED", inst) >= 0); + BitCombinedEnumWrapper::pyobj_insts[3] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(BatchConvBias) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"nonlineMode", serialization::dump(opdef.nonlineMode)}, + {"mode", serialization::dump(opdef.mode)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"format", serialization::dump(opdef.format)}, + {"compute_mode", serialization::dump(opdef.compute_mode)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)}, + {"dtype", serialization::dump(opdef.dtype)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("nonlineMode"); + if (iter != state.end()) { + opdef.nonlineMode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BatchConvBias) + +int PyOp(BatchConvBias)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"nonlineMode", "mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL}; + PyObject *nonlineMode = NULL, *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOO", const_cast(kwlist), &nonlineMode, &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &dtype, &scope)) + return -1; + + if (nonlineMode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().nonlineMode = + py::cast(py::handle(nonlineMode)); + } CATCH_ALL(-1) + } + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BatchConvBias)::py_getsetters[] = { + {const_cast("nonlineMode"), py_get_generic(BatchConvBias, nonlineMode), py_set_generic(BatchConvBias, nonlineMode), const_cast("nonlineMode"), NULL}, + {const_cast("mode"), py_get_generic(BatchConvBias, mode), py_set_generic(BatchConvBias, mode), const_cast("mode"), NULL}, + {const_cast("pad_h"), py_get_generic(BatchConvBias, pad_h), py_set_generic(BatchConvBias, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(BatchConvBias, pad_w), py_set_generic(BatchConvBias, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(BatchConvBias, stride_h), py_set_generic(BatchConvBias, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(BatchConvBias, stride_w), py_set_generic(BatchConvBias, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(BatchConvBias, dilate_h), py_set_generic(BatchConvBias, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(BatchConvBias, dilate_w), py_set_generic(BatchConvBias, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("sparse"), py_get_generic(BatchConvBias, sparse), py_set_generic(BatchConvBias, sparse), const_cast("sparse"), NULL}, + {const_cast("format"), py_get_generic(BatchConvBias, format), py_set_generic(BatchConvBias, format), const_cast("format"), NULL}, + {const_cast("compute_mode"), py_get_generic(BatchConvBias, compute_mode), py_set_generic(BatchConvBias, compute_mode), const_cast("compute_mode"), NULL}, + {const_cast("strategy"), py_get_generic(BatchConvBias, strategy), py_set_generic(BatchConvBias, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(BatchConvBias, workspace_limit), py_set_generic(BatchConvBias, workspace_limit), const_cast("workspace_limit"), NULL}, + {const_cast("dtype"), py_get_generic(BatchConvBias, dtype), py_set_generic(BatchConvBias, dtype), const_cast("dtype"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BatchConvBias)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BatchConvBias)::getstate, METH_NOARGS, "BatchConvBias getstate"}, + {const_cast("__setstate__"), PyOp(BatchConvBias)::setstate, METH_VARARGS, "BatchConvBias setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BatchConvBias(py::module m) { + using py_op = PyOp(BatchConvBias); + auto& py_type = PyOpType(BatchConvBias); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BatchConvBias"; + py_type.tp_basicsize = sizeof(PyOp(BatchConvBias)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BatchConvBias"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_BatchConvBias_NonlineMode(py_type); + _init_py_BatchConvBias_Mode(py_type); + _init_py_BatchConvBias_Sparse(py_type); + _init_py_BatchConvBias_Format(py_type); + _init_py_BatchConvBias_ComputeMode(py_type); + _init_py_BatchConvBias_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("BatchConvBias", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchConvBias::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchNorm.ParamDim"; + static constexpr std::underlying_type_t max = 4 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"DIM_11HW", "DIM_1CHW", "DIM_1C11", "DIM_111C"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("DIM_11HW"), BatchNorm::ParamDim::DIM_11HW}, {normalize_enum("DIM_1CHW"), BatchNorm::ParamDim::DIM_1CHW}, {normalize_enum("DIM_1C11"), BatchNorm::ParamDim::DIM_1C11}, {normalize_enum("DIM_111C"), BatchNorm::ParamDim::DIM_111C}}; +template<> PyObject* EnumWrapper::pyobj_insts[4] = {nullptr}; + +void _init_py_BatchNorm_ParamDim(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchNorm.ParamDim", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("ParamDim").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchNorm.ParamDim").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchNorm::ParamDim::DIM_11HW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_11HW", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchNorm::ParamDim::DIM_1CHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_1CHW", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchNorm::ParamDim::DIM_1C11; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_1C11", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchNorm::ParamDim::DIM_111C; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DIM_111C", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ParamDim", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchNorm.FwdMode"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"TRAINING", "INFERENCE"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("TRAINING"), BatchNorm::FwdMode::TRAINING}, {normalize_enum("INFERENCE"), BatchNorm::FwdMode::INFERENCE}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_BatchNorm_FwdMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchNorm.FwdMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("FwdMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchNorm.FwdMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchNorm::FwdMode::TRAINING; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRAINING", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchNorm::FwdMode::INFERENCE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "INFERENCE", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "FwdMode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(BatchNorm) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"param_dim", serialization::dump(opdef.param_dim)}, + {"fwd_mode", serialization::dump(opdef.fwd_mode)}, + {"epsilon", serialization::dump(opdef.epsilon)}, + {"avg_factor", serialization::dump(opdef.avg_factor)}, + {"scale", serialization::dump(opdef.scale)}, + {"bias", serialization::dump(opdef.bias)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("param_dim"); + if (iter != state.end()) { + opdef.param_dim = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("fwd_mode"); + if (iter != state.end()) { + opdef.fwd_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("epsilon"); + if (iter != state.end()) { + opdef.epsilon = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("avg_factor"); + if (iter != state.end()) { + opdef.avg_factor = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("scale"); + if (iter != state.end()) { + opdef.scale = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bias"); + if (iter != state.end()) { + opdef.bias = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BatchNorm) + +int PyOp(BatchNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"param_dim", "fwd_mode", "epsilon", "avg_factor", "scale", "bias", "scope", NULL}; + PyObject *param_dim = NULL, *fwd_mode = NULL, *epsilon = NULL, *avg_factor = NULL, *scale = NULL, *bias = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOO", const_cast(kwlist), ¶m_dim, &fwd_mode, &epsilon, &avg_factor, &scale, &bias, &scope)) + return -1; + + if (param_dim) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().param_dim = + py::cast(py::handle(param_dim)); + } CATCH_ALL(-1) + } + + if (fwd_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().fwd_mode = + py::cast(py::handle(fwd_mode)); + } CATCH_ALL(-1) + } + + if (epsilon) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().epsilon = + py::cast(py::handle(epsilon)); + } CATCH_ALL(-1) + } + + if (avg_factor) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().avg_factor = + py::cast(py::handle(avg_factor)); + } CATCH_ALL(-1) + } + + if (scale) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().scale = + py::cast(py::handle(scale)); + } CATCH_ALL(-1) + } + + if (bias) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bias = + py::cast(py::handle(bias)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BatchNorm)::py_getsetters[] = { + {const_cast("param_dim"), py_get_generic(BatchNorm, param_dim), py_set_generic(BatchNorm, param_dim), const_cast("param_dim"), NULL}, + {const_cast("fwd_mode"), py_get_generic(BatchNorm, fwd_mode), py_set_generic(BatchNorm, fwd_mode), const_cast("fwd_mode"), NULL}, + {const_cast("epsilon"), py_get_generic(BatchNorm, epsilon), py_set_generic(BatchNorm, epsilon), const_cast("epsilon"), NULL}, + {const_cast("avg_factor"), py_get_generic(BatchNorm, avg_factor), py_set_generic(BatchNorm, avg_factor), const_cast("avg_factor"), NULL}, + {const_cast("scale"), py_get_generic(BatchNorm, scale), py_set_generic(BatchNorm, scale), const_cast("scale"), NULL}, + {const_cast("bias"), py_get_generic(BatchNorm, bias), py_set_generic(BatchNorm, bias), const_cast("bias"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BatchNorm)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BatchNorm)::getstate, METH_NOARGS, "BatchNorm getstate"}, + {const_cast("__setstate__"), PyOp(BatchNorm)::setstate, METH_VARARGS, "BatchNorm setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BatchNorm(py::module m) { + using py_op = PyOp(BatchNorm); + auto& py_type = PyOpType(BatchNorm); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BatchNorm"; + py_type.tp_basicsize = sizeof(PyOp(BatchNorm)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BatchNorm"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_BatchNorm_ParamDim(py_type); + _init_py_BatchNorm_FwdMode(py_type); + + PyType_Modified(&py_type); + m.add_object("BatchNorm", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchNorm::typeinfo(), &py_type).second); +} + +void _init_py_BatchNormBackward_ParamDim(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ParamDim", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_BatchNormBackward_FwdMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "FwdMode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(BatchNormBackward) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"param_dim", serialization::dump(opdef.param_dim)}, + {"fwd_mode", serialization::dump(opdef.fwd_mode)}, + {"epsilon", serialization::dump(opdef.epsilon)}, + {"avg_factor", serialization::dump(opdef.avg_factor)}, + {"scale", serialization::dump(opdef.scale)}, + {"bias", serialization::dump(opdef.bias)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("param_dim"); + if (iter != state.end()) { + opdef.param_dim = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("fwd_mode"); + if (iter != state.end()) { + opdef.fwd_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("epsilon"); + if (iter != state.end()) { + opdef.epsilon = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("avg_factor"); + if (iter != state.end()) { + opdef.avg_factor = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("scale"); + if (iter != state.end()) { + opdef.scale = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bias"); + if (iter != state.end()) { + opdef.bias = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BatchNormBackward) + +int PyOp(BatchNormBackward)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"param_dim", "fwd_mode", "epsilon", "avg_factor", "scale", "bias", "scope", NULL}; + PyObject *param_dim = NULL, *fwd_mode = NULL, *epsilon = NULL, *avg_factor = NULL, *scale = NULL, *bias = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOO", const_cast(kwlist), ¶m_dim, &fwd_mode, &epsilon, &avg_factor, &scale, &bias, &scope)) + return -1; + + if (param_dim) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().param_dim = + py::cast(py::handle(param_dim)); + } CATCH_ALL(-1) + } + + if (fwd_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().fwd_mode = + py::cast(py::handle(fwd_mode)); + } CATCH_ALL(-1) + } + + if (epsilon) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().epsilon = + py::cast(py::handle(epsilon)); + } CATCH_ALL(-1) + } + + if (avg_factor) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().avg_factor = + py::cast(py::handle(avg_factor)); + } CATCH_ALL(-1) + } + + if (scale) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().scale = + py::cast(py::handle(scale)); + } CATCH_ALL(-1) + } + + if (bias) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bias = + py::cast(py::handle(bias)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BatchNormBackward)::py_getsetters[] = { + {const_cast("param_dim"), py_get_generic(BatchNormBackward, param_dim), py_set_generic(BatchNormBackward, param_dim), const_cast("param_dim"), NULL}, + {const_cast("fwd_mode"), py_get_generic(BatchNormBackward, fwd_mode), py_set_generic(BatchNormBackward, fwd_mode), const_cast("fwd_mode"), NULL}, + {const_cast("epsilon"), py_get_generic(BatchNormBackward, epsilon), py_set_generic(BatchNormBackward, epsilon), const_cast("epsilon"), NULL}, + {const_cast("avg_factor"), py_get_generic(BatchNormBackward, avg_factor), py_set_generic(BatchNormBackward, avg_factor), const_cast("avg_factor"), NULL}, + {const_cast("scale"), py_get_generic(BatchNormBackward, scale), py_set_generic(BatchNormBackward, scale), const_cast("scale"), NULL}, + {const_cast("bias"), py_get_generic(BatchNormBackward, bias), py_set_generic(BatchNormBackward, bias), const_cast("bias"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BatchNormBackward)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BatchNormBackward)::getstate, METH_NOARGS, "BatchNormBackward getstate"}, + {const_cast("__setstate__"), PyOp(BatchNormBackward)::setstate, METH_VARARGS, "BatchNormBackward setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BatchNormBackward(py::module m) { + using py_op = PyOp(BatchNormBackward); + auto& py_type = PyOpType(BatchNormBackward); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BatchNormBackward"; + py_type.tp_basicsize = sizeof(PyOp(BatchNormBackward)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BatchNormBackward"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_BatchNormBackward_ParamDim(py_type); + _init_py_BatchNormBackward_FwdMode(py_type); + + PyType_Modified(&py_type); + m.add_object("BatchNormBackward", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchNormBackward::typeinfo(), &py_type).second); +} + +PyOpDefBegin(BatchedIncrMeshIndexing) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BatchedIncrMeshIndexing) + +int PyOp(BatchedIncrMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BatchedIncrMeshIndexing)::py_getsetters[] = { + {const_cast("items"), py_get_generic(BatchedIncrMeshIndexing, items), py_set_generic(BatchedIncrMeshIndexing, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BatchedIncrMeshIndexing)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BatchedIncrMeshIndexing)::getstate, METH_NOARGS, "BatchedIncrMeshIndexing getstate"}, + {const_cast("__setstate__"), PyOp(BatchedIncrMeshIndexing)::setstate, METH_VARARGS, "BatchedIncrMeshIndexing setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BatchedIncrMeshIndexing(py::module m) { + using py_op = PyOp(BatchedIncrMeshIndexing); + auto& py_type = PyOpType(BatchedIncrMeshIndexing); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedIncrMeshIndexing"; + py_type.tp_basicsize = sizeof(PyOp(BatchedIncrMeshIndexing)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BatchedIncrMeshIndexing"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("BatchedIncrMeshIndexing", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedIncrMeshIndexing::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchedMatrixMul.ComputeMode"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"DEFAULT", "FLOAT32"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("DEFAULT"), BatchedMatrixMul::ComputeMode::DEFAULT}, {normalize_enum("FLOAT32"), BatchedMatrixMul::ComputeMode::FLOAT32}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_BatchedMatrixMul_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchedMatrixMul.ComputeMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("ComputeMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchedMatrixMul.ComputeMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchedMatrixMul::ComputeMode::DEFAULT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchedMatrixMul::ComputeMode::FLOAT32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT32", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "BatchedMatrixMul.Format"; + static constexpr std::underlying_type_t max = 5 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"DEFAULT", "MK4", "MK8", "MK4_DOT", "N32K4_DOT"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("DEFAULT"), BatchedMatrixMul::Format::DEFAULT}, {normalize_enum("MK4"), BatchedMatrixMul::Format::MK4}, {normalize_enum("MK8"), BatchedMatrixMul::Format::MK8}, {normalize_enum("MK4_DOT"), BatchedMatrixMul::Format::MK4_DOT}, {normalize_enum("N32K4_DOT"), BatchedMatrixMul::Format::N32K4_DOT}}; +template<> PyObject* EnumWrapper::pyobj_insts[5] = {nullptr}; + +void _init_py_BatchedMatrixMul_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.BatchedMatrixMul.Format", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Format").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("BatchedMatrixMul.Format").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchedMatrixMul::Format::DEFAULT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchedMatrixMul::Format::MK4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK4", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchedMatrixMul::Format::MK8; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK8", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchedMatrixMul::Format::MK4_DOT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MK4_DOT", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = BatchedMatrixMul::Format::N32K4_DOT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "N32K4_DOT", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_BatchedMatrixMul_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(BatchedMatrixMul) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"transposeA", serialization::dump(opdef.transposeA)}, + {"transposeB", serialization::dump(opdef.transposeB)}, + {"compute_mode", serialization::dump(opdef.compute_mode)}, + {"format", serialization::dump(opdef.format)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)}, + {"dimA", serialization::dump(opdef.dimA)}, + {"dimB", serialization::dump(opdef.dimB)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("transposeA"); + if (iter != state.end()) { + opdef.transposeA = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("transposeB"); + if (iter != state.end()) { + opdef.transposeB = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dimA"); + if (iter != state.end()) { + opdef.dimA = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dimB"); + if (iter != state.end()) { + opdef.dimB = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BatchedMatrixMul) + +int PyOp(BatchedMatrixMul)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"transposeA", "transposeB", "compute_mode", "format", "strategy", "workspace_limit", "dimA", "dimB", "scope", NULL}; + PyObject *transposeA = NULL, *transposeB = NULL, *compute_mode = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *dimA = NULL, *dimB = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast(kwlist), &transposeA, &transposeB, &compute_mode, &format, &strategy, &workspace_limit, &dimA, &dimB, &scope)) + return -1; + + if (transposeA) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().transposeA = + py::cast(py::handle(transposeA)); + } CATCH_ALL(-1) + } + + if (transposeB) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().transposeB = + py::cast(py::handle(transposeB)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (dimA) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dimA = + py::cast(py::handle(dimA)); + } CATCH_ALL(-1) + } + + if (dimB) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dimB = + py::cast(py::handle(dimB)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BatchedMatrixMul)::py_getsetters[] = { + {const_cast("transposeA"), py_get_generic(BatchedMatrixMul, transposeA), py_set_generic(BatchedMatrixMul, transposeA), const_cast("transposeA"), NULL}, + {const_cast("transposeB"), py_get_generic(BatchedMatrixMul, transposeB), py_set_generic(BatchedMatrixMul, transposeB), const_cast("transposeB"), NULL}, + {const_cast("compute_mode"), py_get_generic(BatchedMatrixMul, compute_mode), py_set_generic(BatchedMatrixMul, compute_mode), const_cast("compute_mode"), NULL}, + {const_cast("format"), py_get_generic(BatchedMatrixMul, format), py_set_generic(BatchedMatrixMul, format), const_cast("format"), NULL}, + {const_cast("strategy"), py_get_generic(BatchedMatrixMul, strategy), py_set_generic(BatchedMatrixMul, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(BatchedMatrixMul, workspace_limit), py_set_generic(BatchedMatrixMul, workspace_limit), const_cast("workspace_limit"), NULL}, + {const_cast("dimA"), py_get_generic(BatchedMatrixMul, dimA), py_set_generic(BatchedMatrixMul, dimA), const_cast("dimA"), NULL}, + {const_cast("dimB"), py_get_generic(BatchedMatrixMul, dimB), py_set_generic(BatchedMatrixMul, dimB), const_cast("dimB"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BatchedMatrixMul)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BatchedMatrixMul)::getstate, METH_NOARGS, "BatchedMatrixMul getstate"}, + {const_cast("__setstate__"), PyOp(BatchedMatrixMul)::setstate, METH_VARARGS, "BatchedMatrixMul setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BatchedMatrixMul(py::module m) { + using py_op = PyOp(BatchedMatrixMul); + auto& py_type = PyOpType(BatchedMatrixMul); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedMatrixMul"; + py_type.tp_basicsize = sizeof(PyOp(BatchedMatrixMul)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BatchedMatrixMul"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_BatchedMatrixMul_ComputeMode(py_type); + _init_py_BatchedMatrixMul_Format(py_type); + _init_py_BatchedMatrixMul_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("BatchedMatrixMul", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedMatrixMul::typeinfo(), &py_type).second); +} + +PyOpDefBegin(BatchedMeshIndexing) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BatchedMeshIndexing) + +int PyOp(BatchedMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BatchedMeshIndexing)::py_getsetters[] = { + {const_cast("items"), py_get_generic(BatchedMeshIndexing, items), py_set_generic(BatchedMeshIndexing, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BatchedMeshIndexing)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BatchedMeshIndexing)::getstate, METH_NOARGS, "BatchedMeshIndexing getstate"}, + {const_cast("__setstate__"), PyOp(BatchedMeshIndexing)::setstate, METH_VARARGS, "BatchedMeshIndexing setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BatchedMeshIndexing(py::module m) { + using py_op = PyOp(BatchedMeshIndexing); + auto& py_type = PyOpType(BatchedMeshIndexing); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedMeshIndexing"; + py_type.tp_basicsize = sizeof(PyOp(BatchedMeshIndexing)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BatchedMeshIndexing"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("BatchedMeshIndexing", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedMeshIndexing::typeinfo(), &py_type).second); +} + +PyOpDefBegin(BatchedSetMeshIndexing) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BatchedSetMeshIndexing) + +int PyOp(BatchedSetMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BatchedSetMeshIndexing)::py_getsetters[] = { + {const_cast("items"), py_get_generic(BatchedSetMeshIndexing, items), py_set_generic(BatchedSetMeshIndexing, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BatchedSetMeshIndexing)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BatchedSetMeshIndexing)::getstate, METH_NOARGS, "BatchedSetMeshIndexing getstate"}, + {const_cast("__setstate__"), PyOp(BatchedSetMeshIndexing)::setstate, METH_VARARGS, "BatchedSetMeshIndexing setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BatchedSetMeshIndexing(py::module m) { + using py_op = PyOp(BatchedSetMeshIndexing); + auto& py_type = PyOpType(BatchedSetMeshIndexing); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BatchedSetMeshIndexing"; + py_type.tp_basicsize = sizeof(PyOp(BatchedSetMeshIndexing)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BatchedSetMeshIndexing"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("BatchedSetMeshIndexing", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BatchedSetMeshIndexing::typeinfo(), &py_type).second); +} + +PyOpDefBegin(BetaRNG) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"seed", serialization::dump(opdef.seed)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(BetaRNG) + +int PyOp(BetaRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"seed", "handle", "scope", NULL}; + PyObject *seed = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &seed, &handle, &scope)) + return -1; + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(BetaRNG)::py_getsetters[] = { + {const_cast("seed"), py_get_generic(BetaRNG, seed), py_set_generic(BetaRNG, seed), const_cast("seed"), NULL}, + {const_cast("handle"), py_get_generic(BetaRNG, handle), py_set_generic(BetaRNG, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(BetaRNG)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(BetaRNG)::getstate, METH_NOARGS, "BetaRNG getstate"}, + {const_cast("__setstate__"), PyOp(BetaRNG)::setstate, METH_VARARGS, "BetaRNG setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_BetaRNG(py::module m) { + using py_op = PyOp(BetaRNG); + auto& py_type = PyOpType(BetaRNG); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.BetaRNG"; + py_type.tp_basicsize = sizeof(PyOp(BetaRNG)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "BetaRNG"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("BetaRNG", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(BetaRNG::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Borrow) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"comp_node", serialization::dump(opdef.comp_node)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("comp_node"); + if (iter != state.end()) { + opdef.comp_node = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Borrow) + +int PyOp(Borrow)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"comp_node", "scope", NULL}; + PyObject *comp_node = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &comp_node, &scope)) + return -1; + + if (comp_node) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().comp_node = + py::cast(py::handle(comp_node)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Borrow)::py_getsetters[] = { + {const_cast("comp_node"), py_get_generic(Borrow, comp_node), py_set_generic(Borrow, comp_node), const_cast("comp_node"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Borrow)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Borrow)::getstate, METH_NOARGS, "Borrow getstate"}, + {const_cast("__setstate__"), PyOp(Borrow)::setstate, METH_VARARGS, "Borrow setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Borrow(py::module m) { + using py_op = PyOp(Borrow); + auto& py_type = PyOpType(Borrow); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Borrow"; + py_type.tp_basicsize = sizeof(PyOp(Borrow)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Borrow"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Borrow", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Borrow::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Broadcast) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"shape", serialization::dump(opdef.shape)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("shape"); + if (iter != state.end()) { + opdef.shape = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Broadcast) + +int PyOp(Broadcast)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"shape", "scope", NULL}; + PyObject *shape = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &shape, &scope)) + return -1; + + if (shape) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().shape = + py::cast(py::handle(shape)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Broadcast)::py_getsetters[] = { + {const_cast("shape"), py_get_generic(Broadcast, shape), py_set_generic(Broadcast, shape), const_cast("shape"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Broadcast)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Broadcast)::getstate, METH_NOARGS, "Broadcast getstate"}, + {const_cast("__setstate__"), PyOp(Broadcast)::setstate, METH_VARARGS, "Broadcast setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Broadcast(py::module m) { + using py_op = PyOp(Broadcast); + auto& py_type = PyOpType(Broadcast); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Broadcast"; + py_type.tp_basicsize = sizeof(PyOp(Broadcast)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Broadcast"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Broadcast", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Broadcast::typeinfo(), &py_type).second); +} + +PyOpDefBegin(CambriconRuntime) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"buf", serialization::dump(opdef.buf)}, + {"buf_size", serialization::dump(opdef.buf_size)}, + {"symbol", serialization::dump(opdef.symbol)}, + {"tensor_dim_mutable", serialization::dump(opdef.tensor_dim_mutable)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("buf"); + if (iter != state.end()) { + opdef.buf = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("buf_size"); + if (iter != state.end()) { + opdef.buf_size = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("symbol"); + if (iter != state.end()) { + opdef.symbol = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("tensor_dim_mutable"); + if (iter != state.end()) { + opdef.tensor_dim_mutable = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(CambriconRuntime) + +int PyOp(CambriconRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"buf", "buf_size", "symbol", "tensor_dim_mutable", "scope", NULL}; + PyObject *buf = NULL, *buf_size = NULL, *symbol = NULL, *tensor_dim_mutable = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast(kwlist), &buf, &buf_size, &symbol, &tensor_dim_mutable, &scope)) + return -1; + + if (buf) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf = + py::cast(py::handle(buf)); + } CATCH_ALL(-1) + } + + if (buf_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf_size = + py::cast(py::handle(buf_size)); + } CATCH_ALL(-1) + } + + if (symbol) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().symbol = + py::cast(py::handle(symbol)); + } CATCH_ALL(-1) + } + + if (tensor_dim_mutable) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().tensor_dim_mutable = + py::cast(py::handle(tensor_dim_mutable)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(CambriconRuntime)::py_getsetters[] = { + {const_cast("buf"), py_get_generic(CambriconRuntime, buf), py_set_generic(CambriconRuntime, buf), const_cast("buf"), NULL}, + {const_cast("buf_size"), py_get_generic(CambriconRuntime, buf_size), py_set_generic(CambriconRuntime, buf_size), const_cast("buf_size"), NULL}, + {const_cast("symbol"), py_get_generic(CambriconRuntime, symbol), py_set_generic(CambriconRuntime, symbol), const_cast("symbol"), NULL}, + {const_cast("tensor_dim_mutable"), py_get_generic(CambriconRuntime, tensor_dim_mutable), py_set_generic(CambriconRuntime, tensor_dim_mutable), const_cast("tensor_dim_mutable"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(CambriconRuntime)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(CambriconRuntime)::getstate, METH_NOARGS, "CambriconRuntime getstate"}, + {const_cast("__setstate__"), PyOp(CambriconRuntime)::setstate, METH_VARARGS, "CambriconRuntime setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_CambriconRuntime(py::module m) { + using py_op = PyOp(CambriconRuntime); + auto& py_type = PyOpType(CambriconRuntime); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.CambriconRuntime"; + py_type.tp_basicsize = sizeof(PyOp(CambriconRuntime)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "CambriconRuntime"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("CambriconRuntime", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CambriconRuntime::typeinfo(), &py_type).second); +} + +PyOpDefBegin(CheckNonFinite) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"scale", serialization::dump(opdef.scale)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("scale"); + if (iter != state.end()) { + opdef.scale = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(CheckNonFinite) + +int PyOp(CheckNonFinite)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"scale", "scope", NULL}; + PyObject *scale = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &scale, &scope)) + return -1; + + if (scale) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().scale = + py::cast(py::handle(scale)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(CheckNonFinite)::py_getsetters[] = { + {const_cast("scale"), py_get_generic(CheckNonFinite, scale), py_set_generic(CheckNonFinite, scale), const_cast("scale"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(CheckNonFinite)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(CheckNonFinite)::getstate, METH_NOARGS, "CheckNonFinite getstate"}, + {const_cast("__setstate__"), PyOp(CheckNonFinite)::setstate, METH_VARARGS, "CheckNonFinite setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_CheckNonFinite(py::module m) { + using py_op = PyOp(CheckNonFinite); + auto& py_type = PyOpType(CheckNonFinite); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.CheckNonFinite"; + py_type.tp_basicsize = sizeof(PyOp(CheckNonFinite)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "CheckNonFinite"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("CheckNonFinite", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CheckNonFinite::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "CollectiveComm.Mode"; + static constexpr std::underlying_type_t max = 11 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"REDUCE_SUM", "BROADCAST", "ALL_GATHER", "REDUCE_SCATTER_SUM", "ALL_REDUCE_SUM", "ALL_REDUCE_MAX", "ALL_REDUCE_MIN", "ALL_REDUCE_PROD", "GATHER", "SCATTER", "ALL_TO_ALL"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("REDUCE_SUM"), CollectiveComm::Mode::REDUCE_SUM}, {normalize_enum("BROADCAST"), CollectiveComm::Mode::BROADCAST}, {normalize_enum("ALL_GATHER"), CollectiveComm::Mode::ALL_GATHER}, {normalize_enum("REDUCE_SCATTER_SUM"), CollectiveComm::Mode::REDUCE_SCATTER_SUM}, {normalize_enum("ALL_REDUCE_SUM"), CollectiveComm::Mode::ALL_REDUCE_SUM}, {normalize_enum("ALL_REDUCE_MAX"), CollectiveComm::Mode::ALL_REDUCE_MAX}, {normalize_enum("ALL_REDUCE_MIN"), CollectiveComm::Mode::ALL_REDUCE_MIN}, {normalize_enum("ALL_REDUCE_PROD"), CollectiveComm::Mode::ALL_REDUCE_PROD}, {normalize_enum("GATHER"), CollectiveComm::Mode::GATHER}, {normalize_enum("SCATTER"), CollectiveComm::Mode::SCATTER}, {normalize_enum("ALL_TO_ALL"), CollectiveComm::Mode::ALL_TO_ALL}}; +template<> PyObject* EnumWrapper::pyobj_insts[11] = {nullptr}; + +void _init_py_CollectiveComm_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.CollectiveComm.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("CollectiveComm.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::REDUCE_SUM; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REDUCE_SUM", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::BROADCAST; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BROADCAST", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::ALL_GATHER; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_GATHER", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::REDUCE_SCATTER_SUM; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REDUCE_SCATTER_SUM", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_SUM; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_SUM", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_MAX; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_MAX", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_MIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_MIN", inst) >= 0); + EnumWrapper::pyobj_insts[6] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::ALL_REDUCE_PROD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_REDUCE_PROD", inst) >= 0); + EnumWrapper::pyobj_insts[7] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::GATHER; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GATHER", inst) >= 0); + EnumWrapper::pyobj_insts[8] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::SCATTER; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SCATTER", inst) >= 0); + EnumWrapper::pyobj_insts[9] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CollectiveComm::Mode::ALL_TO_ALL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ALL_TO_ALL", inst) >= 0); + EnumWrapper::pyobj_insts[10] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(CollectiveComm) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"key", serialization::dump(opdef.key)}, + {"nr_devices", serialization::dump(opdef.nr_devices)}, + {"rank", serialization::dump(opdef.rank)}, + {"is_root", serialization::dump(opdef.is_root)}, + {"local_grad", serialization::dump(opdef.local_grad)}, + {"addr", serialization::dump(opdef.addr)}, + {"port", serialization::dump(opdef.port)}, + {"dtype", serialization::dump(opdef.dtype)}, + {"backend", serialization::dump(opdef.backend)}, + {"comp_node", serialization::dump(opdef.comp_node)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("key"); + if (iter != state.end()) { + opdef.key = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("nr_devices"); + if (iter != state.end()) { + opdef.nr_devices = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("rank"); + if (iter != state.end()) { + opdef.rank = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("is_root"); + if (iter != state.end()) { + opdef.is_root = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("local_grad"); + if (iter != state.end()) { + opdef.local_grad = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("addr"); + if (iter != state.end()) { + opdef.addr = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("port"); + if (iter != state.end()) { + opdef.port = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("backend"); + if (iter != state.end()) { + opdef.backend = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("comp_node"); + if (iter != state.end()) { + opdef.comp_node = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(CollectiveComm) + +int PyOp(CollectiveComm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "key", "nr_devices", "rank", "is_root", "local_grad", "addr", "port", "dtype", "backend", "comp_node", "scope", NULL}; + PyObject *mode = NULL, *key = NULL, *nr_devices = NULL, *rank = NULL, *is_root = NULL, *local_grad = NULL, *addr = NULL, *port = NULL, *dtype = NULL, *backend = NULL, *comp_node = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOO", const_cast(kwlist), &mode, &key, &nr_devices, &rank, &is_root, &local_grad, &addr, &port, &dtype, &backend, &comp_node, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (key) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().key = + py::cast(py::handle(key)); + } CATCH_ALL(-1) + } + + if (nr_devices) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().nr_devices = + py::cast(py::handle(nr_devices)); + } CATCH_ALL(-1) + } + + if (rank) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().rank = + py::cast(py::handle(rank)); + } CATCH_ALL(-1) + } + + if (is_root) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().is_root = + py::cast(py::handle(is_root)); + } CATCH_ALL(-1) + } + + if (local_grad) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().local_grad = + py::cast(py::handle(local_grad)); + } CATCH_ALL(-1) + } + + if (addr) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().addr = + py::cast(py::handle(addr)); + } CATCH_ALL(-1) + } + + if (port) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().port = + py::cast(py::handle(port)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (backend) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().backend = + py::cast(py::handle(backend)); + } CATCH_ALL(-1) + } + + if (comp_node) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().comp_node = + py::cast(py::handle(comp_node)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(CollectiveComm)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(CollectiveComm, mode), py_set_generic(CollectiveComm, mode), const_cast("mode"), NULL}, + {const_cast("key"), py_get_generic(CollectiveComm, key), py_set_generic(CollectiveComm, key), const_cast("key"), NULL}, + {const_cast("nr_devices"), py_get_generic(CollectiveComm, nr_devices), py_set_generic(CollectiveComm, nr_devices), const_cast("nr_devices"), NULL}, + {const_cast("rank"), py_get_generic(CollectiveComm, rank), py_set_generic(CollectiveComm, rank), const_cast("rank"), NULL}, + {const_cast("is_root"), py_get_generic(CollectiveComm, is_root), py_set_generic(CollectiveComm, is_root), const_cast("is_root"), NULL}, + {const_cast("local_grad"), py_get_generic(CollectiveComm, local_grad), py_set_generic(CollectiveComm, local_grad), const_cast("local_grad"), NULL}, + {const_cast("addr"), py_get_generic(CollectiveComm, addr), py_set_generic(CollectiveComm, addr), const_cast("addr"), NULL}, + {const_cast("port"), py_get_generic(CollectiveComm, port), py_set_generic(CollectiveComm, port), const_cast("port"), NULL}, + {const_cast("dtype"), py_get_generic(CollectiveComm, dtype), py_set_generic(CollectiveComm, dtype), const_cast("dtype"), NULL}, + {const_cast("backend"), py_get_generic(CollectiveComm, backend), py_set_generic(CollectiveComm, backend), const_cast("backend"), NULL}, + {const_cast("comp_node"), py_get_generic(CollectiveComm, comp_node), py_set_generic(CollectiveComm, comp_node), const_cast("comp_node"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(CollectiveComm)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(CollectiveComm)::getstate, METH_NOARGS, "CollectiveComm getstate"}, + {const_cast("__setstate__"), PyOp(CollectiveComm)::setstate, METH_VARARGS, "CollectiveComm setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_CollectiveComm(py::module m) { + using py_op = PyOp(CollectiveComm); + auto& py_type = PyOpType(CollectiveComm); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.CollectiveComm"; + py_type.tp_basicsize = sizeof(PyOp(CollectiveComm)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "CollectiveComm"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_CollectiveComm_Mode(py_type); + + PyType_Modified(&py_type); + m.add_object("CollectiveComm", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CollectiveComm::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Concat) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)}, + {"comp_node", serialization::dump(opdef.comp_node)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("comp_node"); + if (iter != state.end()) { + opdef.comp_node = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Concat) + +int PyOp(Concat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "comp_node", "scope", NULL}; + PyObject *axis = NULL, *comp_node = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &axis, &comp_node, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (comp_node) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().comp_node = + py::cast(py::handle(comp_node)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Concat)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(Concat, axis), py_set_generic(Concat, axis), const_cast("axis"), NULL}, + {const_cast("comp_node"), py_get_generic(Concat, comp_node), py_set_generic(Concat, comp_node), const_cast("comp_node"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Concat)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Concat)::getstate, METH_NOARGS, "Concat getstate"}, + {const_cast("__setstate__"), PyOp(Concat)::setstate, METH_VARARGS, "Concat setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Concat(py::module m) { + using py_op = PyOp(Concat); + auto& py_type = PyOpType(Concat); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Concat"; + py_type.tp_basicsize = sizeof(PyOp(Concat)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Concat"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Concat", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Concat::typeinfo(), &py_type).second); +} + +PyOpDefBegin(CondTake) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(CondTake) + +int PyOp(CondTake)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + + return 0; +} + +PyGetSetDef PyOp(CondTake)::py_getsetters[] = { + + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(CondTake)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(CondTake)::getstate, METH_NOARGS, "CondTake getstate"}, + {const_cast("__setstate__"), PyOp(CondTake)::setstate, METH_VARARGS, "CondTake setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_CondTake(py::module m) { + using py_op = PyOp(CondTake); + auto& py_type = PyOpType(CondTake); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.CondTake"; + py_type.tp_basicsize = sizeof(PyOp(CondTake)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "CondTake"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("CondTake", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CondTake::typeinfo(), &py_type).second); +} + +void _init_py_ConvBias_NonlineMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "NonlineMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvBias_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvBias_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvBias_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvBias_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvBias_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(ConvBias) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"nonlineMode", serialization::dump(opdef.nonlineMode)}, + {"mode", serialization::dump(opdef.mode)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"format", serialization::dump(opdef.format)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"compute_mode", serialization::dump(opdef.compute_mode)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)}, + {"dtype", serialization::dump(opdef.dtype)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("nonlineMode"); + if (iter != state.end()) { + opdef.nonlineMode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ConvBias) + +int PyOp(ConvBias)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"nonlineMode", "mode", "sparse", "format", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL}; + PyObject *nonlineMode = NULL, *mode = NULL, *sparse = NULL, *format = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOO", const_cast(kwlist), &nonlineMode, &mode, &sparse, &format, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &compute_mode, &strategy, &workspace_limit, &dtype, &scope)) + return -1; + + if (nonlineMode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().nonlineMode = + py::cast(py::handle(nonlineMode)); + } CATCH_ALL(-1) + } + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ConvBias)::py_getsetters[] = { + {const_cast("nonlineMode"), py_get_generic(ConvBias, nonlineMode), py_set_generic(ConvBias, nonlineMode), const_cast("nonlineMode"), NULL}, + {const_cast("mode"), py_get_generic(ConvBias, mode), py_set_generic(ConvBias, mode), const_cast("mode"), NULL}, + {const_cast("sparse"), py_get_generic(ConvBias, sparse), py_set_generic(ConvBias, sparse), const_cast("sparse"), NULL}, + {const_cast("format"), py_get_generic(ConvBias, format), py_set_generic(ConvBias, format), const_cast("format"), NULL}, + {const_cast("pad_h"), py_get_generic(ConvBias, pad_h), py_set_generic(ConvBias, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(ConvBias, pad_w), py_set_generic(ConvBias, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(ConvBias, stride_h), py_set_generic(ConvBias, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(ConvBias, stride_w), py_set_generic(ConvBias, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(ConvBias, dilate_h), py_set_generic(ConvBias, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(ConvBias, dilate_w), py_set_generic(ConvBias, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("compute_mode"), py_get_generic(ConvBias, compute_mode), py_set_generic(ConvBias, compute_mode), const_cast("compute_mode"), NULL}, + {const_cast("strategy"), py_get_generic(ConvBias, strategy), py_set_generic(ConvBias, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(ConvBias, workspace_limit), py_set_generic(ConvBias, workspace_limit), const_cast("workspace_limit"), NULL}, + {const_cast("dtype"), py_get_generic(ConvBias, dtype), py_set_generic(ConvBias, dtype), const_cast("dtype"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ConvBias)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ConvBias)::getstate, METH_NOARGS, "ConvBias getstate"}, + {const_cast("__setstate__"), PyOp(ConvBias)::setstate, METH_VARARGS, "ConvBias setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ConvBias(py::module m) { + using py_op = PyOp(ConvBias); + auto& py_type = PyOpType(ConvBias); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ConvBias"; + py_type.tp_basicsize = sizeof(PyOp(ConvBias)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ConvBias"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_ConvBias_NonlineMode(py_type); + _init_py_ConvBias_Mode(py_type); + _init_py_ConvBias_Sparse(py_type); + _init_py_ConvBias_Format(py_type); + _init_py_ConvBias_ComputeMode(py_type); + _init_py_ConvBias_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("ConvBias", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ConvBias::typeinfo(), &py_type).second); +} + +void _init_py_Convolution_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Convolution) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"format", serialization::dump(opdef.format)}, + {"compute_mode", serialization::dump(opdef.compute_mode)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Convolution) + +int PyOp(Convolution)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "scope", NULL}; + PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOO", const_cast(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Convolution)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(Convolution, mode), py_set_generic(Convolution, mode), const_cast("mode"), NULL}, + {const_cast("pad_h"), py_get_generic(Convolution, pad_h), py_set_generic(Convolution, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(Convolution, pad_w), py_set_generic(Convolution, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(Convolution, stride_h), py_set_generic(Convolution, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(Convolution, stride_w), py_set_generic(Convolution, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(Convolution, dilate_h), py_set_generic(Convolution, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(Convolution, dilate_w), py_set_generic(Convolution, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("sparse"), py_get_generic(Convolution, sparse), py_set_generic(Convolution, sparse), const_cast("sparse"), NULL}, + {const_cast("format"), py_get_generic(Convolution, format), py_set_generic(Convolution, format), const_cast("format"), NULL}, + {const_cast("compute_mode"), py_get_generic(Convolution, compute_mode), py_set_generic(Convolution, compute_mode), const_cast("compute_mode"), NULL}, + {const_cast("strategy"), py_get_generic(Convolution, strategy), py_set_generic(Convolution, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(Convolution, workspace_limit), py_set_generic(Convolution, workspace_limit), const_cast("workspace_limit"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Convolution)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Convolution)::getstate, METH_NOARGS, "Convolution getstate"}, + {const_cast("__setstate__"), PyOp(Convolution)::setstate, METH_VARARGS, "Convolution setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Convolution(py::module m) { + using py_op = PyOp(Convolution); + auto& py_type = PyOpType(Convolution); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution"; + py_type.tp_basicsize = sizeof(PyOp(Convolution)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Convolution"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Convolution_Mode(py_type); + _init_py_Convolution_Sparse(py_type); + _init_py_Convolution_Format(py_type); + _init_py_Convolution_ComputeMode(py_type); + _init_py_Convolution_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("Convolution", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Convolution3D.Mode"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"CROSS_CORRELATION", "CONVOLUTION"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("CROSS_CORRELATION"), Convolution3D::Mode::CROSS_CORRELATION}, {normalize_enum("CONVOLUTION"), Convolution3D::Mode::CONVOLUTION}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_Convolution3D_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Convolution3D.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Convolution3D.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::Mode::CROSS_CORRELATION; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CROSS_CORRELATION", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::Mode::CONVOLUTION; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONVOLUTION", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Convolution3D.Sparse"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"DENSE", "GROUP"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("DENSE"), Convolution3D::Sparse::DENSE}, {normalize_enum("GROUP"), Convolution3D::Sparse::GROUP}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_Convolution3D_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Convolution3D.Sparse", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Sparse").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Convolution3D.Sparse").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::Sparse::DENSE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DENSE", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::Sparse::GROUP; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GROUP", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Convolution3D.DataType"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"FLOAT", "FLOAT_IO16xC32"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("FLOAT"), Convolution3D::DataType::FLOAT}, {normalize_enum("FLOAT_IO16xC32"), Convolution3D::DataType::FLOAT_IO16xC32}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_Convolution3D_DataType(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Convolution3D.DataType", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("DataType").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Convolution3D.DataType").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::DataType::FLOAT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::DataType::FLOAT_IO16xC32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_IO16xC32", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "DataType", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Convolution3D.Format"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"NCDHW", "NDHWC"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("NCDHW"), Convolution3D::Format::NCDHW}, {normalize_enum("NDHWC"), Convolution3D::Format::NDHWC}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_Convolution3D_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Convolution3D.Format", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Format").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Convolution3D.Format").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::Format::NCDHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCDHW", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Convolution3D::Format::NDHWC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NDHWC", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution3D_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Convolution3D) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"pad_d", serialization::dump(opdef.pad_d)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_d", serialization::dump(opdef.stride_d)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_d", serialization::dump(opdef.dilate_d)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"data_type", serialization::dump(opdef.data_type)}, + {"format", serialization::dump(opdef.format)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_d"); + if (iter != state.end()) { + opdef.pad_d = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_d"); + if (iter != state.end()) { + opdef.stride_d = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_d"); + if (iter != state.end()) { + opdef.dilate_d = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("data_type"); + if (iter != state.end()) { + opdef.data_type = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Convolution3D) + +int PyOp(Convolution3D)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "pad_d", "pad_h", "pad_w", "stride_d", "stride_h", "stride_w", "dilate_d", "dilate_h", "dilate_w", "sparse", "data_type", "format", "strategy", "workspace_limit", "scope", NULL}; + PyObject *mode = NULL, *pad_d = NULL, *pad_h = NULL, *pad_w = NULL, *stride_d = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_d = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *data_type = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOO", const_cast(kwlist), &mode, &pad_d, &pad_h, &pad_w, &stride_d, &stride_h, &stride_w, &dilate_d, &dilate_h, &dilate_w, &sparse, &data_type, &format, &strategy, &workspace_limit, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_d) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_d = + py::cast(py::handle(pad_d)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_d) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_d = + py::cast(py::handle(stride_d)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_d) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_d = + py::cast(py::handle(dilate_d)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (data_type) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().data_type = + py::cast(py::handle(data_type)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Convolution3D)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(Convolution3D, mode), py_set_generic(Convolution3D, mode), const_cast("mode"), NULL}, + {const_cast("pad_d"), py_get_generic(Convolution3D, pad_d), py_set_generic(Convolution3D, pad_d), const_cast("pad_d"), NULL}, + {const_cast("pad_h"), py_get_generic(Convolution3D, pad_h), py_set_generic(Convolution3D, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(Convolution3D, pad_w), py_set_generic(Convolution3D, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_d"), py_get_generic(Convolution3D, stride_d), py_set_generic(Convolution3D, stride_d), const_cast("stride_d"), NULL}, + {const_cast("stride_h"), py_get_generic(Convolution3D, stride_h), py_set_generic(Convolution3D, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(Convolution3D, stride_w), py_set_generic(Convolution3D, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_d"), py_get_generic(Convolution3D, dilate_d), py_set_generic(Convolution3D, dilate_d), const_cast("dilate_d"), NULL}, + {const_cast("dilate_h"), py_get_generic(Convolution3D, dilate_h), py_set_generic(Convolution3D, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(Convolution3D, dilate_w), py_set_generic(Convolution3D, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("sparse"), py_get_generic(Convolution3D, sparse), py_set_generic(Convolution3D, sparse), const_cast("sparse"), NULL}, + {const_cast("data_type"), py_get_generic(Convolution3D, data_type), py_set_generic(Convolution3D, data_type), const_cast("data_type"), NULL}, + {const_cast("format"), py_get_generic(Convolution3D, format), py_set_generic(Convolution3D, format), const_cast("format"), NULL}, + {const_cast("strategy"), py_get_generic(Convolution3D, strategy), py_set_generic(Convolution3D, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(Convolution3D, workspace_limit), py_set_generic(Convolution3D, workspace_limit), const_cast("workspace_limit"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Convolution3D)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Convolution3D)::getstate, METH_NOARGS, "Convolution3D getstate"}, + {const_cast("__setstate__"), PyOp(Convolution3D)::setstate, METH_VARARGS, "Convolution3D setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Convolution3D(py::module m) { + using py_op = PyOp(Convolution3D); + auto& py_type = PyOpType(Convolution3D); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution3D"; + py_type.tp_basicsize = sizeof(PyOp(Convolution3D)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Convolution3D"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Convolution3D_Mode(py_type); + _init_py_Convolution3D_Sparse(py_type); + _init_py_Convolution3D_DataType(py_type); + _init_py_Convolution3D_Format(py_type); + _init_py_Convolution3D_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("Convolution3D", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution3D::typeinfo(), &py_type).second); +} + +void _init_py_Convolution3DBackwardData_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution3DBackwardData_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution3DBackwardData_DataType(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "DataType", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution3DBackwardData_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Convolution3DBackwardData_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Convolution3DBackwardData) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"pad_d", serialization::dump(opdef.pad_d)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_d", serialization::dump(opdef.stride_d)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_d", serialization::dump(opdef.dilate_d)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"data_type", serialization::dump(opdef.data_type)}, + {"format", serialization::dump(opdef.format)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_d"); + if (iter != state.end()) { + opdef.pad_d = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_d"); + if (iter != state.end()) { + opdef.stride_d = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_d"); + if (iter != state.end()) { + opdef.dilate_d = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("data_type"); + if (iter != state.end()) { + opdef.data_type = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Convolution3DBackwardData) + +int PyOp(Convolution3DBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "pad_d", "pad_h", "pad_w", "stride_d", "stride_h", "stride_w", "dilate_d", "dilate_h", "dilate_w", "sparse", "data_type", "format", "strategy", "workspace_limit", "scope", NULL}; + PyObject *mode = NULL, *pad_d = NULL, *pad_h = NULL, *pad_w = NULL, *stride_d = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_d = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *data_type = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOO", const_cast(kwlist), &mode, &pad_d, &pad_h, &pad_w, &stride_d, &stride_h, &stride_w, &dilate_d, &dilate_h, &dilate_w, &sparse, &data_type, &format, &strategy, &workspace_limit, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_d) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_d = + py::cast(py::handle(pad_d)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_d) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_d = + py::cast(py::handle(stride_d)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_d) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_d = + py::cast(py::handle(dilate_d)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (data_type) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().data_type = + py::cast(py::handle(data_type)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Convolution3DBackwardData)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(Convolution3DBackwardData, mode), py_set_generic(Convolution3DBackwardData, mode), const_cast("mode"), NULL}, + {const_cast("pad_d"), py_get_generic(Convolution3DBackwardData, pad_d), py_set_generic(Convolution3DBackwardData, pad_d), const_cast("pad_d"), NULL}, + {const_cast("pad_h"), py_get_generic(Convolution3DBackwardData, pad_h), py_set_generic(Convolution3DBackwardData, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(Convolution3DBackwardData, pad_w), py_set_generic(Convolution3DBackwardData, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_d"), py_get_generic(Convolution3DBackwardData, stride_d), py_set_generic(Convolution3DBackwardData, stride_d), const_cast("stride_d"), NULL}, + {const_cast("stride_h"), py_get_generic(Convolution3DBackwardData, stride_h), py_set_generic(Convolution3DBackwardData, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(Convolution3DBackwardData, stride_w), py_set_generic(Convolution3DBackwardData, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_d"), py_get_generic(Convolution3DBackwardData, dilate_d), py_set_generic(Convolution3DBackwardData, dilate_d), const_cast("dilate_d"), NULL}, + {const_cast("dilate_h"), py_get_generic(Convolution3DBackwardData, dilate_h), py_set_generic(Convolution3DBackwardData, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(Convolution3DBackwardData, dilate_w), py_set_generic(Convolution3DBackwardData, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("sparse"), py_get_generic(Convolution3DBackwardData, sparse), py_set_generic(Convolution3DBackwardData, sparse), const_cast("sparse"), NULL}, + {const_cast("data_type"), py_get_generic(Convolution3DBackwardData, data_type), py_set_generic(Convolution3DBackwardData, data_type), const_cast("data_type"), NULL}, + {const_cast("format"), py_get_generic(Convolution3DBackwardData, format), py_set_generic(Convolution3DBackwardData, format), const_cast("format"), NULL}, + {const_cast("strategy"), py_get_generic(Convolution3DBackwardData, strategy), py_set_generic(Convolution3DBackwardData, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(Convolution3DBackwardData, workspace_limit), py_set_generic(Convolution3DBackwardData, workspace_limit), const_cast("workspace_limit"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Convolution3DBackwardData)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Convolution3DBackwardData)::getstate, METH_NOARGS, "Convolution3DBackwardData getstate"}, + {const_cast("__setstate__"), PyOp(Convolution3DBackwardData)::setstate, METH_VARARGS, "Convolution3DBackwardData setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Convolution3DBackwardData(py::module m) { + using py_op = PyOp(Convolution3DBackwardData); + auto& py_type = PyOpType(Convolution3DBackwardData); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Convolution3DBackwardData"; + py_type.tp_basicsize = sizeof(PyOp(Convolution3DBackwardData)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Convolution3DBackwardData"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Convolution3DBackwardData_Mode(py_type); + _init_py_Convolution3DBackwardData_Sparse(py_type); + _init_py_Convolution3DBackwardData_DataType(py_type); + _init_py_Convolution3DBackwardData_Format(py_type); + _init_py_Convolution3DBackwardData_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("Convolution3DBackwardData", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Convolution3DBackwardData::typeinfo(), &py_type).second); +} + +void _init_py_ConvolutionBackwardData_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvolutionBackwardData_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvolutionBackwardData_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvolutionBackwardData_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ConvolutionBackwardData_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(ConvolutionBackwardData) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"format", serialization::dump(opdef.format)}, + {"compute_mode", serialization::dump(opdef.compute_mode)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)}, + {"dtype", serialization::dump(opdef.dtype)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ConvolutionBackwardData) + +int PyOp(ConvolutionBackwardData)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "dtype", "scope", NULL}; + PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *dtype = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOO", const_cast(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &dtype, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ConvolutionBackwardData)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(ConvolutionBackwardData, mode), py_set_generic(ConvolutionBackwardData, mode), const_cast("mode"), NULL}, + {const_cast("pad_h"), py_get_generic(ConvolutionBackwardData, pad_h), py_set_generic(ConvolutionBackwardData, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(ConvolutionBackwardData, pad_w), py_set_generic(ConvolutionBackwardData, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(ConvolutionBackwardData, stride_h), py_set_generic(ConvolutionBackwardData, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(ConvolutionBackwardData, stride_w), py_set_generic(ConvolutionBackwardData, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(ConvolutionBackwardData, dilate_h), py_set_generic(ConvolutionBackwardData, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(ConvolutionBackwardData, dilate_w), py_set_generic(ConvolutionBackwardData, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("sparse"), py_get_generic(ConvolutionBackwardData, sparse), py_set_generic(ConvolutionBackwardData, sparse), const_cast("sparse"), NULL}, + {const_cast("format"), py_get_generic(ConvolutionBackwardData, format), py_set_generic(ConvolutionBackwardData, format), const_cast("format"), NULL}, + {const_cast("compute_mode"), py_get_generic(ConvolutionBackwardData, compute_mode), py_set_generic(ConvolutionBackwardData, compute_mode), const_cast("compute_mode"), NULL}, + {const_cast("strategy"), py_get_generic(ConvolutionBackwardData, strategy), py_set_generic(ConvolutionBackwardData, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(ConvolutionBackwardData, workspace_limit), py_set_generic(ConvolutionBackwardData, workspace_limit), const_cast("workspace_limit"), NULL}, + {const_cast("dtype"), py_get_generic(ConvolutionBackwardData, dtype), py_set_generic(ConvolutionBackwardData, dtype), const_cast("dtype"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ConvolutionBackwardData)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ConvolutionBackwardData)::getstate, METH_NOARGS, "ConvolutionBackwardData getstate"}, + {const_cast("__setstate__"), PyOp(ConvolutionBackwardData)::setstate, METH_VARARGS, "ConvolutionBackwardData setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ConvolutionBackwardData(py::module m) { + using py_op = PyOp(ConvolutionBackwardData); + auto& py_type = PyOpType(ConvolutionBackwardData); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ConvolutionBackwardData"; + py_type.tp_basicsize = sizeof(PyOp(ConvolutionBackwardData)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ConvolutionBackwardData"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_ConvolutionBackwardData_Mode(py_type); + _init_py_ConvolutionBackwardData_Sparse(py_type); + _init_py_ConvolutionBackwardData_Format(py_type); + _init_py_ConvolutionBackwardData_ComputeMode(py_type); + _init_py_ConvolutionBackwardData_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("ConvolutionBackwardData", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ConvolutionBackwardData::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Copy) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"comp_node", serialization::dump(opdef.comp_node)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("comp_node"); + if (iter != state.end()) { + opdef.comp_node = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Copy) + +int PyOp(Copy)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"comp_node", "scope", NULL}; + PyObject *comp_node = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &comp_node, &scope)) + return -1; + + if (comp_node) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().comp_node = + py::cast(py::handle(comp_node)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Copy)::py_getsetters[] = { + {const_cast("comp_node"), py_get_generic(Copy, comp_node), py_set_generic(Copy, comp_node), const_cast("comp_node"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Copy)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Copy)::getstate, METH_NOARGS, "Copy getstate"}, + {const_cast("__setstate__"), PyOp(Copy)::setstate, METH_VARARGS, "Copy setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Copy(py::module m) { + using py_op = PyOp(Copy); + auto& py_type = PyOpType(Copy); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Copy"; + py_type.tp_basicsize = sizeof(PyOp(Copy)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Copy"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Copy", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Copy::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Correlation.Format"; + static constexpr std::underlying_type_t max = 20 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"NCHW", "NHWC", "NHWCD4", "NCHW4", "NCHW8", "NCHW32", "NCHW88", "NCHW44", "NCHW44_DOT", "NCHW_WINOGRAD", "NCHW88_WINOGRAD", "NCHW44_WINOGRAD", "NCHW4_NCHW32", "NCHW32_NCHW4", "NCHW4_NCHW", "NHWC_NCHW", "NHWC_NCHW4_IC_SMALL", "NCHW_NCHW4_IC_SMALL", "CHWN4", "NCHW4_NHWC"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("NCHW"), Correlation::Format::NCHW}, {normalize_enum("NHWC"), Correlation::Format::NHWC}, {normalize_enum("NHWCD4"), Correlation::Format::NHWCD4}, {normalize_enum("NCHW4"), Correlation::Format::NCHW4}, {normalize_enum("NCHW8"), Correlation::Format::NCHW8}, {normalize_enum("NCHW32"), Correlation::Format::NCHW32}, {normalize_enum("NCHW88"), Correlation::Format::NCHW88}, {normalize_enum("NCHW44"), Correlation::Format::NCHW44}, {normalize_enum("NCHW44_DOT"), Correlation::Format::NCHW44_DOT}, {normalize_enum("NCHW_WINOGRAD"), Correlation::Format::NCHW_WINOGRAD}, {normalize_enum("NCHW88_WINOGRAD"), Correlation::Format::NCHW88_WINOGRAD}, {normalize_enum("NCHW44_WINOGRAD"), Correlation::Format::NCHW44_WINOGRAD}, {normalize_enum("NCHW4_NCHW32"), Correlation::Format::NCHW4_NCHW32}, {normalize_enum("NCHW32_NCHW4"), Correlation::Format::NCHW32_NCHW4}, {normalize_enum("NCHW4_NCHW"), Correlation::Format::NCHW4_NCHW}, {normalize_enum("NHWC_NCHW"), Correlation::Format::NHWC_NCHW}, {normalize_enum("NHWC_NCHW4_IC_SMALL"), Correlation::Format::NHWC_NCHW4_IC_SMALL}, {normalize_enum("NCHW_NCHW4_IC_SMALL"), Correlation::Format::NCHW_NCHW4_IC_SMALL}, {normalize_enum("CHWN4"), Correlation::Format::CHWN4}, {normalize_enum("NCHW4_NHWC"), Correlation::Format::NCHW4_NHWC}}; +template<> PyObject* EnumWrapper::pyobj_insts[20] = {nullptr}; + +void _init_py_Correlation_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Correlation.Format", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Format").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Correlation.Format").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NHWC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NHWCD4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWCD4", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW8; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW8", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW88; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88", inst) >= 0); + EnumWrapper::pyobj_insts[6] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW44; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44", inst) >= 0); + EnumWrapper::pyobj_insts[7] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW44_DOT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_DOT", inst) >= 0); + EnumWrapper::pyobj_insts[8] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW_WINOGRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_WINOGRAD", inst) >= 0); + EnumWrapper::pyobj_insts[9] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW88_WINOGRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW88_WINOGRAD", inst) >= 0); + EnumWrapper::pyobj_insts[10] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW44_WINOGRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW44_WINOGRAD", inst) >= 0); + EnumWrapper::pyobj_insts[11] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW4_NCHW32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW32", inst) >= 0); + EnumWrapper::pyobj_insts[12] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW32_NCHW4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW32_NCHW4", inst) >= 0); + EnumWrapper::pyobj_insts[13] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW4_NCHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NCHW", inst) >= 0); + EnumWrapper::pyobj_insts[14] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NHWC_NCHW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW", inst) >= 0); + EnumWrapper::pyobj_insts[15] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NHWC_NCHW4_IC_SMALL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NHWC_NCHW4_IC_SMALL", inst) >= 0); + EnumWrapper::pyobj_insts[16] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW_NCHW4_IC_SMALL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW_NCHW4_IC_SMALL", inst) >= 0); + EnumWrapper::pyobj_insts[17] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::CHWN4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CHWN4", inst) >= 0); + EnumWrapper::pyobj_insts[18] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Correlation::Format::NCHW4_NHWC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NCHW4_NHWC", inst) >= 0); + EnumWrapper::pyobj_insts[19] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Correlation) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"format", serialization::dump(opdef.format)}, + {"kernel_size", serialization::dump(opdef.kernel_size)}, + {"max_displacement", serialization::dump(opdef.max_displacement)}, + {"stride1", serialization::dump(opdef.stride1)}, + {"stride2", serialization::dump(opdef.stride2)}, + {"pad_size", serialization::dump(opdef.pad_size)}, + {"is_multiply", serialization::dump(opdef.is_multiply)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("kernel_size"); + if (iter != state.end()) { + opdef.kernel_size = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("max_displacement"); + if (iter != state.end()) { + opdef.max_displacement = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride1"); + if (iter != state.end()) { + opdef.stride1 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride2"); + if (iter != state.end()) { + opdef.stride2 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_size"); + if (iter != state.end()) { + opdef.pad_size = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("is_multiply"); + if (iter != state.end()) { + opdef.is_multiply = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Correlation) + +int PyOp(Correlation)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"format", "kernel_size", "max_displacement", "stride1", "stride2", "pad_size", "is_multiply", "scope", NULL}; + PyObject *format = NULL, *kernel_size = NULL, *max_displacement = NULL, *stride1 = NULL, *stride2 = NULL, *pad_size = NULL, *is_multiply = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast(kwlist), &format, &kernel_size, &max_displacement, &stride1, &stride2, &pad_size, &is_multiply, &scope)) + return -1; + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (kernel_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().kernel_size = + py::cast(py::handle(kernel_size)); + } CATCH_ALL(-1) + } + + if (max_displacement) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().max_displacement = + py::cast(py::handle(max_displacement)); + } CATCH_ALL(-1) + } + + if (stride1) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride1 = + py::cast(py::handle(stride1)); + } CATCH_ALL(-1) + } + + if (stride2) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride2 = + py::cast(py::handle(stride2)); + } CATCH_ALL(-1) + } + + if (pad_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_size = + py::cast(py::handle(pad_size)); + } CATCH_ALL(-1) + } + + if (is_multiply) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().is_multiply = + py::cast(py::handle(is_multiply)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Correlation)::py_getsetters[] = { + {const_cast("format"), py_get_generic(Correlation, format), py_set_generic(Correlation, format), const_cast("format"), NULL}, + {const_cast("kernel_size"), py_get_generic(Correlation, kernel_size), py_set_generic(Correlation, kernel_size), const_cast("kernel_size"), NULL}, + {const_cast("max_displacement"), py_get_generic(Correlation, max_displacement), py_set_generic(Correlation, max_displacement), const_cast("max_displacement"), NULL}, + {const_cast("stride1"), py_get_generic(Correlation, stride1), py_set_generic(Correlation, stride1), const_cast("stride1"), NULL}, + {const_cast("stride2"), py_get_generic(Correlation, stride2), py_set_generic(Correlation, stride2), const_cast("stride2"), NULL}, + {const_cast("pad_size"), py_get_generic(Correlation, pad_size), py_set_generic(Correlation, pad_size), const_cast("pad_size"), NULL}, + {const_cast("is_multiply"), py_get_generic(Correlation, is_multiply), py_set_generic(Correlation, is_multiply), const_cast("is_multiply"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Correlation)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Correlation)::getstate, METH_NOARGS, "Correlation getstate"}, + {const_cast("__setstate__"), PyOp(Correlation)::setstate, METH_VARARGS, "Correlation setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Correlation(py::module m) { + using py_op = PyOp(Correlation); + auto& py_type = PyOpType(Correlation); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Correlation"; + py_type.tp_basicsize = sizeof(PyOp(Correlation)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Correlation"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Correlation_Format(py_type); + + PyType_Modified(&py_type); + m.add_object("Correlation", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Correlation::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Cumsum) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)}, + {"exclusive", serialization::dump(opdef.exclusive)}, + {"reverse", serialization::dump(opdef.reverse)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("exclusive"); + if (iter != state.end()) { + opdef.exclusive = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("reverse"); + if (iter != state.end()) { + opdef.reverse = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Cumsum) + +int PyOp(Cumsum)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "exclusive", "reverse", "scope", NULL}; + PyObject *axis = NULL, *exclusive = NULL, *reverse = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast(kwlist), &axis, &exclusive, &reverse, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (exclusive) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().exclusive = + py::cast(py::handle(exclusive)); + } CATCH_ALL(-1) + } + + if (reverse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().reverse = + py::cast(py::handle(reverse)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Cumsum)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(Cumsum, axis), py_set_generic(Cumsum, axis), const_cast("axis"), NULL}, + {const_cast("exclusive"), py_get_generic(Cumsum, exclusive), py_set_generic(Cumsum, exclusive), const_cast("exclusive"), NULL}, + {const_cast("reverse"), py_get_generic(Cumsum, reverse), py_set_generic(Cumsum, reverse), const_cast("reverse"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Cumsum)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Cumsum)::getstate, METH_NOARGS, "Cumsum getstate"}, + {const_cast("__setstate__"), PyOp(Cumsum)::setstate, METH_VARARGS, "Cumsum setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Cumsum(py::module m) { + using py_op = PyOp(Cumsum); + auto& py_type = PyOpType(Cumsum); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Cumsum"; + py_type.tp_basicsize = sizeof(PyOp(Cumsum)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Cumsum"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Cumsum", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Cumsum::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "CvtColor.Mode"; + static constexpr std::underlying_type_t max = 32 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"RGB2GRAY", "RGB2YUV", "YUV2RGB", "GRAY2RGB", "RGBA2RGB", "RGBA2BGR", "RGBA2GRAY", "RGB2BGR", "BGR2GRAY", "BGR2RGB", "YUV2GRAY_NV21", "YUV2RGB_NV21", "YUV2BGR_NV21", "YUV2GRAY_NV12", "YUV2RGB_NV12", "YUV2BGR_NV12", "YUV2GRAY_YV12", "YUV2RGB_YV12", "YUV2BGR_YV12", "YUV2GRAY_YU12", "YUV2RGB_YU12", "YUV2BGR_YU12", "YCrCb2RGB", "YCrCb2BGR", "BT601_YUV2RGB_NV21", "BT601_YUV2BGR_NV21", "BT601_YUV2RGB_NV12", "BT601_YUV2BGR_NV12", "BT601_YUV2RGB_YV12", "BT601_YUV2BGR_YV12", "BT601_YUV2RGB_YU12", "BT601_YUV2BGR_YU12"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("RGB2GRAY"), CvtColor::Mode::RGB2GRAY}, {normalize_enum("RGB2YUV"), CvtColor::Mode::RGB2YUV}, {normalize_enum("YUV2RGB"), CvtColor::Mode::YUV2RGB}, {normalize_enum("GRAY2RGB"), CvtColor::Mode::GRAY2RGB}, {normalize_enum("RGBA2RGB"), CvtColor::Mode::RGBA2RGB}, {normalize_enum("RGBA2BGR"), CvtColor::Mode::RGBA2BGR}, {normalize_enum("RGBA2GRAY"), CvtColor::Mode::RGBA2GRAY}, {normalize_enum("RGB2BGR"), CvtColor::Mode::RGB2BGR}, {normalize_enum("BGR2GRAY"), CvtColor::Mode::BGR2GRAY}, {normalize_enum("BGR2RGB"), CvtColor::Mode::BGR2RGB}, {normalize_enum("YUV2GRAY_NV21"), CvtColor::Mode::YUV2GRAY_NV21}, {normalize_enum("YUV2RGB_NV21"), CvtColor::Mode::YUV2RGB_NV21}, {normalize_enum("YUV2BGR_NV21"), CvtColor::Mode::YUV2BGR_NV21}, {normalize_enum("YUV2GRAY_NV12"), CvtColor::Mode::YUV2GRAY_NV12}, {normalize_enum("YUV2RGB_NV12"), CvtColor::Mode::YUV2RGB_NV12}, {normalize_enum("YUV2BGR_NV12"), CvtColor::Mode::YUV2BGR_NV12}, {normalize_enum("YUV2GRAY_YV12"), CvtColor::Mode::YUV2GRAY_YV12}, {normalize_enum("YUV2RGB_YV12"), CvtColor::Mode::YUV2RGB_YV12}, {normalize_enum("YUV2BGR_YV12"), CvtColor::Mode::YUV2BGR_YV12}, {normalize_enum("YUV2GRAY_YU12"), CvtColor::Mode::YUV2GRAY_YU12}, {normalize_enum("YUV2RGB_YU12"), CvtColor::Mode::YUV2RGB_YU12}, {normalize_enum("YUV2BGR_YU12"), CvtColor::Mode::YUV2BGR_YU12}, {normalize_enum("YCrCb2RGB"), CvtColor::Mode::YCrCb2RGB}, {normalize_enum("YCrCb2BGR"), CvtColor::Mode::YCrCb2BGR}, {normalize_enum("BT601_YUV2RGB_NV21"), CvtColor::Mode::BT601_YUV2RGB_NV21}, {normalize_enum("BT601_YUV2BGR_NV21"), CvtColor::Mode::BT601_YUV2BGR_NV21}, {normalize_enum("BT601_YUV2RGB_NV12"), CvtColor::Mode::BT601_YUV2RGB_NV12}, {normalize_enum("BT601_YUV2BGR_NV12"), CvtColor::Mode::BT601_YUV2BGR_NV12}, {normalize_enum("BT601_YUV2RGB_YV12"), CvtColor::Mode::BT601_YUV2RGB_YV12}, {normalize_enum("BT601_YUV2BGR_YV12"), CvtColor::Mode::BT601_YUV2BGR_YV12}, {normalize_enum("BT601_YUV2RGB_YU12"), CvtColor::Mode::BT601_YUV2RGB_YU12}, {normalize_enum("BT601_YUV2BGR_YU12"), CvtColor::Mode::BT601_YUV2BGR_YU12}}; +template<> PyObject* EnumWrapper::pyobj_insts[32] = {nullptr}; + +void _init_py_CvtColor_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.CvtColor.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("CvtColor.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::RGB2GRAY; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2GRAY", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::RGB2YUV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2YUV", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2RGB; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::GRAY2RGB; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GRAY2RGB", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::RGBA2RGB; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2RGB", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::RGBA2BGR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2BGR", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::RGBA2GRAY; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGBA2GRAY", inst) >= 0); + EnumWrapper::pyobj_insts[6] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::RGB2BGR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RGB2BGR", inst) >= 0); + EnumWrapper::pyobj_insts[7] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BGR2GRAY; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2GRAY", inst) >= 0); + EnumWrapper::pyobj_insts[8] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BGR2RGB; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BGR2RGB", inst) >= 0); + EnumWrapper::pyobj_insts[9] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV21; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV21", inst) >= 0); + EnumWrapper::pyobj_insts[10] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2RGB_NV21; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV21", inst) >= 0); + EnumWrapper::pyobj_insts[11] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2BGR_NV21; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV21", inst) >= 0); + EnumWrapper::pyobj_insts[12] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2GRAY_NV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_NV12", inst) >= 0); + EnumWrapper::pyobj_insts[13] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2RGB_NV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_NV12", inst) >= 0); + EnumWrapper::pyobj_insts[14] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2BGR_NV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_NV12", inst) >= 0); + EnumWrapper::pyobj_insts[15] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2GRAY_YV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YV12", inst) >= 0); + EnumWrapper::pyobj_insts[16] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2RGB_YV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YV12", inst) >= 0); + EnumWrapper::pyobj_insts[17] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2BGR_YV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YV12", inst) >= 0); + EnumWrapper::pyobj_insts[18] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2GRAY_YU12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2GRAY_YU12", inst) >= 0); + EnumWrapper::pyobj_insts[19] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2RGB_YU12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2RGB_YU12", inst) >= 0); + EnumWrapper::pyobj_insts[20] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YUV2BGR_YU12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YUV2BGR_YU12", inst) >= 0); + EnumWrapper::pyobj_insts[21] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YCrCb2RGB; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2RGB", inst) >= 0); + EnumWrapper::pyobj_insts[22] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::YCrCb2BGR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "YCrCb2BGR", inst) >= 0); + EnumWrapper::pyobj_insts[23] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV21; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV21", inst) >= 0); + EnumWrapper::pyobj_insts[24] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV21; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV21", inst) >= 0); + EnumWrapper::pyobj_insts[25] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_NV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_NV12", inst) >= 0); + EnumWrapper::pyobj_insts[26] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_NV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_NV12", inst) >= 0); + EnumWrapper::pyobj_insts[27] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YV12", inst) >= 0); + EnumWrapper::pyobj_insts[28] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YV12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YV12", inst) >= 0); + EnumWrapper::pyobj_insts[29] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2RGB_YU12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2RGB_YU12", inst) >= 0); + EnumWrapper::pyobj_insts[30] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = CvtColor::Mode::BT601_YUV2BGR_YU12; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "BT601_YUV2BGR_YU12", inst) >= 0); + EnumWrapper::pyobj_insts[31] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(CvtColor) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(CvtColor) + +int PyOp(CvtColor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "scope", NULL}; + PyObject *mode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &mode, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(CvtColor)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(CvtColor, mode), py_set_generic(CvtColor, mode), const_cast("mode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(CvtColor)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(CvtColor)::getstate, METH_NOARGS, "CvtColor getstate"}, + {const_cast("__setstate__"), PyOp(CvtColor)::setstate, METH_VARARGS, "CvtColor setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_CvtColor(py::module m) { + using py_op = PyOp(CvtColor); + auto& py_type = PyOpType(CvtColor); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.CvtColor"; + py_type.tp_basicsize = sizeof(PyOp(CvtColor)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "CvtColor"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_CvtColor_Mode(py_type); + + PyType_Modified(&py_type); + m.add_object("CvtColor", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(CvtColor::typeinfo(), &py_type).second); +} + +void _init_py_DeformableConv_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_DeformableConv_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_DeformableConv_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_DeformableConv_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_DeformableConv_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(DeformableConv) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"format", serialization::dump(opdef.format)}, + {"compute_mode", serialization::dump(opdef.compute_mode)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(DeformableConv) + +int PyOp(DeformableConv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "strategy", "workspace_limit", "scope", NULL}; + PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOO", const_cast(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &strategy, &workspace_limit, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(DeformableConv)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(DeformableConv, mode), py_set_generic(DeformableConv, mode), const_cast("mode"), NULL}, + {const_cast("pad_h"), py_get_generic(DeformableConv, pad_h), py_set_generic(DeformableConv, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(DeformableConv, pad_w), py_set_generic(DeformableConv, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(DeformableConv, stride_h), py_set_generic(DeformableConv, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(DeformableConv, stride_w), py_set_generic(DeformableConv, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(DeformableConv, dilate_h), py_set_generic(DeformableConv, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(DeformableConv, dilate_w), py_set_generic(DeformableConv, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("sparse"), py_get_generic(DeformableConv, sparse), py_set_generic(DeformableConv, sparse), const_cast("sparse"), NULL}, + {const_cast("format"), py_get_generic(DeformableConv, format), py_set_generic(DeformableConv, format), const_cast("format"), NULL}, + {const_cast("compute_mode"), py_get_generic(DeformableConv, compute_mode), py_set_generic(DeformableConv, compute_mode), const_cast("compute_mode"), NULL}, + {const_cast("strategy"), py_get_generic(DeformableConv, strategy), py_set_generic(DeformableConv, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(DeformableConv, workspace_limit), py_set_generic(DeformableConv, workspace_limit), const_cast("workspace_limit"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(DeformableConv)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(DeformableConv)::getstate, METH_NOARGS, "DeformableConv getstate"}, + {const_cast("__setstate__"), PyOp(DeformableConv)::setstate, METH_VARARGS, "DeformableConv setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_DeformableConv(py::module m) { + using py_op = PyOp(DeformableConv); + auto& py_type = PyOpType(DeformableConv); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.DeformableConv"; + py_type.tp_basicsize = sizeof(PyOp(DeformableConv)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "DeformableConv"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_DeformableConv_Mode(py_type); + _init_py_DeformableConv_Sparse(py_type); + _init_py_DeformableConv_Format(py_type); + _init_py_DeformableConv_ComputeMode(py_type); + _init_py_DeformableConv_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("DeformableConv", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformableConv::typeinfo(), &py_type).second); +} + +PyOpDefBegin(DeformablePSROIPooling) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"no_trans", serialization::dump(opdef.no_trans)}, + {"spatial_scale", serialization::dump(opdef.spatial_scale)}, + {"trans_std", serialization::dump(opdef.trans_std)}, + {"pooled_h", serialization::dump(opdef.pooled_h)}, + {"pooled_w", serialization::dump(opdef.pooled_w)}, + {"part_size", serialization::dump(opdef.part_size)}, + {"sample_per_part", serialization::dump(opdef.sample_per_part)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("no_trans"); + if (iter != state.end()) { + opdef.no_trans = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("spatial_scale"); + if (iter != state.end()) { + opdef.spatial_scale = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("trans_std"); + if (iter != state.end()) { + opdef.trans_std = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pooled_h"); + if (iter != state.end()) { + opdef.pooled_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pooled_w"); + if (iter != state.end()) { + opdef.pooled_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("part_size"); + if (iter != state.end()) { + opdef.part_size = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sample_per_part"); + if (iter != state.end()) { + opdef.sample_per_part = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(DeformablePSROIPooling) + +int PyOp(DeformablePSROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"no_trans", "spatial_scale", "trans_std", "pooled_h", "pooled_w", "part_size", "sample_per_part", "scope", NULL}; + PyObject *no_trans = NULL, *spatial_scale = NULL, *trans_std = NULL, *pooled_h = NULL, *pooled_w = NULL, *part_size = NULL, *sample_per_part = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast(kwlist), &no_trans, &spatial_scale, &trans_std, &pooled_h, &pooled_w, &part_size, &sample_per_part, &scope)) + return -1; + + if (no_trans) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().no_trans = + py::cast(py::handle(no_trans)); + } CATCH_ALL(-1) + } + + if (spatial_scale) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().spatial_scale = + py::cast(py::handle(spatial_scale)); + } CATCH_ALL(-1) + } + + if (trans_std) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().trans_std = + py::cast(py::handle(trans_std)); + } CATCH_ALL(-1) + } + + if (pooled_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pooled_h = + py::cast(py::handle(pooled_h)); + } CATCH_ALL(-1) + } + + if (pooled_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pooled_w = + py::cast(py::handle(pooled_w)); + } CATCH_ALL(-1) + } + + if (part_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().part_size = + py::cast(py::handle(part_size)); + } CATCH_ALL(-1) + } + + if (sample_per_part) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sample_per_part = + py::cast(py::handle(sample_per_part)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(DeformablePSROIPooling)::py_getsetters[] = { + {const_cast("no_trans"), py_get_generic(DeformablePSROIPooling, no_trans), py_set_generic(DeformablePSROIPooling, no_trans), const_cast("no_trans"), NULL}, + {const_cast("spatial_scale"), py_get_generic(DeformablePSROIPooling, spatial_scale), py_set_generic(DeformablePSROIPooling, spatial_scale), const_cast("spatial_scale"), NULL}, + {const_cast("trans_std"), py_get_generic(DeformablePSROIPooling, trans_std), py_set_generic(DeformablePSROIPooling, trans_std), const_cast("trans_std"), NULL}, + {const_cast("pooled_h"), py_get_generic(DeformablePSROIPooling, pooled_h), py_set_generic(DeformablePSROIPooling, pooled_h), const_cast("pooled_h"), NULL}, + {const_cast("pooled_w"), py_get_generic(DeformablePSROIPooling, pooled_w), py_set_generic(DeformablePSROIPooling, pooled_w), const_cast("pooled_w"), NULL}, + {const_cast("part_size"), py_get_generic(DeformablePSROIPooling, part_size), py_set_generic(DeformablePSROIPooling, part_size), const_cast("part_size"), NULL}, + {const_cast("sample_per_part"), py_get_generic(DeformablePSROIPooling, sample_per_part), py_set_generic(DeformablePSROIPooling, sample_per_part), const_cast("sample_per_part"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(DeformablePSROIPooling)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(DeformablePSROIPooling)::getstate, METH_NOARGS, "DeformablePSROIPooling getstate"}, + {const_cast("__setstate__"), PyOp(DeformablePSROIPooling)::setstate, METH_VARARGS, "DeformablePSROIPooling setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_DeformablePSROIPooling(py::module m) { + using py_op = PyOp(DeformablePSROIPooling); + auto& py_type = PyOpType(DeformablePSROIPooling); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.DeformablePSROIPooling"; + py_type.tp_basicsize = sizeof(PyOp(DeformablePSROIPooling)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "DeformablePSROIPooling"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("DeformablePSROIPooling", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(DeformablePSROIPooling::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Diag) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"k", serialization::dump(opdef.k)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("k"); + if (iter != state.end()) { + opdef.k = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Diag) + +int PyOp(Diag)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"k", "scope", NULL}; + PyObject *k = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &k, &scope)) + return -1; + + if (k) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().k = + py::cast(py::handle(k)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Diag)::py_getsetters[] = { + {const_cast("k"), py_get_generic(Diag, k), py_set_generic(Diag, k), const_cast("k"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Diag)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Diag)::getstate, METH_NOARGS, "Diag getstate"}, + {const_cast("__setstate__"), PyOp(Diag)::setstate, METH_VARARGS, "Diag setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Diag(py::module m) { + using py_op = PyOp(Diag); + auto& py_type = PyOpType(Diag); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Diag"; + py_type.tp_basicsize = sizeof(PyOp(Diag)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Diag"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Diag", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Diag::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Dimshuffle) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"pattern", serialization::dump(opdef.pattern)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("pattern"); + if (iter != state.end()) { + opdef.pattern = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Dimshuffle) + +int PyOp(Dimshuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"pattern", "scope", NULL}; + PyObject *pattern = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &pattern, &scope)) + return -1; + + if (pattern) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pattern = + py::cast(py::handle(pattern)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Dimshuffle)::py_getsetters[] = { + {const_cast("pattern"), py_get_generic(Dimshuffle, pattern), py_set_generic(Dimshuffle, pattern), const_cast("pattern"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Dimshuffle)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Dimshuffle)::getstate, METH_NOARGS, "Dimshuffle getstate"}, + {const_cast("__setstate__"), PyOp(Dimshuffle)::setstate, METH_VARARGS, "Dimshuffle setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Dimshuffle(py::module m) { + using py_op = PyOp(Dimshuffle); + auto& py_type = PyOpType(Dimshuffle); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Dimshuffle"; + py_type.tp_basicsize = sizeof(PyOp(Dimshuffle)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Dimshuffle"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Dimshuffle", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dimshuffle::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Dot) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Dot) + +int PyOp(Dot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + + return 0; +} + +PyGetSetDef PyOp(Dot)::py_getsetters[] = { + + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Dot)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Dot)::getstate, METH_NOARGS, "Dot getstate"}, + {const_cast("__setstate__"), PyOp(Dot)::setstate, METH_VARARGS, "Dot setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Dot(py::module m) { + using py_op = PyOp(Dot); + auto& py_type = PyOpType(Dot); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Dot"; + py_type.tp_basicsize = sizeof(PyOp(Dot)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Dot"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Dot", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dot::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Dropout) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"drop_prob", serialization::dump(opdef.drop_prob)}, + {"seed", serialization::dump(opdef.seed)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("drop_prob"); + if (iter != state.end()) { + opdef.drop_prob = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Dropout) + +int PyOp(Dropout)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"drop_prob", "seed", "handle", "scope", NULL}; + PyObject *drop_prob = NULL, *seed = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast(kwlist), &drop_prob, &seed, &handle, &scope)) + return -1; + + if (drop_prob) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().drop_prob = + py::cast(py::handle(drop_prob)); + } CATCH_ALL(-1) + } + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Dropout)::py_getsetters[] = { + {const_cast("drop_prob"), py_get_generic(Dropout, drop_prob), py_set_generic(Dropout, drop_prob), const_cast("drop_prob"), NULL}, + {const_cast("seed"), py_get_generic(Dropout, seed), py_set_generic(Dropout, seed), const_cast("seed"), NULL}, + {const_cast("handle"), py_get_generic(Dropout, handle), py_set_generic(Dropout, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Dropout)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Dropout)::getstate, METH_NOARGS, "Dropout getstate"}, + {const_cast("__setstate__"), PyOp(Dropout)::setstate, METH_VARARGS, "Dropout setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Dropout(py::module m) { + using py_op = PyOp(Dropout); + auto& py_type = PyOpType(Dropout); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Dropout"; + py_type.tp_basicsize = sizeof(PyOp(Dropout)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Dropout"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Dropout", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Dropout::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Elemwise.Mode"; + static constexpr std::underlying_type_t max = 61 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"RELU", "ABS", "ACOS", "ASIN", "CEIL", "COS", "EXP", "EXPM1", "FLOOR", "LOG", "LOG1P", "NEGATE", "SIGMOID", "SIN", "TANH", "ABS_GRAD", "ADD", "FLOOR_DIV", "MAX", "MIN", "MOD", "MUL", "POW", "SIGMOID_GRAD", "SUB", "SWITCH_GT0", "TANH_GRAD", "TRUE_DIV", "LOG_SUM_EXP", "LT", "LEQ", "EQ", "SHL", "SHR", "COND_LEQ_MOV", "FUSE_MUL_ADD3", "FUSE_MUL_ADD4", "FUSE_ADD_RELU", "FUSE_ADD_SIGMOID", "FUSE_ADD_TANH", "FAST_TANH", "FAST_TANH_GRAD", "ROUND", "RMULH", "ATAN2", "ERF", "ERFINV", "ERFC", "ERFCINV", "H_SWISH", "H_SWISH_GRAD", "FUSE_ADD_H_SWISH", "NOT", "AND", "OR", "XOR", "SILU", "SILU_GRAD", "GELU", "GELU_GRAD", "COND_LT_MOV"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("RELU"), Elemwise::Mode::RELU}, {normalize_enum("ABS"), Elemwise::Mode::ABS}, {normalize_enum("ACOS"), Elemwise::Mode::ACOS}, {normalize_enum("ASIN"), Elemwise::Mode::ASIN}, {normalize_enum("CEIL"), Elemwise::Mode::CEIL}, {normalize_enum("COS"), Elemwise::Mode::COS}, {normalize_enum("EXP"), Elemwise::Mode::EXP}, {normalize_enum("EXPM1"), Elemwise::Mode::EXPM1}, {normalize_enum("FLOOR"), Elemwise::Mode::FLOOR}, {normalize_enum("LOG"), Elemwise::Mode::LOG}, {normalize_enum("LOG1P"), Elemwise::Mode::LOG1P}, {normalize_enum("NEGATE"), Elemwise::Mode::NEGATE}, {normalize_enum("SIGMOID"), Elemwise::Mode::SIGMOID}, {normalize_enum("SIN"), Elemwise::Mode::SIN}, {normalize_enum("TANH"), Elemwise::Mode::TANH}, {normalize_enum("ABS_GRAD"), Elemwise::Mode::ABS_GRAD}, {normalize_enum("ADD"), Elemwise::Mode::ADD}, {normalize_enum("FLOOR_DIV"), Elemwise::Mode::FLOOR_DIV}, {normalize_enum("MAX"), Elemwise::Mode::MAX}, {normalize_enum("MIN"), Elemwise::Mode::MIN}, {normalize_enum("MOD"), Elemwise::Mode::MOD}, {normalize_enum("MUL"), Elemwise::Mode::MUL}, {normalize_enum("POW"), Elemwise::Mode::POW}, {normalize_enum("SIGMOID_GRAD"), Elemwise::Mode::SIGMOID_GRAD}, {normalize_enum("SUB"), Elemwise::Mode::SUB}, {normalize_enum("SWITCH_GT0"), Elemwise::Mode::SWITCH_GT0}, {normalize_enum("TANH_GRAD"), Elemwise::Mode::TANH_GRAD}, {normalize_enum("TRUE_DIV"), Elemwise::Mode::TRUE_DIV}, {normalize_enum("LOG_SUM_EXP"), Elemwise::Mode::LOG_SUM_EXP}, {normalize_enum("LT"), Elemwise::Mode::LT}, {normalize_enum("LEQ"), Elemwise::Mode::LEQ}, {normalize_enum("EQ"), Elemwise::Mode::EQ}, {normalize_enum("SHL"), Elemwise::Mode::SHL}, {normalize_enum("SHR"), Elemwise::Mode::SHR}, {normalize_enum("COND_LEQ_MOV"), Elemwise::Mode::COND_LEQ_MOV}, {normalize_enum("FUSE_MUL_ADD3"), Elemwise::Mode::FUSE_MUL_ADD3}, {normalize_enum("FUSE_MUL_ADD4"), Elemwise::Mode::FUSE_MUL_ADD4}, {normalize_enum("FUSE_ADD_RELU"), Elemwise::Mode::FUSE_ADD_RELU}, {normalize_enum("FUSE_ADD_SIGMOID"), Elemwise::Mode::FUSE_ADD_SIGMOID}, {normalize_enum("FUSE_ADD_TANH"), Elemwise::Mode::FUSE_ADD_TANH}, {normalize_enum("FAST_TANH"), Elemwise::Mode::FAST_TANH}, {normalize_enum("FAST_TANH_GRAD"), Elemwise::Mode::FAST_TANH_GRAD}, {normalize_enum("ROUND"), Elemwise::Mode::ROUND}, {normalize_enum("RMULH"), Elemwise::Mode::RMULH}, {normalize_enum("ATAN2"), Elemwise::Mode::ATAN2}, {normalize_enum("ERF"), Elemwise::Mode::ERF}, {normalize_enum("ERFINV"), Elemwise::Mode::ERFINV}, {normalize_enum("ERFC"), Elemwise::Mode::ERFC}, {normalize_enum("ERFCINV"), Elemwise::Mode::ERFCINV}, {normalize_enum("H_SWISH"), Elemwise::Mode::H_SWISH}, {normalize_enum("H_SWISH_GRAD"), Elemwise::Mode::H_SWISH_GRAD}, {normalize_enum("FUSE_ADD_H_SWISH"), Elemwise::Mode::FUSE_ADD_H_SWISH}, {normalize_enum("NOT"), Elemwise::Mode::NOT}, {normalize_enum("AND"), Elemwise::Mode::AND}, {normalize_enum("OR"), Elemwise::Mode::OR}, {normalize_enum("XOR"), Elemwise::Mode::XOR}, {normalize_enum("SILU"), Elemwise::Mode::SILU}, {normalize_enum("SILU_GRAD"), Elemwise::Mode::SILU_GRAD}, {normalize_enum("GELU"), Elemwise::Mode::GELU}, {normalize_enum("GELU_GRAD"), Elemwise::Mode::GELU_GRAD}, {normalize_enum("COND_LT_MOV"), Elemwise::Mode::COND_LT_MOV}}; +template<> PyObject* EnumWrapper::pyobj_insts[61] = {nullptr}; + +void _init_py_Elemwise_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Elemwise.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Elemwise.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::RELU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ABS; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ACOS; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ACOS", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ASIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ASIN", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::CEIL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CEIL", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::COS; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COS", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::EXP; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXP", inst) >= 0); + EnumWrapper::pyobj_insts[6] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::EXPM1; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EXPM1", inst) >= 0); + EnumWrapper::pyobj_insts[7] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FLOOR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR", inst) >= 0); + EnumWrapper::pyobj_insts[8] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::LOG; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG", inst) >= 0); + EnumWrapper::pyobj_insts[9] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::LOG1P; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG1P", inst) >= 0); + EnumWrapper::pyobj_insts[10] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::NEGATE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEGATE", inst) >= 0); + EnumWrapper::pyobj_insts[11] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SIGMOID; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID", inst) >= 0); + EnumWrapper::pyobj_insts[12] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIN", inst) >= 0); + EnumWrapper::pyobj_insts[13] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::TANH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0); + EnumWrapper::pyobj_insts[14] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ABS_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ABS_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[15] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ADD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ADD", inst) >= 0); + EnumWrapper::pyobj_insts[16] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FLOOR_DIV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOOR_DIV", inst) >= 0); + EnumWrapper::pyobj_insts[17] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::MAX; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0); + EnumWrapper::pyobj_insts[18] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::MIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0); + EnumWrapper::pyobj_insts[19] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::MOD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MOD", inst) >= 0); + EnumWrapper::pyobj_insts[20] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::MUL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL", inst) >= 0); + EnumWrapper::pyobj_insts[21] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::POW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "POW", inst) >= 0); + EnumWrapper::pyobj_insts[22] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SIGMOID_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SIGMOID_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[23] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SUB; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUB", inst) >= 0); + EnumWrapper::pyobj_insts[24] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SWITCH_GT0; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SWITCH_GT0", inst) >= 0); + EnumWrapper::pyobj_insts[25] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::TANH_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[26] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::TRUE_DIV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRUE_DIV", inst) >= 0); + EnumWrapper::pyobj_insts[27] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::LOG_SUM_EXP; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LOG_SUM_EXP", inst) >= 0); + EnumWrapper::pyobj_insts[28] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::LT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LT", inst) >= 0); + EnumWrapper::pyobj_insts[29] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::LEQ; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LEQ", inst) >= 0); + EnumWrapper::pyobj_insts[30] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::EQ; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "EQ", inst) >= 0); + EnumWrapper::pyobj_insts[31] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SHL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHL", inst) >= 0); + EnumWrapper::pyobj_insts[32] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SHR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SHR", inst) >= 0); + EnumWrapper::pyobj_insts[33] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::COND_LEQ_MOV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LEQ_MOV", inst) >= 0); + EnumWrapper::pyobj_insts[34] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD3; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3", inst) >= 0); + EnumWrapper::pyobj_insts[35] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FUSE_MUL_ADD4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD4", inst) >= 0); + EnumWrapper::pyobj_insts[36] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FUSE_ADD_RELU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RELU", inst) >= 0); + EnumWrapper::pyobj_insts[37] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FUSE_ADD_SIGMOID; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_SIGMOID", inst) >= 0); + EnumWrapper::pyobj_insts[38] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FUSE_ADD_TANH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_TANH", inst) >= 0); + EnumWrapper::pyobj_insts[39] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FAST_TANH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH", inst) >= 0); + EnumWrapper::pyobj_insts[40] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FAST_TANH_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FAST_TANH_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[41] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ROUND; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND", inst) >= 0); + EnumWrapper::pyobj_insts[42] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::RMULH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RMULH", inst) >= 0); + EnumWrapper::pyobj_insts[43] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ATAN2; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ATAN2", inst) >= 0); + EnumWrapper::pyobj_insts[44] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ERF; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERF", inst) >= 0); + EnumWrapper::pyobj_insts[45] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ERFINV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFINV", inst) >= 0); + EnumWrapper::pyobj_insts[46] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ERFC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFC", inst) >= 0); + EnumWrapper::pyobj_insts[47] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::ERFCINV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ERFCINV", inst) >= 0); + EnumWrapper::pyobj_insts[48] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::H_SWISH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH", inst) >= 0); + EnumWrapper::pyobj_insts[49] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::H_SWISH_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "H_SWISH_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[50] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::FUSE_ADD_H_SWISH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_H_SWISH", inst) >= 0); + EnumWrapper::pyobj_insts[51] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::NOT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NOT", inst) >= 0); + EnumWrapper::pyobj_insts[52] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::AND; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AND", inst) >= 0); + EnumWrapper::pyobj_insts[53] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::OR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "OR", inst) >= 0); + EnumWrapper::pyobj_insts[54] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::XOR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "XOR", inst) >= 0); + EnumWrapper::pyobj_insts[55] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SILU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU", inst) >= 0); + EnumWrapper::pyobj_insts[56] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::SILU_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SILU_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[57] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::GELU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU", inst) >= 0); + EnumWrapper::pyobj_insts[58] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::GELU_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "GELU_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[59] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Elemwise::Mode::COND_LT_MOV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "COND_LT_MOV", inst) >= 0); + EnumWrapper::pyobj_insts[60] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Elemwise) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Elemwise) + +int PyOp(Elemwise)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "scope", NULL}; + PyObject *mode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &mode, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Elemwise)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(Elemwise, mode), py_set_generic(Elemwise, mode), const_cast("mode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Elemwise)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Elemwise)::getstate, METH_NOARGS, "Elemwise getstate"}, + {const_cast("__setstate__"), PyOp(Elemwise)::setstate, METH_VARARGS, "Elemwise setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Elemwise(py::module m) { + using py_op = PyOp(Elemwise); + auto& py_type = PyOpType(Elemwise); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Elemwise"; + py_type.tp_basicsize = sizeof(PyOp(Elemwise)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Elemwise"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Elemwise_Mode(py_type); + + PyType_Modified(&py_type); + m.add_object("Elemwise", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Elemwise::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "ElemwiseMultiType.Mode"; + static constexpr std::underlying_type_t max = 58 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"FUSE_MUL_ADD3_INT16x32x32x32", "FUSE_MUL_ADD3_IXxF32xF32xI8", "ROUND_SHR_SATURATE_IXxI8xI8", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", "ROUND_SHR_SATURATE_IXxI8xI16", "QADD", "QFUSE_ADD_RELU", "QMUL", "QMIN", "QMAX", "QSUB", "QTRUE_DIV", "QFUSE_ADD_SIGMOID", "QFUSE_ADD_TANH", "QRELU", "QABS", "QSIGMOID", "QEXP", "QTANH", "QFUSE_MUL_ADD3", "QFAST_TANH", "QNEGATE", "QACOS", "QASIN", "QCEIL", "QCOS", "QEXPM1", "QFLOOR", "QLOG", "QLOG1P", "QSIN", "QROUND", "QERF", "QERFINV", "QERFC", "QERFCINV", "QABS_GRAD", "QFLOOR_DIV", "QMOD", "QSIGMOID_GRAD", "QSWITCH_GT0", "QTANH_GRAD", "QLT", "QLEQ", "QEQ", "QPOW", "QLOG_SUM_EXP", "QFAST_TANH_GRAD", "QATAN2", "QCOND_LEQ_MOV", "QH_SWISH", "QFUSE_ADD_H_SWISH", "QH_SWISH_GRAD", "FUSE_MUL_ADD3_INT16xF32xF32xF32", "MUL_INT16xF32xF32", "FUSE_MUL_ADD3_UINT8xF32xF32xF32", "QCOND_LT_MOV"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("FUSE_MUL_ADD3_INT16x32x32x32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32}, {normalize_enum("FUSE_MUL_ADD3_IXxF32xF32xI8"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8}, {normalize_enum("ROUND_SHR_SATURATE_IXxI8xI8"), ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8}, {normalize_enum("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8"), ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8}, {normalize_enum("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8"), ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8}, {normalize_enum("ROUND_SHR_SATURATE_IXxI8xI16"), ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16}, {normalize_enum("QADD"), ElemwiseMultiType::Mode::QADD}, {normalize_enum("QFUSE_ADD_RELU"), ElemwiseMultiType::Mode::QFUSE_ADD_RELU}, {normalize_enum("QMUL"), ElemwiseMultiType::Mode::QMUL}, {normalize_enum("QMIN"), ElemwiseMultiType::Mode::QMIN}, {normalize_enum("QMAX"), ElemwiseMultiType::Mode::QMAX}, {normalize_enum("QSUB"), ElemwiseMultiType::Mode::QSUB}, {normalize_enum("QTRUE_DIV"), ElemwiseMultiType::Mode::QTRUE_DIV}, {normalize_enum("QFUSE_ADD_SIGMOID"), ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID}, {normalize_enum("QFUSE_ADD_TANH"), ElemwiseMultiType::Mode::QFUSE_ADD_TANH}, {normalize_enum("QRELU"), ElemwiseMultiType::Mode::QRELU}, {normalize_enum("QABS"), ElemwiseMultiType::Mode::QABS}, {normalize_enum("QSIGMOID"), ElemwiseMultiType::Mode::QSIGMOID}, {normalize_enum("QEXP"), ElemwiseMultiType::Mode::QEXP}, {normalize_enum("QTANH"), ElemwiseMultiType::Mode::QTANH}, {normalize_enum("QFUSE_MUL_ADD3"), ElemwiseMultiType::Mode::QFUSE_MUL_ADD3}, {normalize_enum("QFAST_TANH"), ElemwiseMultiType::Mode::QFAST_TANH}, {normalize_enum("QNEGATE"), ElemwiseMultiType::Mode::QNEGATE}, {normalize_enum("QACOS"), ElemwiseMultiType::Mode::QACOS}, {normalize_enum("QASIN"), ElemwiseMultiType::Mode::QASIN}, {normalize_enum("QCEIL"), ElemwiseMultiType::Mode::QCEIL}, {normalize_enum("QCOS"), ElemwiseMultiType::Mode::QCOS}, {normalize_enum("QEXPM1"), ElemwiseMultiType::Mode::QEXPM1}, {normalize_enum("QFLOOR"), ElemwiseMultiType::Mode::QFLOOR}, {normalize_enum("QLOG"), ElemwiseMultiType::Mode::QLOG}, {normalize_enum("QLOG1P"), ElemwiseMultiType::Mode::QLOG1P}, {normalize_enum("QSIN"), ElemwiseMultiType::Mode::QSIN}, {normalize_enum("QROUND"), ElemwiseMultiType::Mode::QROUND}, {normalize_enum("QERF"), ElemwiseMultiType::Mode::QERF}, {normalize_enum("QERFINV"), ElemwiseMultiType::Mode::QERFINV}, {normalize_enum("QERFC"), ElemwiseMultiType::Mode::QERFC}, {normalize_enum("QERFCINV"), ElemwiseMultiType::Mode::QERFCINV}, {normalize_enum("QABS_GRAD"), ElemwiseMultiType::Mode::QABS_GRAD}, {normalize_enum("QFLOOR_DIV"), ElemwiseMultiType::Mode::QFLOOR_DIV}, {normalize_enum("QMOD"), ElemwiseMultiType::Mode::QMOD}, {normalize_enum("QSIGMOID_GRAD"), ElemwiseMultiType::Mode::QSIGMOID_GRAD}, {normalize_enum("QSWITCH_GT0"), ElemwiseMultiType::Mode::QSWITCH_GT0}, {normalize_enum("QTANH_GRAD"), ElemwiseMultiType::Mode::QTANH_GRAD}, {normalize_enum("QLT"), ElemwiseMultiType::Mode::QLT}, {normalize_enum("QLEQ"), ElemwiseMultiType::Mode::QLEQ}, {normalize_enum("QEQ"), ElemwiseMultiType::Mode::QEQ}, {normalize_enum("QPOW"), ElemwiseMultiType::Mode::QPOW}, {normalize_enum("QLOG_SUM_EXP"), ElemwiseMultiType::Mode::QLOG_SUM_EXP}, {normalize_enum("QFAST_TANH_GRAD"), ElemwiseMultiType::Mode::QFAST_TANH_GRAD}, {normalize_enum("QATAN2"), ElemwiseMultiType::Mode::QATAN2}, {normalize_enum("QCOND_LEQ_MOV"), ElemwiseMultiType::Mode::QCOND_LEQ_MOV}, {normalize_enum("QH_SWISH"), ElemwiseMultiType::Mode::QH_SWISH}, {normalize_enum("QFUSE_ADD_H_SWISH"), ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH}, {normalize_enum("QH_SWISH_GRAD"), ElemwiseMultiType::Mode::QH_SWISH_GRAD}, {normalize_enum("FUSE_MUL_ADD3_INT16xF32xF32xF32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32}, {normalize_enum("MUL_INT16xF32xF32"), ElemwiseMultiType::Mode::MUL_INT16xF32xF32}, {normalize_enum("FUSE_MUL_ADD3_UINT8xF32xF32xF32"), ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32}, {normalize_enum("QCOND_LT_MOV"), ElemwiseMultiType::Mode::QCOND_LT_MOV}}; +template<> PyObject* EnumWrapper::pyobj_insts[58] = {nullptr}; + +void _init_py_ElemwiseMultiType_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.ElemwiseMultiType.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("ElemwiseMultiType.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16x32x32x32", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_IXxF32xF32xI8", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI8", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ROUND_SHR_SATURATE_IXxI8xI16", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QADD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QADD", inst) >= 0); + EnumWrapper::pyobj_insts[6] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_RELU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_RELU", inst) >= 0); + EnumWrapper::pyobj_insts[7] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QMUL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMUL", inst) >= 0); + EnumWrapper::pyobj_insts[8] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QMIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMIN", inst) >= 0); + EnumWrapper::pyobj_insts[9] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QMAX; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMAX", inst) >= 0); + EnumWrapper::pyobj_insts[10] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QSUB; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSUB", inst) >= 0); + EnumWrapper::pyobj_insts[11] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QTRUE_DIV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTRUE_DIV", inst) >= 0); + EnumWrapper::pyobj_insts[12] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_SIGMOID", inst) >= 0); + EnumWrapper::pyobj_insts[13] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_TANH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_TANH", inst) >= 0); + EnumWrapper::pyobj_insts[14] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QRELU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QRELU", inst) >= 0); + EnumWrapper::pyobj_insts[15] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QABS; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS", inst) >= 0); + EnumWrapper::pyobj_insts[16] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID", inst) >= 0); + EnumWrapper::pyobj_insts[17] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QEXP; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXP", inst) >= 0); + EnumWrapper::pyobj_insts[18] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QTANH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH", inst) >= 0); + EnumWrapper::pyobj_insts[19] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_MUL_ADD3; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_MUL_ADD3", inst) >= 0); + EnumWrapper::pyobj_insts[20] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH", inst) >= 0); + EnumWrapper::pyobj_insts[21] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QNEGATE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QNEGATE", inst) >= 0); + EnumWrapper::pyobj_insts[22] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QACOS; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QACOS", inst) >= 0); + EnumWrapper::pyobj_insts[23] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QASIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QASIN", inst) >= 0); + EnumWrapper::pyobj_insts[24] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QCEIL; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCEIL", inst) >= 0); + EnumWrapper::pyobj_insts[25] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QCOS; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOS", inst) >= 0); + EnumWrapper::pyobj_insts[26] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QEXPM1; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEXPM1", inst) >= 0); + EnumWrapper::pyobj_insts[27] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR", inst) >= 0); + EnumWrapper::pyobj_insts[28] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QLOG; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG", inst) >= 0); + EnumWrapper::pyobj_insts[29] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QLOG1P; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG1P", inst) >= 0); + EnumWrapper::pyobj_insts[30] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QSIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIN", inst) >= 0); + EnumWrapper::pyobj_insts[31] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QROUND; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QROUND", inst) >= 0); + EnumWrapper::pyobj_insts[32] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QERF; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERF", inst) >= 0); + EnumWrapper::pyobj_insts[33] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QERFINV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFINV", inst) >= 0); + EnumWrapper::pyobj_insts[34] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QERFC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFC", inst) >= 0); + EnumWrapper::pyobj_insts[35] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QERFCINV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QERFCINV", inst) >= 0); + EnumWrapper::pyobj_insts[36] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QABS_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QABS_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[37] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFLOOR_DIV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFLOOR_DIV", inst) >= 0); + EnumWrapper::pyobj_insts[38] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QMOD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QMOD", inst) >= 0); + EnumWrapper::pyobj_insts[39] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QSIGMOID_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSIGMOID_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[40] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QSWITCH_GT0; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QSWITCH_GT0", inst) >= 0); + EnumWrapper::pyobj_insts[41] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QTANH_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QTANH_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[42] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QLT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLT", inst) >= 0); + EnumWrapper::pyobj_insts[43] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QLEQ; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLEQ", inst) >= 0); + EnumWrapper::pyobj_insts[44] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QEQ; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QEQ", inst) >= 0); + EnumWrapper::pyobj_insts[45] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QPOW; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QPOW", inst) >= 0); + EnumWrapper::pyobj_insts[46] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QLOG_SUM_EXP; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QLOG_SUM_EXP", inst) >= 0); + EnumWrapper::pyobj_insts[47] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFAST_TANH_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFAST_TANH_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[48] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QATAN2; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QATAN2", inst) >= 0); + EnumWrapper::pyobj_insts[49] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LEQ_MOV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LEQ_MOV", inst) >= 0); + EnumWrapper::pyobj_insts[50] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH", inst) >= 0); + EnumWrapper::pyobj_insts[51] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QFUSE_ADD_H_SWISH", inst) >= 0); + EnumWrapper::pyobj_insts[52] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QH_SWISH_GRAD; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QH_SWISH_GRAD", inst) >= 0); + EnumWrapper::pyobj_insts[53] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_INT16xF32xF32xF32", inst) >= 0); + EnumWrapper::pyobj_insts[54] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::MUL_INT16xF32xF32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MUL_INT16xF32xF32", inst) >= 0); + EnumWrapper::pyobj_insts[55] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FUSE_MUL_ADD3_UINT8xF32xF32xF32", inst) >= 0); + EnumWrapper::pyobj_insts[56] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ElemwiseMultiType::Mode::QCOND_LT_MOV; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QCOND_LT_MOV", inst) >= 0); + EnumWrapper::pyobj_insts[57] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(ElemwiseMultiType) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"dtype", serialization::dump(opdef.dtype)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ElemwiseMultiType) + +int PyOp(ElemwiseMultiType)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "dtype", "scope", NULL}; + PyObject *mode = NULL, *dtype = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &mode, &dtype, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ElemwiseMultiType)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(ElemwiseMultiType, mode), py_set_generic(ElemwiseMultiType, mode), const_cast("mode"), NULL}, + {const_cast("dtype"), py_get_generic(ElemwiseMultiType, dtype), py_set_generic(ElemwiseMultiType, dtype), const_cast("dtype"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ElemwiseMultiType)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ElemwiseMultiType)::getstate, METH_NOARGS, "ElemwiseMultiType getstate"}, + {const_cast("__setstate__"), PyOp(ElemwiseMultiType)::setstate, METH_VARARGS, "ElemwiseMultiType setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ElemwiseMultiType(py::module m) { + using py_op = PyOp(ElemwiseMultiType); + auto& py_type = PyOpType(ElemwiseMultiType); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ElemwiseMultiType"; + py_type.tp_basicsize = sizeof(PyOp(ElemwiseMultiType)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ElemwiseMultiType"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_ElemwiseMultiType_Mode(py_type); + + PyType_Modified(&py_type); + m.add_object("ElemwiseMultiType", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ElemwiseMultiType::typeinfo(), &py_type).second); +} + +PyOpDefBegin(ExternOpr) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"output_shapes", serialization::dump(opdef.output_shapes)}, + {"name", serialization::dump(opdef.name)}, + {"data", serialization::dump(opdef.data)}, + {"data_len", serialization::dump(opdef.data_len)}, + {"output_dtypes", serialization::dump(opdef.output_dtypes)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("output_shapes"); + if (iter != state.end()) { + opdef.output_shapes = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("name"); + if (iter != state.end()) { + opdef.name = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("data"); + if (iter != state.end()) { + opdef.data = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("data_len"); + if (iter != state.end()) { + opdef.data_len = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("output_dtypes"); + if (iter != state.end()) { + opdef.output_dtypes = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ExternOpr) + +int PyOp(ExternOpr)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"output_shapes", "name", "data", "data_len", "output_dtypes", "scope", NULL}; + PyObject *output_shapes = NULL, *name = NULL, *data = NULL, *data_len = NULL, *output_dtypes = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast(kwlist), &output_shapes, &name, &data, &data_len, &output_dtypes, &scope)) + return -1; + + if (output_shapes) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().output_shapes = + py::cast(py::handle(output_shapes)); + } CATCH_ALL(-1) + } + + if (name) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().name = + py::cast(py::handle(name)); + } CATCH_ALL(-1) + } + + if (data) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().data = + py::cast(py::handle(data)); + } CATCH_ALL(-1) + } + + if (data_len) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().data_len = + py::cast(py::handle(data_len)); + } CATCH_ALL(-1) + } + + if (output_dtypes) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().output_dtypes = + py::cast(py::handle(output_dtypes)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ExternOpr)::py_getsetters[] = { + {const_cast("output_shapes"), py_get_generic(ExternOpr, output_shapes), py_set_generic(ExternOpr, output_shapes), const_cast("output_shapes"), NULL}, + {const_cast("name"), py_get_generic(ExternOpr, name), py_set_generic(ExternOpr, name), const_cast("name"), NULL}, + {const_cast("data"), py_get_generic(ExternOpr, data), py_set_generic(ExternOpr, data), const_cast("data"), NULL}, + {const_cast("data_len"), py_get_generic(ExternOpr, data_len), py_set_generic(ExternOpr, data_len), const_cast("data_len"), NULL}, + {const_cast("output_dtypes"), py_get_generic(ExternOpr, output_dtypes), py_set_generic(ExternOpr, output_dtypes), const_cast("output_dtypes"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ExternOpr)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ExternOpr)::getstate, METH_NOARGS, "ExternOpr getstate"}, + {const_cast("__setstate__"), PyOp(ExternOpr)::setstate, METH_VARARGS, "ExternOpr setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ExternOpr(py::module m) { + using py_op = PyOp(ExternOpr); + auto& py_type = PyOpType(ExternOpr); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ExternOpr"; + py_type.tp_basicsize = sizeof(PyOp(ExternOpr)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ExternOpr"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("ExternOpr", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ExternOpr::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Eye) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"k", serialization::dump(opdef.k)}, + {"dtype", serialization::dump(opdef.dtype)}, + {"comp_node", serialization::dump(opdef.comp_node)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("k"); + if (iter != state.end()) { + opdef.k = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("comp_node"); + if (iter != state.end()) { + opdef.comp_node = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Eye) + +int PyOp(Eye)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"k", "dtype", "comp_node", "scope", NULL}; + PyObject *k = NULL, *dtype = NULL, *comp_node = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast(kwlist), &k, &dtype, &comp_node, &scope)) + return -1; + + if (k) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().k = + py::cast(py::handle(k)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (comp_node) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().comp_node = + py::cast(py::handle(comp_node)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Eye)::py_getsetters[] = { + {const_cast("k"), py_get_generic(Eye, k), py_set_generic(Eye, k), const_cast("k"), NULL}, + {const_cast("dtype"), py_get_generic(Eye, dtype), py_set_generic(Eye, dtype), const_cast("dtype"), NULL}, + {const_cast("comp_node"), py_get_generic(Eye, comp_node), py_set_generic(Eye, comp_node), const_cast("comp_node"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Eye)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Eye)::getstate, METH_NOARGS, "Eye getstate"}, + {const_cast("__setstate__"), PyOp(Eye)::setstate, METH_VARARGS, "Eye setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Eye(py::module m) { + using py_op = PyOp(Eye); + auto& py_type = PyOpType(Eye); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Eye"; + py_type.tp_basicsize = sizeof(PyOp(Eye)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Eye"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Eye", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Eye::typeinfo(), &py_type).second); +} + +PyOpDefBegin(FakeQuant) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"qmin", serialization::dump(opdef.qmin)}, + {"qmax", serialization::dump(opdef.qmax)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("qmin"); + if (iter != state.end()) { + opdef.qmin = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("qmax"); + if (iter != state.end()) { + opdef.qmax = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(FakeQuant) + +int PyOp(FakeQuant)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"qmin", "qmax", "scope", NULL}; + PyObject *qmin = NULL, *qmax = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &qmin, &qmax, &scope)) + return -1; + + if (qmin) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().qmin = + py::cast(py::handle(qmin)); + } CATCH_ALL(-1) + } + + if (qmax) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().qmax = + py::cast(py::handle(qmax)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(FakeQuant)::py_getsetters[] = { + {const_cast("qmin"), py_get_generic(FakeQuant, qmin), py_set_generic(FakeQuant, qmin), const_cast("qmin"), NULL}, + {const_cast("qmax"), py_get_generic(FakeQuant, qmax), py_set_generic(FakeQuant, qmax), const_cast("qmax"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(FakeQuant)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(FakeQuant)::getstate, METH_NOARGS, "FakeQuant getstate"}, + {const_cast("__setstate__"), PyOp(FakeQuant)::setstate, METH_VARARGS, "FakeQuant setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_FakeQuant(py::module m) { + using py_op = PyOp(FakeQuant); + auto& py_type = PyOpType(FakeQuant); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.FakeQuant"; + py_type.tp_basicsize = sizeof(PyOp(FakeQuant)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "FakeQuant"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("FakeQuant", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FakeQuant::typeinfo(), &py_type).second); +} + +PyOpDefBegin(FastpathCopy) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(FastpathCopy) + +int PyOp(FastpathCopy)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + + return 0; +} + +PyGetSetDef PyOp(FastpathCopy)::py_getsetters[] = { + + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(FastpathCopy)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(FastpathCopy)::getstate, METH_NOARGS, "FastpathCopy getstate"}, + {const_cast("__setstate__"), PyOp(FastpathCopy)::setstate, METH_VARARGS, "FastpathCopy setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_FastpathCopy(py::module m) { + using py_op = PyOp(FastpathCopy); + auto& py_type = PyOpType(FastpathCopy); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.FastpathCopy"; + py_type.tp_basicsize = sizeof(PyOp(FastpathCopy)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "FastpathCopy"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("FastpathCopy", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(FastpathCopy::typeinfo(), &py_type).second); +} + +PyOpDefBegin(GammaRNG) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"seed", serialization::dump(opdef.seed)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(GammaRNG) + +int PyOp(GammaRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"seed", "handle", "scope", NULL}; + PyObject *seed = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &seed, &handle, &scope)) + return -1; + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(GammaRNG)::py_getsetters[] = { + {const_cast("seed"), py_get_generic(GammaRNG, seed), py_set_generic(GammaRNG, seed), const_cast("seed"), NULL}, + {const_cast("handle"), py_get_generic(GammaRNG, handle), py_set_generic(GammaRNG, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(GammaRNG)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(GammaRNG)::getstate, METH_NOARGS, "GammaRNG getstate"}, + {const_cast("__setstate__"), PyOp(GammaRNG)::setstate, METH_VARARGS, "GammaRNG setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_GammaRNG(py::module m) { + using py_op = PyOp(GammaRNG); + auto& py_type = PyOpType(GammaRNG); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.GammaRNG"; + py_type.tp_basicsize = sizeof(PyOp(GammaRNG)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "GammaRNG"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("GammaRNG", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GammaRNG::typeinfo(), &py_type).second); +} + +PyOpDefBegin(GaussianRNG) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"seed", serialization::dump(opdef.seed)}, + {"mean", serialization::dump(opdef.mean)}, + {"std", serialization::dump(opdef.std)}, + {"dtype", serialization::dump(opdef.dtype)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("mean"); + if (iter != state.end()) { + opdef.mean = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("std"); + if (iter != state.end()) { + opdef.std = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(GaussianRNG) + +int PyOp(GaussianRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"seed", "mean", "std", "dtype", "handle", "scope", NULL}; + PyObject *seed = NULL, *mean = NULL, *std = NULL, *dtype = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast(kwlist), &seed, &mean, &std, &dtype, &handle, &scope)) + return -1; + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (mean) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mean = + py::cast(py::handle(mean)); + } CATCH_ALL(-1) + } + + if (std) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().std = + py::cast(py::handle(std)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(GaussianRNG)::py_getsetters[] = { + {const_cast("seed"), py_get_generic(GaussianRNG, seed), py_set_generic(GaussianRNG, seed), const_cast("seed"), NULL}, + {const_cast("mean"), py_get_generic(GaussianRNG, mean), py_set_generic(GaussianRNG, mean), const_cast("mean"), NULL}, + {const_cast("std"), py_get_generic(GaussianRNG, std), py_set_generic(GaussianRNG, std), const_cast("std"), NULL}, + {const_cast("dtype"), py_get_generic(GaussianRNG, dtype), py_set_generic(GaussianRNG, dtype), const_cast("dtype"), NULL}, + {const_cast("handle"), py_get_generic(GaussianRNG, handle), py_set_generic(GaussianRNG, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(GaussianRNG)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(GaussianRNG)::getstate, METH_NOARGS, "GaussianRNG getstate"}, + {const_cast("__setstate__"), PyOp(GaussianRNG)::setstate, METH_VARARGS, "GaussianRNG setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_GaussianRNG(py::module m) { + using py_op = PyOp(GaussianRNG); + auto& py_type = PyOpType(GaussianRNG); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.GaussianRNG"; + py_type.tp_basicsize = sizeof(PyOp(GaussianRNG)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "GaussianRNG"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("GaussianRNG", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GaussianRNG::typeinfo(), &py_type).second); +} + +PyOpDefBegin(GetVarShape) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(GetVarShape) + +int PyOp(GetVarShape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "scope", NULL}; + PyObject *axis = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &axis, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(GetVarShape)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(GetVarShape, axis), py_set_generic(GetVarShape, axis), const_cast("axis"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(GetVarShape)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(GetVarShape)::getstate, METH_NOARGS, "GetVarShape getstate"}, + {const_cast("__setstate__"), PyOp(GetVarShape)::setstate, METH_VARARGS, "GetVarShape setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_GetVarShape(py::module m) { + using py_op = PyOp(GetVarShape); + auto& py_type = PyOpType(GetVarShape); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.GetVarShape"; + py_type.tp_basicsize = sizeof(PyOp(GetVarShape)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "GetVarShape"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("GetVarShape", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GetVarShape::typeinfo(), &py_type).second); +} + +void _init_py_GroupLocal_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_GroupLocal_Sparse(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Sparse", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_GroupLocal_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_GroupLocal_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(GroupLocal) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"sparse", serialization::dump(opdef.sparse)}, + {"format", serialization::dump(opdef.format)}, + {"compute_mode", serialization::dump(opdef.compute_mode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sparse"); + if (iter != state.end()) { + opdef.sparse = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(GroupLocal) + +int PyOp(GroupLocal)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "sparse", "format", "compute_mode", "scope", NULL}; + PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *sparse = NULL, *format = NULL, *compute_mode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &sparse, &format, &compute_mode, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (sparse) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sparse = + py::cast(py::handle(sparse)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(GroupLocal)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(GroupLocal, mode), py_set_generic(GroupLocal, mode), const_cast("mode"), NULL}, + {const_cast("pad_h"), py_get_generic(GroupLocal, pad_h), py_set_generic(GroupLocal, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(GroupLocal, pad_w), py_set_generic(GroupLocal, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(GroupLocal, stride_h), py_set_generic(GroupLocal, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(GroupLocal, stride_w), py_set_generic(GroupLocal, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(GroupLocal, dilate_h), py_set_generic(GroupLocal, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(GroupLocal, dilate_w), py_set_generic(GroupLocal, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("sparse"), py_get_generic(GroupLocal, sparse), py_set_generic(GroupLocal, sparse), const_cast("sparse"), NULL}, + {const_cast("format"), py_get_generic(GroupLocal, format), py_set_generic(GroupLocal, format), const_cast("format"), NULL}, + {const_cast("compute_mode"), py_get_generic(GroupLocal, compute_mode), py_set_generic(GroupLocal, compute_mode), const_cast("compute_mode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(GroupLocal)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(GroupLocal)::getstate, METH_NOARGS, "GroupLocal getstate"}, + {const_cast("__setstate__"), PyOp(GroupLocal)::setstate, METH_VARARGS, "GroupLocal setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_GroupLocal(py::module m) { + using py_op = PyOp(GroupLocal); + auto& py_type = PyOpType(GroupLocal); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.GroupLocal"; + py_type.tp_basicsize = sizeof(PyOp(GroupLocal)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "GroupLocal"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_GroupLocal_Mode(py_type); + _init_py_GroupLocal_Sparse(py_type); + _init_py_GroupLocal_Format(py_type); + _init_py_GroupLocal_ComputeMode(py_type); + + PyType_Modified(&py_type); + m.add_object("GroupLocal", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(GroupLocal::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Identity) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Identity) + +int PyOp(Identity)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + + return 0; +} + +PyGetSetDef PyOp(Identity)::py_getsetters[] = { + + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Identity)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Identity)::getstate, METH_NOARGS, "Identity getstate"}, + {const_cast("__setstate__"), PyOp(Identity)::setstate, METH_VARARGS, "Identity setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Identity(py::module m) { + using py_op = PyOp(Identity); + auto& py_type = PyOpType(Identity); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Identity"; + py_type.tp_basicsize = sizeof(PyOp(Identity)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Identity"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Identity", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Identity::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Images2Neibs) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"window_h", serialization::dump(opdef.window_h)}, + {"window_w", serialization::dump(opdef.window_w)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("window_h"); + if (iter != state.end()) { + opdef.window_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("window_w"); + if (iter != state.end()) { + opdef.window_w = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Images2Neibs) + +int PyOp(Images2Neibs)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "window_h", "window_w", "scope", NULL}; + PyObject *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *window_h = NULL, *window_w = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast(kwlist), &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &window_h, &window_w, &scope)) + return -1; + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (window_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().window_h = + py::cast(py::handle(window_h)); + } CATCH_ALL(-1) + } + + if (window_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().window_w = + py::cast(py::handle(window_w)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Images2Neibs)::py_getsetters[] = { + {const_cast("pad_h"), py_get_generic(Images2Neibs, pad_h), py_set_generic(Images2Neibs, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(Images2Neibs, pad_w), py_set_generic(Images2Neibs, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(Images2Neibs, stride_h), py_set_generic(Images2Neibs, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(Images2Neibs, stride_w), py_set_generic(Images2Neibs, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(Images2Neibs, dilate_h), py_set_generic(Images2Neibs, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(Images2Neibs, dilate_w), py_set_generic(Images2Neibs, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("window_h"), py_get_generic(Images2Neibs, window_h), py_set_generic(Images2Neibs, window_h), const_cast("window_h"), NULL}, + {const_cast("window_w"), py_get_generic(Images2Neibs, window_w), py_set_generic(Images2Neibs, window_w), const_cast("window_w"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Images2Neibs)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Images2Neibs)::getstate, METH_NOARGS, "Images2Neibs getstate"}, + {const_cast("__setstate__"), PyOp(Images2Neibs)::setstate, METH_VARARGS, "Images2Neibs setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Images2Neibs(py::module m) { + using py_op = PyOp(Images2Neibs); + auto& py_type = PyOpType(Images2Neibs); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Images2Neibs"; + py_type.tp_basicsize = sizeof(PyOp(Images2Neibs)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Images2Neibs"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Images2Neibs", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Images2Neibs::typeinfo(), &py_type).second); +} + +PyOpDefBegin(IncrMeshIndexing) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(IncrMeshIndexing) + +int PyOp(IncrMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(IncrMeshIndexing)::py_getsetters[] = { + {const_cast("items"), py_get_generic(IncrMeshIndexing, items), py_set_generic(IncrMeshIndexing, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(IncrMeshIndexing)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(IncrMeshIndexing)::getstate, METH_NOARGS, "IncrMeshIndexing getstate"}, + {const_cast("__setstate__"), PyOp(IncrMeshIndexing)::setstate, METH_VARARGS, "IncrMeshIndexing setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_IncrMeshIndexing(py::module m) { + using py_op = PyOp(IncrMeshIndexing); + auto& py_type = PyOpType(IncrMeshIndexing); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.IncrMeshIndexing"; + py_type.tp_basicsize = sizeof(PyOp(IncrMeshIndexing)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "IncrMeshIndexing"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("IncrMeshIndexing", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrMeshIndexing::typeinfo(), &py_type).second); +} + +PyOpDefBegin(IncrSubtensor) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(IncrSubtensor) + +int PyOp(IncrSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(IncrSubtensor)::py_getsetters[] = { + {const_cast("items"), py_get_generic(IncrSubtensor, items), py_set_generic(IncrSubtensor, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(IncrSubtensor)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(IncrSubtensor)::getstate, METH_NOARGS, "IncrSubtensor getstate"}, + {const_cast("__setstate__"), PyOp(IncrSubtensor)::setstate, METH_VARARGS, "IncrSubtensor setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_IncrSubtensor(py::module m) { + using py_op = PyOp(IncrSubtensor); + auto& py_type = PyOpType(IncrSubtensor); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.IncrSubtensor"; + py_type.tp_basicsize = sizeof(PyOp(IncrSubtensor)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "IncrSubtensor"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("IncrSubtensor", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IncrSubtensor::typeinfo(), &py_type).second); +} + +PyOpDefBegin(IndexingIncrMultiAxisVec) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(IndexingIncrMultiAxisVec) + +int PyOp(IndexingIncrMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(IndexingIncrMultiAxisVec)::py_getsetters[] = { + {const_cast("items"), py_get_generic(IndexingIncrMultiAxisVec, items), py_set_generic(IndexingIncrMultiAxisVec, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(IndexingIncrMultiAxisVec)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(IndexingIncrMultiAxisVec)::getstate, METH_NOARGS, "IndexingIncrMultiAxisVec getstate"}, + {const_cast("__setstate__"), PyOp(IndexingIncrMultiAxisVec)::setstate, METH_VARARGS, "IndexingIncrMultiAxisVec setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_IndexingIncrMultiAxisVec(py::module m) { + using py_op = PyOp(IndexingIncrMultiAxisVec); + auto& py_type = PyOpType(IndexingIncrMultiAxisVec); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingIncrMultiAxisVec"; + py_type.tp_basicsize = sizeof(PyOp(IndexingIncrMultiAxisVec)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "IndexingIncrMultiAxisVec"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("IndexingIncrMultiAxisVec", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingIncrMultiAxisVec::typeinfo(), &py_type).second); +} + +PyOpDefBegin(IndexingMultiAxisVec) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(IndexingMultiAxisVec) + +int PyOp(IndexingMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(IndexingMultiAxisVec)::py_getsetters[] = { + {const_cast("items"), py_get_generic(IndexingMultiAxisVec, items), py_set_generic(IndexingMultiAxisVec, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(IndexingMultiAxisVec)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(IndexingMultiAxisVec)::getstate, METH_NOARGS, "IndexingMultiAxisVec getstate"}, + {const_cast("__setstate__"), PyOp(IndexingMultiAxisVec)::setstate, METH_VARARGS, "IndexingMultiAxisVec setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_IndexingMultiAxisVec(py::module m) { + using py_op = PyOp(IndexingMultiAxisVec); + auto& py_type = PyOpType(IndexingMultiAxisVec); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingMultiAxisVec"; + py_type.tp_basicsize = sizeof(PyOp(IndexingMultiAxisVec)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "IndexingMultiAxisVec"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("IndexingMultiAxisVec", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingMultiAxisVec::typeinfo(), &py_type).second); +} + +PyOpDefBegin(IndexingOneHot) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)}, + {"ndim", serialization::dump(opdef.ndim)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("ndim"); + if (iter != state.end()) { + opdef.ndim = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(IndexingOneHot) + +int PyOp(IndexingOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "ndim", "scope", NULL}; + PyObject *axis = NULL, *ndim = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &axis, &ndim, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (ndim) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().ndim = + py::cast(py::handle(ndim)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(IndexingOneHot)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(IndexingOneHot, axis), py_set_generic(IndexingOneHot, axis), const_cast("axis"), NULL}, + {const_cast("ndim"), py_get_generic(IndexingOneHot, ndim), py_set_generic(IndexingOneHot, ndim), const_cast("ndim"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(IndexingOneHot)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(IndexingOneHot)::getstate, METH_NOARGS, "IndexingOneHot getstate"}, + {const_cast("__setstate__"), PyOp(IndexingOneHot)::setstate, METH_VARARGS, "IndexingOneHot setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_IndexingOneHot(py::module m) { + using py_op = PyOp(IndexingOneHot); + auto& py_type = PyOpType(IndexingOneHot); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingOneHot"; + py_type.tp_basicsize = sizeof(PyOp(IndexingOneHot)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "IndexingOneHot"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("IndexingOneHot", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingOneHot::typeinfo(), &py_type).second); +} + +PyOpDefBegin(IndexingSetMultiAxisVec) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(IndexingSetMultiAxisVec) + +int PyOp(IndexingSetMultiAxisVec)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(IndexingSetMultiAxisVec)::py_getsetters[] = { + {const_cast("items"), py_get_generic(IndexingSetMultiAxisVec, items), py_set_generic(IndexingSetMultiAxisVec, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(IndexingSetMultiAxisVec)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(IndexingSetMultiAxisVec)::getstate, METH_NOARGS, "IndexingSetMultiAxisVec getstate"}, + {const_cast("__setstate__"), PyOp(IndexingSetMultiAxisVec)::setstate, METH_VARARGS, "IndexingSetMultiAxisVec setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_IndexingSetMultiAxisVec(py::module m) { + using py_op = PyOp(IndexingSetMultiAxisVec); + auto& py_type = PyOpType(IndexingSetMultiAxisVec); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetMultiAxisVec"; + py_type.tp_basicsize = sizeof(PyOp(IndexingSetMultiAxisVec)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "IndexingSetMultiAxisVec"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("IndexingSetMultiAxisVec", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetMultiAxisVec::typeinfo(), &py_type).second); +} + +PyOpDefBegin(IndexingSetOneHot) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)}, + {"ndim", serialization::dump(opdef.ndim)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("ndim"); + if (iter != state.end()) { + opdef.ndim = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(IndexingSetOneHot) + +int PyOp(IndexingSetOneHot)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "ndim", "scope", NULL}; + PyObject *axis = NULL, *ndim = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &axis, &ndim, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (ndim) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().ndim = + py::cast(py::handle(ndim)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(IndexingSetOneHot)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(IndexingSetOneHot, axis), py_set_generic(IndexingSetOneHot, axis), const_cast("axis"), NULL}, + {const_cast("ndim"), py_get_generic(IndexingSetOneHot, ndim), py_set_generic(IndexingSetOneHot, ndim), const_cast("ndim"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(IndexingSetOneHot)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(IndexingSetOneHot)::getstate, METH_NOARGS, "IndexingSetOneHot getstate"}, + {const_cast("__setstate__"), PyOp(IndexingSetOneHot)::setstate, METH_VARARGS, "IndexingSetOneHot setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_IndexingSetOneHot(py::module m) { + using py_op = PyOp(IndexingSetOneHot); + auto& py_type = PyOpType(IndexingSetOneHot); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.IndexingSetOneHot"; + py_type.tp_basicsize = sizeof(PyOp(IndexingSetOneHot)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "IndexingSetOneHot"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("IndexingSetOneHot", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(IndexingSetOneHot::typeinfo(), &py_type).second); +} + +PyOpDefBegin(InplaceAdd) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(InplaceAdd) + +int PyOp(InplaceAdd)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + + return 0; +} + +PyGetSetDef PyOp(InplaceAdd)::py_getsetters[] = { + + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(InplaceAdd)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(InplaceAdd)::getstate, METH_NOARGS, "InplaceAdd getstate"}, + {const_cast("__setstate__"), PyOp(InplaceAdd)::setstate, METH_VARARGS, "InplaceAdd setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_InplaceAdd(py::module m) { + using py_op = PyOp(InplaceAdd); + auto& py_type = PyOpType(InplaceAdd); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.InplaceAdd"; + py_type.tp_basicsize = sizeof(PyOp(InplaceAdd)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "InplaceAdd"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("InplaceAdd", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(InplaceAdd::typeinfo(), &py_type).second); +} + +PyOpDefBegin(LAMBUpdate) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"beta_1", serialization::dump(opdef.beta_1)}, + {"beta_2", serialization::dump(opdef.beta_2)}, + {"step", serialization::dump(opdef.step)}, + {"lr", serialization::dump(opdef.lr)}, + {"weight_decay", serialization::dump(opdef.weight_decay)}, + {"eps", serialization::dump(opdef.eps)}, + {"bias_correction", serialization::dump(opdef.bias_correction)}, + {"always_adapt", serialization::dump(opdef.always_adapt)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("beta_1"); + if (iter != state.end()) { + opdef.beta_1 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("beta_2"); + if (iter != state.end()) { + opdef.beta_2 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("step"); + if (iter != state.end()) { + opdef.step = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("lr"); + if (iter != state.end()) { + opdef.lr = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("weight_decay"); + if (iter != state.end()) { + opdef.weight_decay = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("eps"); + if (iter != state.end()) { + opdef.eps = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bias_correction"); + if (iter != state.end()) { + opdef.bias_correction = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("always_adapt"); + if (iter != state.end()) { + opdef.always_adapt = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(LAMBUpdate) + +int PyOp(LAMBUpdate)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"beta_1", "beta_2", "step", "lr", "weight_decay", "eps", "bias_correction", "always_adapt", "scope", NULL}; + PyObject *beta_1 = NULL, *beta_2 = NULL, *step = NULL, *lr = NULL, *weight_decay = NULL, *eps = NULL, *bias_correction = NULL, *always_adapt = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast(kwlist), &beta_1, &beta_2, &step, &lr, &weight_decay, &eps, &bias_correction, &always_adapt, &scope)) + return -1; + + if (beta_1) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().beta_1 = + py::cast(py::handle(beta_1)); + } CATCH_ALL(-1) + } + + if (beta_2) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().beta_2 = + py::cast(py::handle(beta_2)); + } CATCH_ALL(-1) + } + + if (step) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().step = + py::cast(py::handle(step)); + } CATCH_ALL(-1) + } + + if (lr) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().lr = + py::cast(py::handle(lr)); + } CATCH_ALL(-1) + } + + if (weight_decay) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().weight_decay = + py::cast(py::handle(weight_decay)); + } CATCH_ALL(-1) + } + + if (eps) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().eps = + py::cast(py::handle(eps)); + } CATCH_ALL(-1) + } + + if (bias_correction) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bias_correction = + py::cast(py::handle(bias_correction)); + } CATCH_ALL(-1) + } + + if (always_adapt) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().always_adapt = + py::cast(py::handle(always_adapt)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(LAMBUpdate)::py_getsetters[] = { + {const_cast("beta_1"), py_get_generic(LAMBUpdate, beta_1), py_set_generic(LAMBUpdate, beta_1), const_cast("beta_1"), NULL}, + {const_cast("beta_2"), py_get_generic(LAMBUpdate, beta_2), py_set_generic(LAMBUpdate, beta_2), const_cast("beta_2"), NULL}, + {const_cast("step"), py_get_generic(LAMBUpdate, step), py_set_generic(LAMBUpdate, step), const_cast("step"), NULL}, + {const_cast("lr"), py_get_generic(LAMBUpdate, lr), py_set_generic(LAMBUpdate, lr), const_cast("lr"), NULL}, + {const_cast("weight_decay"), py_get_generic(LAMBUpdate, weight_decay), py_set_generic(LAMBUpdate, weight_decay), const_cast("weight_decay"), NULL}, + {const_cast("eps"), py_get_generic(LAMBUpdate, eps), py_set_generic(LAMBUpdate, eps), const_cast("eps"), NULL}, + {const_cast("bias_correction"), py_get_generic(LAMBUpdate, bias_correction), py_set_generic(LAMBUpdate, bias_correction), const_cast("bias_correction"), NULL}, + {const_cast("always_adapt"), py_get_generic(LAMBUpdate, always_adapt), py_set_generic(LAMBUpdate, always_adapt), const_cast("always_adapt"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(LAMBUpdate)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(LAMBUpdate)::getstate, METH_NOARGS, "LAMBUpdate getstate"}, + {const_cast("__setstate__"), PyOp(LAMBUpdate)::setstate, METH_VARARGS, "LAMBUpdate setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_LAMBUpdate(py::module m) { + using py_op = PyOp(LAMBUpdate); + auto& py_type = PyOpType(LAMBUpdate); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.LAMBUpdate"; + py_type.tp_basicsize = sizeof(PyOp(LAMBUpdate)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "LAMBUpdate"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("LAMBUpdate", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LAMBUpdate::typeinfo(), &py_type).second); +} + +PyOpDefBegin(LRN) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"n", serialization::dump(opdef.n)}, + {"k", serialization::dump(opdef.k)}, + {"alpha", serialization::dump(opdef.alpha)}, + {"beta", serialization::dump(opdef.beta)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("n"); + if (iter != state.end()) { + opdef.n = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("k"); + if (iter != state.end()) { + opdef.k = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("alpha"); + if (iter != state.end()) { + opdef.alpha = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("beta"); + if (iter != state.end()) { + opdef.beta = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(LRN) + +int PyOp(LRN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"n", "k", "alpha", "beta", "scope", NULL}; + PyObject *n = NULL, *k = NULL, *alpha = NULL, *beta = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast(kwlist), &n, &k, &alpha, &beta, &scope)) + return -1; + + if (n) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().n = + py::cast(py::handle(n)); + } CATCH_ALL(-1) + } + + if (k) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().k = + py::cast(py::handle(k)); + } CATCH_ALL(-1) + } + + if (alpha) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().alpha = + py::cast(py::handle(alpha)); + } CATCH_ALL(-1) + } + + if (beta) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().beta = + py::cast(py::handle(beta)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(LRN)::py_getsetters[] = { + {const_cast("n"), py_get_generic(LRN, n), py_set_generic(LRN, n), const_cast("n"), NULL}, + {const_cast("k"), py_get_generic(LRN, k), py_set_generic(LRN, k), const_cast("k"), NULL}, + {const_cast("alpha"), py_get_generic(LRN, alpha), py_set_generic(LRN, alpha), const_cast("alpha"), NULL}, + {const_cast("beta"), py_get_generic(LRN, beta), py_set_generic(LRN, beta), const_cast("beta"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(LRN)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(LRN)::getstate, METH_NOARGS, "LRN getstate"}, + {const_cast("__setstate__"), PyOp(LRN)::setstate, METH_VARARGS, "LRN setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_LRN(py::module m) { + using py_op = PyOp(LRN); + auto& py_type = PyOpType(LRN); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.LRN"; + py_type.tp_basicsize = sizeof(PyOp(LRN)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "LRN"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("LRN", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LRN::typeinfo(), &py_type).second); +} + +PyOpDefBegin(LSQ) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"qmin", serialization::dump(opdef.qmin)}, + {"qmax", serialization::dump(opdef.qmax)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("qmin"); + if (iter != state.end()) { + opdef.qmin = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("qmax"); + if (iter != state.end()) { + opdef.qmax = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(LSQ) + +int PyOp(LSQ)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"qmin", "qmax", "scope", NULL}; + PyObject *qmin = NULL, *qmax = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &qmin, &qmax, &scope)) + return -1; + + if (qmin) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().qmin = + py::cast(py::handle(qmin)); + } CATCH_ALL(-1) + } + + if (qmax) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().qmax = + py::cast(py::handle(qmax)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(LSQ)::py_getsetters[] = { + {const_cast("qmin"), py_get_generic(LSQ, qmin), py_set_generic(LSQ, qmin), const_cast("qmin"), NULL}, + {const_cast("qmax"), py_get_generic(LSQ, qmax), py_set_generic(LSQ, qmax), const_cast("qmax"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(LSQ)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(LSQ)::getstate, METH_NOARGS, "LSQ getstate"}, + {const_cast("__setstate__"), PyOp(LSQ)::setstate, METH_VARARGS, "LSQ setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_LSQ(py::module m) { + using py_op = PyOp(LSQ); + auto& py_type = PyOpType(LSQ); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.LSQ"; + py_type.tp_basicsize = sizeof(PyOp(LSQ)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "LSQ"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("LSQ", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSQ::typeinfo(), &py_type).second); +} + +void _init_py_LSTM_FwdMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "FwdMode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(LSTM) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"num_layers", serialization::dump(opdef.num_layers)}, + {"bidirectional", serialization::dump(opdef.bidirectional)}, + {"bias", serialization::dump(opdef.bias)}, + {"hidden_size", serialization::dump(opdef.hidden_size)}, + {"proj_size", serialization::dump(opdef.proj_size)}, + {"dropout", serialization::dump(opdef.dropout)}, + {"fwd_mode", serialization::dump(opdef.fwd_mode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("num_layers"); + if (iter != state.end()) { + opdef.num_layers = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bidirectional"); + if (iter != state.end()) { + opdef.bidirectional = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bias"); + if (iter != state.end()) { + opdef.bias = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("hidden_size"); + if (iter != state.end()) { + opdef.hidden_size = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("proj_size"); + if (iter != state.end()) { + opdef.proj_size = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dropout"); + if (iter != state.end()) { + opdef.dropout = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("fwd_mode"); + if (iter != state.end()) { + opdef.fwd_mode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(LSTM) + +int PyOp(LSTM)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "proj_size", "dropout", "fwd_mode", "scope", NULL}; + PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *proj_size = NULL, *dropout = NULL, *fwd_mode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &proj_size, &dropout, &fwd_mode, &scope)) + return -1; + + if (num_layers) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().num_layers = + py::cast(py::handle(num_layers)); + } CATCH_ALL(-1) + } + + if (bidirectional) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bidirectional = + py::cast(py::handle(bidirectional)); + } CATCH_ALL(-1) + } + + if (bias) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bias = + py::cast(py::handle(bias)); + } CATCH_ALL(-1) + } + + if (hidden_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().hidden_size = + py::cast(py::handle(hidden_size)); + } CATCH_ALL(-1) + } + + if (proj_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().proj_size = + py::cast(py::handle(proj_size)); + } CATCH_ALL(-1) + } + + if (dropout) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dropout = + py::cast(py::handle(dropout)); + } CATCH_ALL(-1) + } + + if (fwd_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().fwd_mode = + py::cast(py::handle(fwd_mode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(LSTM)::py_getsetters[] = { + {const_cast("num_layers"), py_get_generic(LSTM, num_layers), py_set_generic(LSTM, num_layers), const_cast("num_layers"), NULL}, + {const_cast("bidirectional"), py_get_generic(LSTM, bidirectional), py_set_generic(LSTM, bidirectional), const_cast("bidirectional"), NULL}, + {const_cast("bias"), py_get_generic(LSTM, bias), py_set_generic(LSTM, bias), const_cast("bias"), NULL}, + {const_cast("hidden_size"), py_get_generic(LSTM, hidden_size), py_set_generic(LSTM, hidden_size), const_cast("hidden_size"), NULL}, + {const_cast("proj_size"), py_get_generic(LSTM, proj_size), py_set_generic(LSTM, proj_size), const_cast("proj_size"), NULL}, + {const_cast("dropout"), py_get_generic(LSTM, dropout), py_set_generic(LSTM, dropout), const_cast("dropout"), NULL}, + {const_cast("fwd_mode"), py_get_generic(LSTM, fwd_mode), py_set_generic(LSTM, fwd_mode), const_cast("fwd_mode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(LSTM)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(LSTM)::getstate, METH_NOARGS, "LSTM getstate"}, + {const_cast("__setstate__"), PyOp(LSTM)::setstate, METH_VARARGS, "LSTM setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_LSTM(py::module m) { + using py_op = PyOp(LSTM); + auto& py_type = PyOpType(LSTM); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.LSTM"; + py_type.tp_basicsize = sizeof(PyOp(LSTM)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "LSTM"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_LSTM_FwdMode(py_type); + + PyType_Modified(&py_type); + m.add_object("LSTM", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTM::typeinfo(), &py_type).second); +} + +PyOpDefBegin(LSTMCell) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(LSTMCell) + +int PyOp(LSTMCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + + return 0; +} + +PyGetSetDef PyOp(LSTMCell)::py_getsetters[] = { + + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(LSTMCell)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(LSTMCell)::getstate, METH_NOARGS, "LSTMCell getstate"}, + {const_cast("__setstate__"), PyOp(LSTMCell)::setstate, METH_VARARGS, "LSTMCell setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_LSTMCell(py::module m) { + using py_op = PyOp(LSTMCell); + auto& py_type = PyOpType(LSTMCell); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.LSTMCell"; + py_type.tp_basicsize = sizeof(PyOp(LSTMCell)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "LSTMCell"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("LSTMCell", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LSTMCell::typeinfo(), &py_type).second); +} + +PyOpDefBegin(LayerNorm) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"affine", serialization::dump(opdef.affine)}, + {"eps", serialization::dump(opdef.eps)}, + {"normalized_dim", serialization::dump(opdef.normalized_dim)}, + {"normalized_size", serialization::dump(opdef.normalized_size)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("affine"); + if (iter != state.end()) { + opdef.affine = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("eps"); + if (iter != state.end()) { + opdef.eps = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("normalized_dim"); + if (iter != state.end()) { + opdef.normalized_dim = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("normalized_size"); + if (iter != state.end()) { + opdef.normalized_size = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(LayerNorm) + +int PyOp(LayerNorm)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"affine", "eps", "normalized_dim", "normalized_size", "scope", NULL}; + PyObject *affine = NULL, *eps = NULL, *normalized_dim = NULL, *normalized_size = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast(kwlist), &affine, &eps, &normalized_dim, &normalized_size, &scope)) + return -1; + + if (affine) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().affine = + py::cast(py::handle(affine)); + } CATCH_ALL(-1) + } + + if (eps) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().eps = + py::cast(py::handle(eps)); + } CATCH_ALL(-1) + } + + if (normalized_dim) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().normalized_dim = + py::cast(py::handle(normalized_dim)); + } CATCH_ALL(-1) + } + + if (normalized_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().normalized_size = + py::cast(py::handle(normalized_size)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(LayerNorm)::py_getsetters[] = { + {const_cast("affine"), py_get_generic(LayerNorm, affine), py_set_generic(LayerNorm, affine), const_cast("affine"), NULL}, + {const_cast("eps"), py_get_generic(LayerNorm, eps), py_set_generic(LayerNorm, eps), const_cast("eps"), NULL}, + {const_cast("normalized_dim"), py_get_generic(LayerNorm, normalized_dim), py_set_generic(LayerNorm, normalized_dim), const_cast("normalized_dim"), NULL}, + {const_cast("normalized_size"), py_get_generic(LayerNorm, normalized_size), py_set_generic(LayerNorm, normalized_size), const_cast("normalized_size"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(LayerNorm)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(LayerNorm)::getstate, METH_NOARGS, "LayerNorm getstate"}, + {const_cast("__setstate__"), PyOp(LayerNorm)::setstate, METH_VARARGS, "LayerNorm setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_LayerNorm(py::module m) { + using py_op = PyOp(LayerNorm); + auto& py_type = PyOpType(LayerNorm); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.LayerNorm"; + py_type.tp_basicsize = sizeof(PyOp(LayerNorm)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "LayerNorm"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("LayerNorm", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(LayerNorm::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Linspace) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"endpoint", serialization::dump(opdef.endpoint)}, + {"comp_node", serialization::dump(opdef.comp_node)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("endpoint"); + if (iter != state.end()) { + opdef.endpoint = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("comp_node"); + if (iter != state.end()) { + opdef.comp_node = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Linspace) + +int PyOp(Linspace)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"endpoint", "comp_node", "scope", NULL}; + PyObject *endpoint = NULL, *comp_node = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &endpoint, &comp_node, &scope)) + return -1; + + if (endpoint) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().endpoint = + py::cast(py::handle(endpoint)); + } CATCH_ALL(-1) + } + + if (comp_node) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().comp_node = + py::cast(py::handle(comp_node)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Linspace)::py_getsetters[] = { + {const_cast("endpoint"), py_get_generic(Linspace, endpoint), py_set_generic(Linspace, endpoint), const_cast("endpoint"), NULL}, + {const_cast("comp_node"), py_get_generic(Linspace, comp_node), py_set_generic(Linspace, comp_node), const_cast("comp_node"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Linspace)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Linspace)::getstate, METH_NOARGS, "Linspace getstate"}, + {const_cast("__setstate__"), PyOp(Linspace)::setstate, METH_VARARGS, "Linspace setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Linspace(py::module m) { + using py_op = PyOp(Linspace); + auto& py_type = PyOpType(Linspace); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Linspace"; + py_type.tp_basicsize = sizeof(PyOp(Linspace)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Linspace"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Linspace", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Linspace::typeinfo(), &py_type).second); +} + +PyOpDefBegin(MagicMindRuntime) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"buf", serialization::dump(opdef.buf)}, + {"buf_size", serialization::dump(opdef.buf_size)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("buf"); + if (iter != state.end()) { + opdef.buf = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("buf_size"); + if (iter != state.end()) { + opdef.buf_size = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(MagicMindRuntime) + +int PyOp(MagicMindRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"buf", "buf_size", "scope", NULL}; + PyObject *buf = NULL, *buf_size = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &buf, &buf_size, &scope)) + return -1; + + if (buf) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf = + py::cast(py::handle(buf)); + } CATCH_ALL(-1) + } + + if (buf_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf_size = + py::cast(py::handle(buf_size)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(MagicMindRuntime)::py_getsetters[] = { + {const_cast("buf"), py_get_generic(MagicMindRuntime, buf), py_set_generic(MagicMindRuntime, buf), const_cast("buf"), NULL}, + {const_cast("buf_size"), py_get_generic(MagicMindRuntime, buf_size), py_set_generic(MagicMindRuntime, buf_size), const_cast("buf_size"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(MagicMindRuntime)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(MagicMindRuntime)::getstate, METH_NOARGS, "MagicMindRuntime getstate"}, + {const_cast("__setstate__"), PyOp(MagicMindRuntime)::setstate, METH_VARARGS, "MagicMindRuntime setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_MagicMindRuntime(py::module m) { + using py_op = PyOp(MagicMindRuntime); + auto& py_type = PyOpType(MagicMindRuntime); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.MagicMindRuntime"; + py_type.tp_basicsize = sizeof(PyOp(MagicMindRuntime)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "MagicMindRuntime"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("MagicMindRuntime", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MagicMindRuntime::typeinfo(), &py_type).second); +} + +PyOpDefBegin(MatrixInverse) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(MatrixInverse) + +int PyOp(MatrixInverse)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + + return 0; +} + +PyGetSetDef PyOp(MatrixInverse)::py_getsetters[] = { + + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(MatrixInverse)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(MatrixInverse)::getstate, METH_NOARGS, "MatrixInverse getstate"}, + {const_cast("__setstate__"), PyOp(MatrixInverse)::setstate, METH_VARARGS, "MatrixInverse setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_MatrixInverse(py::module m) { + using py_op = PyOp(MatrixInverse); + auto& py_type = PyOpType(MatrixInverse); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixInverse"; + py_type.tp_basicsize = sizeof(PyOp(MatrixInverse)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "MatrixInverse"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("MatrixInverse", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixInverse::typeinfo(), &py_type).second); +} + +void _init_py_MatrixMul_ComputeMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "ComputeMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_MatrixMul_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_MatrixMul_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(MatrixMul) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"transposeA", serialization::dump(opdef.transposeA)}, + {"transposeB", serialization::dump(opdef.transposeB)}, + {"compute_mode", serialization::dump(opdef.compute_mode)}, + {"format", serialization::dump(opdef.format)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)}, + {"dimA", serialization::dump(opdef.dimA)}, + {"dimB", serialization::dump(opdef.dimB)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("transposeA"); + if (iter != state.end()) { + opdef.transposeA = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("transposeB"); + if (iter != state.end()) { + opdef.transposeB = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_mode"); + if (iter != state.end()) { + opdef.compute_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dimA"); + if (iter != state.end()) { + opdef.dimA = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dimB"); + if (iter != state.end()) { + opdef.dimB = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(MatrixMul) + +int PyOp(MatrixMul)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"transposeA", "transposeB", "compute_mode", "format", "strategy", "workspace_limit", "dimA", "dimB", "scope", NULL}; + PyObject *transposeA = NULL, *transposeB = NULL, *compute_mode = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *dimA = NULL, *dimB = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast(kwlist), &transposeA, &transposeB, &compute_mode, &format, &strategy, &workspace_limit, &dimA, &dimB, &scope)) + return -1; + + if (transposeA) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().transposeA = + py::cast(py::handle(transposeA)); + } CATCH_ALL(-1) + } + + if (transposeB) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().transposeB = + py::cast(py::handle(transposeB)); + } CATCH_ALL(-1) + } + + if (compute_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_mode = + py::cast(py::handle(compute_mode)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (dimA) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dimA = + py::cast(py::handle(dimA)); + } CATCH_ALL(-1) + } + + if (dimB) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dimB = + py::cast(py::handle(dimB)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(MatrixMul)::py_getsetters[] = { + {const_cast("transposeA"), py_get_generic(MatrixMul, transposeA), py_set_generic(MatrixMul, transposeA), const_cast("transposeA"), NULL}, + {const_cast("transposeB"), py_get_generic(MatrixMul, transposeB), py_set_generic(MatrixMul, transposeB), const_cast("transposeB"), NULL}, + {const_cast("compute_mode"), py_get_generic(MatrixMul, compute_mode), py_set_generic(MatrixMul, compute_mode), const_cast("compute_mode"), NULL}, + {const_cast("format"), py_get_generic(MatrixMul, format), py_set_generic(MatrixMul, format), const_cast("format"), NULL}, + {const_cast("strategy"), py_get_generic(MatrixMul, strategy), py_set_generic(MatrixMul, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(MatrixMul, workspace_limit), py_set_generic(MatrixMul, workspace_limit), const_cast("workspace_limit"), NULL}, + {const_cast("dimA"), py_get_generic(MatrixMul, dimA), py_set_generic(MatrixMul, dimA), const_cast("dimA"), NULL}, + {const_cast("dimB"), py_get_generic(MatrixMul, dimB), py_set_generic(MatrixMul, dimB), const_cast("dimB"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(MatrixMul)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(MatrixMul)::getstate, METH_NOARGS, "MatrixMul getstate"}, + {const_cast("__setstate__"), PyOp(MatrixMul)::setstate, METH_VARARGS, "MatrixMul setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_MatrixMul(py::module m) { + using py_op = PyOp(MatrixMul); + auto& py_type = PyOpType(MatrixMul); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.MatrixMul"; + py_type.tp_basicsize = sizeof(PyOp(MatrixMul)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "MatrixMul"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_MatrixMul_ComputeMode(py_type); + _init_py_MatrixMul_Format(py_type); + _init_py_MatrixMul_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("MatrixMul", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MatrixMul::typeinfo(), &py_type).second); +} + +PyOpDefBegin(MeshIndexing) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(MeshIndexing) + +int PyOp(MeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(MeshIndexing)::py_getsetters[] = { + {const_cast("items"), py_get_generic(MeshIndexing, items), py_set_generic(MeshIndexing, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(MeshIndexing)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(MeshIndexing)::getstate, METH_NOARGS, "MeshIndexing getstate"}, + {const_cast("__setstate__"), PyOp(MeshIndexing)::setstate, METH_VARARGS, "MeshIndexing setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_MeshIndexing(py::module m) { + using py_op = PyOp(MeshIndexing); + auto& py_type = PyOpType(MeshIndexing); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.MeshIndexing"; + py_type.tp_basicsize = sizeof(PyOp(MeshIndexing)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "MeshIndexing"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("MeshIndexing", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(MeshIndexing::typeinfo(), &py_type).second); +} + +PyOpDefBegin(NMSKeep) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"iou_thresh", serialization::dump(opdef.iou_thresh)}, + {"max_output", serialization::dump(opdef.max_output)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("iou_thresh"); + if (iter != state.end()) { + opdef.iou_thresh = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("max_output"); + if (iter != state.end()) { + opdef.max_output = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(NMSKeep) + +int PyOp(NMSKeep)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"iou_thresh", "max_output", "scope", NULL}; + PyObject *iou_thresh = NULL, *max_output = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &iou_thresh, &max_output, &scope)) + return -1; + + if (iou_thresh) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().iou_thresh = + py::cast(py::handle(iou_thresh)); + } CATCH_ALL(-1) + } + + if (max_output) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().max_output = + py::cast(py::handle(max_output)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(NMSKeep)::py_getsetters[] = { + {const_cast("iou_thresh"), py_get_generic(NMSKeep, iou_thresh), py_set_generic(NMSKeep, iou_thresh), const_cast("iou_thresh"), NULL}, + {const_cast("max_output"), py_get_generic(NMSKeep, max_output), py_set_generic(NMSKeep, max_output), const_cast("max_output"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(NMSKeep)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(NMSKeep)::getstate, METH_NOARGS, "NMSKeep getstate"}, + {const_cast("__setstate__"), PyOp(NMSKeep)::setstate, METH_VARARGS, "NMSKeep setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_NMSKeep(py::module m) { + using py_op = PyOp(NMSKeep); + auto& py_type = PyOpType(NMSKeep); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.NMSKeep"; + py_type.tp_basicsize = sizeof(PyOp(NMSKeep)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "NMSKeep"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("NMSKeep", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NMSKeep::typeinfo(), &py_type).second); +} + +PyOpDefBegin(NvOf) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"precision", serialization::dump(opdef.precision)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("precision"); + if (iter != state.end()) { + opdef.precision = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(NvOf) + +int PyOp(NvOf)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"precision", "scope", NULL}; + PyObject *precision = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &precision, &scope)) + return -1; + + if (precision) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().precision = + py::cast(py::handle(precision)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(NvOf)::py_getsetters[] = { + {const_cast("precision"), py_get_generic(NvOf, precision), py_set_generic(NvOf, precision), const_cast("precision"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(NvOf)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(NvOf)::getstate, METH_NOARGS, "NvOf getstate"}, + {const_cast("__setstate__"), PyOp(NvOf)::setstate, METH_VARARGS, "NvOf setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_NvOf(py::module m) { + using py_op = PyOp(NvOf); + auto& py_type = PyOpType(NvOf); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.NvOf"; + py_type.tp_basicsize = sizeof(PyOp(NvOf)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "NvOf"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("NvOf", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(NvOf::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Padding.PaddingMode"; + static constexpr std::underlying_type_t max = 3 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"REPLICATE", "REFLECT", "CONSTANT"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("REPLICATE"), Padding::PaddingMode::REPLICATE}, {normalize_enum("REFLECT"), Padding::PaddingMode::REFLECT}, {normalize_enum("CONSTANT"), Padding::PaddingMode::CONSTANT}}; +template<> PyObject* EnumWrapper::pyobj_insts[3] = {nullptr}; + +void _init_py_Padding_PaddingMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Padding.PaddingMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("PaddingMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Padding.PaddingMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Padding::PaddingMode::REPLICATE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Padding::PaddingMode::REFLECT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Padding::PaddingMode::CONSTANT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "PaddingMode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Padding) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"front_offset_dim0", serialization::dump(opdef.front_offset_dim0)}, + {"front_offset_dim1", serialization::dump(opdef.front_offset_dim1)}, + {"front_offset_dim2", serialization::dump(opdef.front_offset_dim2)}, + {"front_offset_dim3", serialization::dump(opdef.front_offset_dim3)}, + {"front_offset_dim4", serialization::dump(opdef.front_offset_dim4)}, + {"front_offset_dim5", serialization::dump(opdef.front_offset_dim5)}, + {"front_offset_dim6", serialization::dump(opdef.front_offset_dim6)}, + {"back_offset_dim0", serialization::dump(opdef.back_offset_dim0)}, + {"back_offset_dim1", serialization::dump(opdef.back_offset_dim1)}, + {"back_offset_dim2", serialization::dump(opdef.back_offset_dim2)}, + {"back_offset_dim3", serialization::dump(opdef.back_offset_dim3)}, + {"back_offset_dim4", serialization::dump(opdef.back_offset_dim4)}, + {"back_offset_dim5", serialization::dump(opdef.back_offset_dim5)}, + {"back_offset_dim6", serialization::dump(opdef.back_offset_dim6)}, + {"padding_val", serialization::dump(opdef.padding_val)}, + {"padding_mode", serialization::dump(opdef.padding_mode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("front_offset_dim0"); + if (iter != state.end()) { + opdef.front_offset_dim0 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("front_offset_dim1"); + if (iter != state.end()) { + opdef.front_offset_dim1 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("front_offset_dim2"); + if (iter != state.end()) { + opdef.front_offset_dim2 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("front_offset_dim3"); + if (iter != state.end()) { + opdef.front_offset_dim3 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("front_offset_dim4"); + if (iter != state.end()) { + opdef.front_offset_dim4 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("front_offset_dim5"); + if (iter != state.end()) { + opdef.front_offset_dim5 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("front_offset_dim6"); + if (iter != state.end()) { + opdef.front_offset_dim6 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("back_offset_dim0"); + if (iter != state.end()) { + opdef.back_offset_dim0 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("back_offset_dim1"); + if (iter != state.end()) { + opdef.back_offset_dim1 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("back_offset_dim2"); + if (iter != state.end()) { + opdef.back_offset_dim2 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("back_offset_dim3"); + if (iter != state.end()) { + opdef.back_offset_dim3 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("back_offset_dim4"); + if (iter != state.end()) { + opdef.back_offset_dim4 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("back_offset_dim5"); + if (iter != state.end()) { + opdef.back_offset_dim5 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("back_offset_dim6"); + if (iter != state.end()) { + opdef.back_offset_dim6 = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("padding_val"); + if (iter != state.end()) { + opdef.padding_val = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("padding_mode"); + if (iter != state.end()) { + opdef.padding_mode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Padding) + +int PyOp(Padding)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"front_offset_dim0", "front_offset_dim1", "front_offset_dim2", "front_offset_dim3", "front_offset_dim4", "front_offset_dim5", "front_offset_dim6", "back_offset_dim0", "back_offset_dim1", "back_offset_dim2", "back_offset_dim3", "back_offset_dim4", "back_offset_dim5", "back_offset_dim6", "padding_val", "padding_mode", "scope", NULL}; + PyObject *front_offset_dim0 = NULL, *front_offset_dim1 = NULL, *front_offset_dim2 = NULL, *front_offset_dim3 = NULL, *front_offset_dim4 = NULL, *front_offset_dim5 = NULL, *front_offset_dim6 = NULL, *back_offset_dim0 = NULL, *back_offset_dim1 = NULL, *back_offset_dim2 = NULL, *back_offset_dim3 = NULL, *back_offset_dim4 = NULL, *back_offset_dim5 = NULL, *back_offset_dim6 = NULL, *padding_val = NULL, *padding_mode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOOOOOOOO", const_cast(kwlist), &front_offset_dim0, &front_offset_dim1, &front_offset_dim2, &front_offset_dim3, &front_offset_dim4, &front_offset_dim5, &front_offset_dim6, &back_offset_dim0, &back_offset_dim1, &back_offset_dim2, &back_offset_dim3, &back_offset_dim4, &back_offset_dim5, &back_offset_dim6, &padding_val, &padding_mode, &scope)) + return -1; + + if (front_offset_dim0) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().front_offset_dim0 = + py::cast(py::handle(front_offset_dim0)); + } CATCH_ALL(-1) + } + + if (front_offset_dim1) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().front_offset_dim1 = + py::cast(py::handle(front_offset_dim1)); + } CATCH_ALL(-1) + } + + if (front_offset_dim2) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().front_offset_dim2 = + py::cast(py::handle(front_offset_dim2)); + } CATCH_ALL(-1) + } + + if (front_offset_dim3) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().front_offset_dim3 = + py::cast(py::handle(front_offset_dim3)); + } CATCH_ALL(-1) + } + + if (front_offset_dim4) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().front_offset_dim4 = + py::cast(py::handle(front_offset_dim4)); + } CATCH_ALL(-1) + } + + if (front_offset_dim5) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().front_offset_dim5 = + py::cast(py::handle(front_offset_dim5)); + } CATCH_ALL(-1) + } + + if (front_offset_dim6) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().front_offset_dim6 = + py::cast(py::handle(front_offset_dim6)); + } CATCH_ALL(-1) + } + + if (back_offset_dim0) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().back_offset_dim0 = + py::cast(py::handle(back_offset_dim0)); + } CATCH_ALL(-1) + } + + if (back_offset_dim1) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().back_offset_dim1 = + py::cast(py::handle(back_offset_dim1)); + } CATCH_ALL(-1) + } + + if (back_offset_dim2) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().back_offset_dim2 = + py::cast(py::handle(back_offset_dim2)); + } CATCH_ALL(-1) + } + + if (back_offset_dim3) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().back_offset_dim3 = + py::cast(py::handle(back_offset_dim3)); + } CATCH_ALL(-1) + } + + if (back_offset_dim4) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().back_offset_dim4 = + py::cast(py::handle(back_offset_dim4)); + } CATCH_ALL(-1) + } + + if (back_offset_dim5) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().back_offset_dim5 = + py::cast(py::handle(back_offset_dim5)); + } CATCH_ALL(-1) + } + + if (back_offset_dim6) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().back_offset_dim6 = + py::cast(py::handle(back_offset_dim6)); + } CATCH_ALL(-1) + } + + if (padding_val) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().padding_val = + py::cast(py::handle(padding_val)); + } CATCH_ALL(-1) + } + + if (padding_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().padding_mode = + py::cast(py::handle(padding_mode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Padding)::py_getsetters[] = { + {const_cast("front_offset_dim0"), py_get_generic(Padding, front_offset_dim0), py_set_generic(Padding, front_offset_dim0), const_cast("front_offset_dim0"), NULL}, + {const_cast("front_offset_dim1"), py_get_generic(Padding, front_offset_dim1), py_set_generic(Padding, front_offset_dim1), const_cast("front_offset_dim1"), NULL}, + {const_cast("front_offset_dim2"), py_get_generic(Padding, front_offset_dim2), py_set_generic(Padding, front_offset_dim2), const_cast("front_offset_dim2"), NULL}, + {const_cast("front_offset_dim3"), py_get_generic(Padding, front_offset_dim3), py_set_generic(Padding, front_offset_dim3), const_cast("front_offset_dim3"), NULL}, + {const_cast("front_offset_dim4"), py_get_generic(Padding, front_offset_dim4), py_set_generic(Padding, front_offset_dim4), const_cast("front_offset_dim4"), NULL}, + {const_cast("front_offset_dim5"), py_get_generic(Padding, front_offset_dim5), py_set_generic(Padding, front_offset_dim5), const_cast("front_offset_dim5"), NULL}, + {const_cast("front_offset_dim6"), py_get_generic(Padding, front_offset_dim6), py_set_generic(Padding, front_offset_dim6), const_cast("front_offset_dim6"), NULL}, + {const_cast("back_offset_dim0"), py_get_generic(Padding, back_offset_dim0), py_set_generic(Padding, back_offset_dim0), const_cast("back_offset_dim0"), NULL}, + {const_cast("back_offset_dim1"), py_get_generic(Padding, back_offset_dim1), py_set_generic(Padding, back_offset_dim1), const_cast("back_offset_dim1"), NULL}, + {const_cast("back_offset_dim2"), py_get_generic(Padding, back_offset_dim2), py_set_generic(Padding, back_offset_dim2), const_cast("back_offset_dim2"), NULL}, + {const_cast("back_offset_dim3"), py_get_generic(Padding, back_offset_dim3), py_set_generic(Padding, back_offset_dim3), const_cast("back_offset_dim3"), NULL}, + {const_cast("back_offset_dim4"), py_get_generic(Padding, back_offset_dim4), py_set_generic(Padding, back_offset_dim4), const_cast("back_offset_dim4"), NULL}, + {const_cast("back_offset_dim5"), py_get_generic(Padding, back_offset_dim5), py_set_generic(Padding, back_offset_dim5), const_cast("back_offset_dim5"), NULL}, + {const_cast("back_offset_dim6"), py_get_generic(Padding, back_offset_dim6), py_set_generic(Padding, back_offset_dim6), const_cast("back_offset_dim6"), NULL}, + {const_cast("padding_val"), py_get_generic(Padding, padding_val), py_set_generic(Padding, padding_val), const_cast("padding_val"), NULL}, + {const_cast("padding_mode"), py_get_generic(Padding, padding_mode), py_set_generic(Padding, padding_mode), const_cast("padding_mode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Padding)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Padding)::getstate, METH_NOARGS, "Padding getstate"}, + {const_cast("__setstate__"), PyOp(Padding)::setstate, METH_VARARGS, "Padding setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Padding(py::module m) { + using py_op = PyOp(Padding); + auto& py_type = PyOpType(Padding); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Padding"; + py_type.tp_basicsize = sizeof(PyOp(Padding)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Padding"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Padding_PaddingMode(py_type); + + PyType_Modified(&py_type); + m.add_object("Padding", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Padding::typeinfo(), &py_type).second); +} + +PyOpDefBegin(ParamPackConcat) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"offsets", serialization::dump(opdef.offsets)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("offsets"); + if (iter != state.end()) { + opdef.offsets = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ParamPackConcat) + +int PyOp(ParamPackConcat)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"offsets", "scope", NULL}; + PyObject *offsets = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &offsets, &scope)) + return -1; + + if (offsets) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().offsets = + py::cast(py::handle(offsets)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ParamPackConcat)::py_getsetters[] = { + {const_cast("offsets"), py_get_generic(ParamPackConcat, offsets), py_set_generic(ParamPackConcat, offsets), const_cast("offsets"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ParamPackConcat)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ParamPackConcat)::getstate, METH_NOARGS, "ParamPackConcat getstate"}, + {const_cast("__setstate__"), PyOp(ParamPackConcat)::setstate, METH_VARARGS, "ParamPackConcat setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ParamPackConcat(py::module m) { + using py_op = PyOp(ParamPackConcat); + auto& py_type = PyOpType(ParamPackConcat); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackConcat"; + py_type.tp_basicsize = sizeof(PyOp(ParamPackConcat)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ParamPackConcat"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("ParamPackConcat", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackConcat::typeinfo(), &py_type).second); +} + +PyOpDefBegin(ParamPackSplit) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"offsets", serialization::dump(opdef.offsets)}, + {"shapes", serialization::dump(opdef.shapes)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("offsets"); + if (iter != state.end()) { + opdef.offsets = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("shapes"); + if (iter != state.end()) { + opdef.shapes = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ParamPackSplit) + +int PyOp(ParamPackSplit)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"offsets", "shapes", "scope", NULL}; + PyObject *offsets = NULL, *shapes = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &offsets, &shapes, &scope)) + return -1; + + if (offsets) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().offsets = + py::cast(py::handle(offsets)); + } CATCH_ALL(-1) + } + + if (shapes) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().shapes = + py::cast(py::handle(shapes)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ParamPackSplit)::py_getsetters[] = { + {const_cast("offsets"), py_get_generic(ParamPackSplit, offsets), py_set_generic(ParamPackSplit, offsets), const_cast("offsets"), NULL}, + {const_cast("shapes"), py_get_generic(ParamPackSplit, shapes), py_set_generic(ParamPackSplit, shapes), const_cast("shapes"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ParamPackSplit)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ParamPackSplit)::getstate, METH_NOARGS, "ParamPackSplit getstate"}, + {const_cast("__setstate__"), PyOp(ParamPackSplit)::setstate, METH_VARARGS, "ParamPackSplit setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ParamPackSplit(py::module m) { + using py_op = PyOp(ParamPackSplit); + auto& py_type = PyOpType(ParamPackSplit); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ParamPackSplit"; + py_type.tp_basicsize = sizeof(PyOp(ParamPackSplit)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ParamPackSplit"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("ParamPackSplit", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ParamPackSplit::typeinfo(), &py_type).second); +} + +PyOpDefBegin(PermutationRNG) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"seed", serialization::dump(opdef.seed)}, + {"dtype", serialization::dump(opdef.dtype)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(PermutationRNG) + +int PyOp(PermutationRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL}; + PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast(kwlist), &seed, &dtype, &handle, &scope)) + return -1; + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(PermutationRNG)::py_getsetters[] = { + {const_cast("seed"), py_get_generic(PermutationRNG, seed), py_set_generic(PermutationRNG, seed), const_cast("seed"), NULL}, + {const_cast("dtype"), py_get_generic(PermutationRNG, dtype), py_set_generic(PermutationRNG, dtype), const_cast("dtype"), NULL}, + {const_cast("handle"), py_get_generic(PermutationRNG, handle), py_set_generic(PermutationRNG, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(PermutationRNG)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(PermutationRNG)::getstate, METH_NOARGS, "PermutationRNG getstate"}, + {const_cast("__setstate__"), PyOp(PermutationRNG)::setstate, METH_VARARGS, "PermutationRNG setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_PermutationRNG(py::module m) { + using py_op = PyOp(PermutationRNG); + auto& py_type = PyOpType(PermutationRNG); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.PermutationRNG"; + py_type.tp_basicsize = sizeof(PyOp(PermutationRNG)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "PermutationRNG"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("PermutationRNG", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PermutationRNG::typeinfo(), &py_type).second); +} + +PyOpDefBegin(PixelShuffle) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"factor", serialization::dump(opdef.factor)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("factor"); + if (iter != state.end()) { + opdef.factor = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(PixelShuffle) + +int PyOp(PixelShuffle)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"factor", "scope", NULL}; + PyObject *factor = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &factor, &scope)) + return -1; + + if (factor) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().factor = + py::cast(py::handle(factor)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(PixelShuffle)::py_getsetters[] = { + {const_cast("factor"), py_get_generic(PixelShuffle, factor), py_set_generic(PixelShuffle, factor), const_cast("factor"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(PixelShuffle)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(PixelShuffle)::getstate, METH_NOARGS, "PixelShuffle getstate"}, + {const_cast("__setstate__"), PyOp(PixelShuffle)::setstate, METH_VARARGS, "PixelShuffle setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_PixelShuffle(py::module m) { + using py_op = PyOp(PixelShuffle); + auto& py_type = PyOpType(PixelShuffle); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffle"; + py_type.tp_basicsize = sizeof(PyOp(PixelShuffle)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "PixelShuffle"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("PixelShuffle", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffle::typeinfo(), &py_type).second); +} + +PyOpDefBegin(PixelShuffleBackward) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"factor", serialization::dump(opdef.factor)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("factor"); + if (iter != state.end()) { + opdef.factor = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(PixelShuffleBackward) + +int PyOp(PixelShuffleBackward)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"factor", "scope", NULL}; + PyObject *factor = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &factor, &scope)) + return -1; + + if (factor) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().factor = + py::cast(py::handle(factor)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(PixelShuffleBackward)::py_getsetters[] = { + {const_cast("factor"), py_get_generic(PixelShuffleBackward, factor), py_set_generic(PixelShuffleBackward, factor), const_cast("factor"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(PixelShuffleBackward)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(PixelShuffleBackward)::getstate, METH_NOARGS, "PixelShuffleBackward getstate"}, + {const_cast("__setstate__"), PyOp(PixelShuffleBackward)::setstate, METH_VARARGS, "PixelShuffleBackward setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_PixelShuffleBackward(py::module m) { + using py_op = PyOp(PixelShuffleBackward); + auto& py_type = PyOpType(PixelShuffleBackward); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.PixelShuffleBackward"; + py_type.tp_basicsize = sizeof(PyOp(PixelShuffleBackward)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "PixelShuffleBackward"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("PixelShuffleBackward", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PixelShuffleBackward::typeinfo(), &py_type).second); +} + +PyOpDefBegin(PoissonRNG) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"seed", serialization::dump(opdef.seed)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(PoissonRNG) + +int PyOp(PoissonRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"seed", "handle", "scope", NULL}; + PyObject *seed = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &seed, &handle, &scope)) + return -1; + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(PoissonRNG)::py_getsetters[] = { + {const_cast("seed"), py_get_generic(PoissonRNG, seed), py_set_generic(PoissonRNG, seed), const_cast("seed"), NULL}, + {const_cast("handle"), py_get_generic(PoissonRNG, handle), py_set_generic(PoissonRNG, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(PoissonRNG)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(PoissonRNG)::getstate, METH_NOARGS, "PoissonRNG getstate"}, + {const_cast("__setstate__"), PyOp(PoissonRNG)::setstate, METH_VARARGS, "PoissonRNG setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_PoissonRNG(py::module m) { + using py_op = PyOp(PoissonRNG); + auto& py_type = PyOpType(PoissonRNG); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.PoissonRNG"; + py_type.tp_basicsize = sizeof(PyOp(PoissonRNG)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "PoissonRNG"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("PoissonRNG", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(PoissonRNG::typeinfo(), &py_type).second); +} + +void _init_py_Pooling_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Pooling_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Pooling_Strategy(PyTypeObject& py_type) { + auto& e_type = BitCombinedEnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Strategy", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Pooling) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"window_h", serialization::dump(opdef.window_h)}, + {"window_w", serialization::dump(opdef.window_w)}, + {"format", serialization::dump(opdef.format)}, + {"strategy", serialization::dump(opdef.strategy)}, + {"workspace_limit", serialization::dump(opdef.workspace_limit)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("window_h"); + if (iter != state.end()) { + opdef.window_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("window_w"); + if (iter != state.end()) { + opdef.window_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("strategy"); + if (iter != state.end()) { + opdef.strategy = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("workspace_limit"); + if (iter != state.end()) { + opdef.workspace_limit = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Pooling) + +int PyOp(Pooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "pad_h", "pad_w", "stride_h", "stride_w", "window_h", "window_w", "format", "strategy", "workspace_limit", "scope", NULL}; + PyObject *mode = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *window_h = NULL, *window_w = NULL, *format = NULL, *strategy = NULL, *workspace_limit = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast(kwlist), &mode, &pad_h, &pad_w, &stride_h, &stride_w, &window_h, &window_w, &format, &strategy, &workspace_limit, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (window_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().window_h = + py::cast(py::handle(window_h)); + } CATCH_ALL(-1) + } + + if (window_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().window_w = + py::cast(py::handle(window_w)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (strategy) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().strategy = + py::cast(py::handle(strategy)); + } CATCH_ALL(-1) + } + + if (workspace_limit) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().workspace_limit = + py::cast(py::handle(workspace_limit)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Pooling)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(Pooling, mode), py_set_generic(Pooling, mode), const_cast("mode"), NULL}, + {const_cast("pad_h"), py_get_generic(Pooling, pad_h), py_set_generic(Pooling, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(Pooling, pad_w), py_set_generic(Pooling, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(Pooling, stride_h), py_set_generic(Pooling, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(Pooling, stride_w), py_set_generic(Pooling, stride_w), const_cast("stride_w"), NULL}, + {const_cast("window_h"), py_get_generic(Pooling, window_h), py_set_generic(Pooling, window_h), const_cast("window_h"), NULL}, + {const_cast("window_w"), py_get_generic(Pooling, window_w), py_set_generic(Pooling, window_w), const_cast("window_w"), NULL}, + {const_cast("format"), py_get_generic(Pooling, format), py_set_generic(Pooling, format), const_cast("format"), NULL}, + {const_cast("strategy"), py_get_generic(Pooling, strategy), py_set_generic(Pooling, strategy), const_cast("strategy"), NULL}, + {const_cast("workspace_limit"), py_get_generic(Pooling, workspace_limit), py_set_generic(Pooling, workspace_limit), const_cast("workspace_limit"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Pooling)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Pooling)::getstate, METH_NOARGS, "Pooling getstate"}, + {const_cast("__setstate__"), PyOp(Pooling)::setstate, METH_VARARGS, "Pooling setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Pooling(py::module m) { + using py_op = PyOp(Pooling); + auto& py_type = PyOpType(Pooling); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Pooling"; + py_type.tp_basicsize = sizeof(PyOp(Pooling)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Pooling"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Pooling_Mode(py_type); + _init_py_Pooling_Format(py_type); + _init_py_Pooling_Strategy(py_type); + + PyType_Modified(&py_type); + m.add_object("Pooling", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Pooling::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "RNN.NonlineMode"; + static constexpr std::underlying_type_t max = 3 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"IDENTITY", "RELU", "TANH"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("IDENTITY"), RNN::NonlineMode::IDENTITY}, {normalize_enum("RELU"), RNN::NonlineMode::RELU}, {normalize_enum("TANH"), RNN::NonlineMode::TANH}}; +template<> PyObject* EnumWrapper::pyobj_insts[3] = {nullptr}; + +void _init_py_RNN_NonlineMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.RNN.NonlineMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("NonlineMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("RNN.NonlineMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = RNN::NonlineMode::IDENTITY; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "IDENTITY", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = RNN::NonlineMode::RELU; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "RELU", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = RNN::NonlineMode::TANH; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TANH", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "NonlineMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_RNN_FwdMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "FwdMode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(RNN) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"num_layers", serialization::dump(opdef.num_layers)}, + {"bidirectional", serialization::dump(opdef.bidirectional)}, + {"bias", serialization::dump(opdef.bias)}, + {"hidden_size", serialization::dump(opdef.hidden_size)}, + {"dropout", serialization::dump(opdef.dropout)}, + {"nonlineMode", serialization::dump(opdef.nonlineMode)}, + {"fwd_mode", serialization::dump(opdef.fwd_mode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("num_layers"); + if (iter != state.end()) { + opdef.num_layers = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bidirectional"); + if (iter != state.end()) { + opdef.bidirectional = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bias"); + if (iter != state.end()) { + opdef.bias = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("hidden_size"); + if (iter != state.end()) { + opdef.hidden_size = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dropout"); + if (iter != state.end()) { + opdef.dropout = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("nonlineMode"); + if (iter != state.end()) { + opdef.nonlineMode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("fwd_mode"); + if (iter != state.end()) { + opdef.fwd_mode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(RNN) + +int PyOp(RNN)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"num_layers", "bidirectional", "bias", "hidden_size", "dropout", "nonlineMode", "fwd_mode", "scope", NULL}; + PyObject *num_layers = NULL, *bidirectional = NULL, *bias = NULL, *hidden_size = NULL, *dropout = NULL, *nonlineMode = NULL, *fwd_mode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOO", const_cast(kwlist), &num_layers, &bidirectional, &bias, &hidden_size, &dropout, &nonlineMode, &fwd_mode, &scope)) + return -1; + + if (num_layers) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().num_layers = + py::cast(py::handle(num_layers)); + } CATCH_ALL(-1) + } + + if (bidirectional) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bidirectional = + py::cast(py::handle(bidirectional)); + } CATCH_ALL(-1) + } + + if (bias) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bias = + py::cast(py::handle(bias)); + } CATCH_ALL(-1) + } + + if (hidden_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().hidden_size = + py::cast(py::handle(hidden_size)); + } CATCH_ALL(-1) + } + + if (dropout) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dropout = + py::cast(py::handle(dropout)); + } CATCH_ALL(-1) + } + + if (nonlineMode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().nonlineMode = + py::cast(py::handle(nonlineMode)); + } CATCH_ALL(-1) + } + + if (fwd_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().fwd_mode = + py::cast(py::handle(fwd_mode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(RNN)::py_getsetters[] = { + {const_cast("num_layers"), py_get_generic(RNN, num_layers), py_set_generic(RNN, num_layers), const_cast("num_layers"), NULL}, + {const_cast("bidirectional"), py_get_generic(RNN, bidirectional), py_set_generic(RNN, bidirectional), const_cast("bidirectional"), NULL}, + {const_cast("bias"), py_get_generic(RNN, bias), py_set_generic(RNN, bias), const_cast("bias"), NULL}, + {const_cast("hidden_size"), py_get_generic(RNN, hidden_size), py_set_generic(RNN, hidden_size), const_cast("hidden_size"), NULL}, + {const_cast("dropout"), py_get_generic(RNN, dropout), py_set_generic(RNN, dropout), const_cast("dropout"), NULL}, + {const_cast("nonlineMode"), py_get_generic(RNN, nonlineMode), py_set_generic(RNN, nonlineMode), const_cast("nonlineMode"), NULL}, + {const_cast("fwd_mode"), py_get_generic(RNN, fwd_mode), py_set_generic(RNN, fwd_mode), const_cast("fwd_mode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(RNN)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(RNN)::getstate, METH_NOARGS, "RNN getstate"}, + {const_cast("__setstate__"), PyOp(RNN)::setstate, METH_VARARGS, "RNN setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_RNN(py::module m) { + using py_op = PyOp(RNN); + auto& py_type = PyOpType(RNN); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.RNN"; + py_type.tp_basicsize = sizeof(PyOp(RNN)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "RNN"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_RNN_NonlineMode(py_type); + _init_py_RNN_FwdMode(py_type); + + PyType_Modified(&py_type); + m.add_object("RNN", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNN::typeinfo(), &py_type).second); +} + +void _init_py_RNNCell_NonlineMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "NonlineMode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(RNNCell) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"nonlineMode", serialization::dump(opdef.nonlineMode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("nonlineMode"); + if (iter != state.end()) { + opdef.nonlineMode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(RNNCell) + +int PyOp(RNNCell)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"nonlineMode", "scope", NULL}; + PyObject *nonlineMode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &nonlineMode, &scope)) + return -1; + + if (nonlineMode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().nonlineMode = + py::cast(py::handle(nonlineMode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(RNNCell)::py_getsetters[] = { + {const_cast("nonlineMode"), py_get_generic(RNNCell, nonlineMode), py_set_generic(RNNCell, nonlineMode), const_cast("nonlineMode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(RNNCell)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(RNNCell)::getstate, METH_NOARGS, "RNNCell getstate"}, + {const_cast("__setstate__"), PyOp(RNNCell)::setstate, METH_VARARGS, "RNNCell setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_RNNCell(py::module m) { + using py_op = PyOp(RNNCell); + auto& py_type = PyOpType(RNNCell); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.RNNCell"; + py_type.tp_basicsize = sizeof(PyOp(RNNCell)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "RNNCell"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_RNNCell_NonlineMode(py_type); + + PyType_Modified(&py_type); + m.add_object("RNNCell", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RNNCell::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "ROIAlign.Mode"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"MAX", "AVERAGE"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("MAX"), ROIAlign::Mode::MAX}, {normalize_enum("AVERAGE"), ROIAlign::Mode::AVERAGE}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_ROIAlign_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.ROIAlign.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("ROIAlign.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ROIAlign::Mode::MAX; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ROIAlign::Mode::AVERAGE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_ROIAlign_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(ROIAlign) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"format", serialization::dump(opdef.format)}, + {"spatial_scale", serialization::dump(opdef.spatial_scale)}, + {"offset", serialization::dump(opdef.offset)}, + {"pooled_height", serialization::dump(opdef.pooled_height)}, + {"pooled_width", serialization::dump(opdef.pooled_width)}, + {"sample_height", serialization::dump(opdef.sample_height)}, + {"sample_width", serialization::dump(opdef.sample_width)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("spatial_scale"); + if (iter != state.end()) { + opdef.spatial_scale = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("offset"); + if (iter != state.end()) { + opdef.offset = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pooled_height"); + if (iter != state.end()) { + opdef.pooled_height = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pooled_width"); + if (iter != state.end()) { + opdef.pooled_width = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sample_height"); + if (iter != state.end()) { + opdef.sample_height = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("sample_width"); + if (iter != state.end()) { + opdef.sample_width = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ROIAlign) + +int PyOp(ROIAlign)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "format", "spatial_scale", "offset", "pooled_height", "pooled_width", "sample_height", "sample_width", "scope", NULL}; + PyObject *mode = NULL, *format = NULL, *spatial_scale = NULL, *offset = NULL, *pooled_height = NULL, *pooled_width = NULL, *sample_height = NULL, *sample_width = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast(kwlist), &mode, &format, &spatial_scale, &offset, &pooled_height, &pooled_width, &sample_height, &sample_width, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (spatial_scale) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().spatial_scale = + py::cast(py::handle(spatial_scale)); + } CATCH_ALL(-1) + } + + if (offset) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().offset = + py::cast(py::handle(offset)); + } CATCH_ALL(-1) + } + + if (pooled_height) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pooled_height = + py::cast(py::handle(pooled_height)); + } CATCH_ALL(-1) + } + + if (pooled_width) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pooled_width = + py::cast(py::handle(pooled_width)); + } CATCH_ALL(-1) + } + + if (sample_height) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sample_height = + py::cast(py::handle(sample_height)); + } CATCH_ALL(-1) + } + + if (sample_width) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().sample_width = + py::cast(py::handle(sample_width)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ROIAlign)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(ROIAlign, mode), py_set_generic(ROIAlign, mode), const_cast("mode"), NULL}, + {const_cast("format"), py_get_generic(ROIAlign, format), py_set_generic(ROIAlign, format), const_cast("format"), NULL}, + {const_cast("spatial_scale"), py_get_generic(ROIAlign, spatial_scale), py_set_generic(ROIAlign, spatial_scale), const_cast("spatial_scale"), NULL}, + {const_cast("offset"), py_get_generic(ROIAlign, offset), py_set_generic(ROIAlign, offset), const_cast("offset"), NULL}, + {const_cast("pooled_height"), py_get_generic(ROIAlign, pooled_height), py_set_generic(ROIAlign, pooled_height), const_cast("pooled_height"), NULL}, + {const_cast("pooled_width"), py_get_generic(ROIAlign, pooled_width), py_set_generic(ROIAlign, pooled_width), const_cast("pooled_width"), NULL}, + {const_cast("sample_height"), py_get_generic(ROIAlign, sample_height), py_set_generic(ROIAlign, sample_height), const_cast("sample_height"), NULL}, + {const_cast("sample_width"), py_get_generic(ROIAlign, sample_width), py_set_generic(ROIAlign, sample_width), const_cast("sample_width"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ROIAlign)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ROIAlign)::getstate, METH_NOARGS, "ROIAlign getstate"}, + {const_cast("__setstate__"), PyOp(ROIAlign)::setstate, METH_VARARGS, "ROIAlign setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ROIAlign(py::module m) { + using py_op = PyOp(ROIAlign); + auto& py_type = PyOpType(ROIAlign); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ROIAlign"; + py_type.tp_basicsize = sizeof(PyOp(ROIAlign)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ROIAlign"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_ROIAlign_Mode(py_type); + _init_py_ROIAlign_Format(py_type); + + PyType_Modified(&py_type); + m.add_object("ROIAlign", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIAlign::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "ROIPooling.Mode"; + static constexpr std::underlying_type_t max = 2 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"MAX", "AVERAGE"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("MAX"), ROIPooling::Mode::MAX}, {normalize_enum("AVERAGE"), ROIPooling::Mode::AVERAGE}}; +template<> PyObject* EnumWrapper::pyobj_insts[2] = {nullptr}; + +void _init_py_ROIPooling_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.ROIPooling.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("ROIPooling.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ROIPooling::Mode::MAX; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = ROIPooling::Mode::AVERAGE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AVERAGE", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(ROIPooling) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"scale", serialization::dump(opdef.scale)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("scale"); + if (iter != state.end()) { + opdef.scale = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ROIPooling) + +int PyOp(ROIPooling)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "scale", "scope", NULL}; + PyObject *mode = NULL, *scale = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &mode, &scale, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (scale) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().scale = + py::cast(py::handle(scale)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ROIPooling)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(ROIPooling, mode), py_set_generic(ROIPooling, mode), const_cast("mode"), NULL}, + {const_cast("scale"), py_get_generic(ROIPooling, scale), py_set_generic(ROIPooling, scale), const_cast("scale"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ROIPooling)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ROIPooling)::getstate, METH_NOARGS, "ROIPooling getstate"}, + {const_cast("__setstate__"), PyOp(ROIPooling)::setstate, METH_VARARGS, "ROIPooling setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ROIPooling(py::module m) { + using py_op = PyOp(ROIPooling); + auto& py_type = PyOpType(ROIPooling); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ROIPooling"; + py_type.tp_basicsize = sizeof(PyOp(ROIPooling)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ROIPooling"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_ROIPooling_Mode(py_type); + + PyType_Modified(&py_type); + m.add_object("ROIPooling", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ROIPooling::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Reduce.Mode"; + static constexpr std::underlying_type_t max = 6 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"SUM", "SUM_SQR", "PRODUCT", "MIN", "MAX", "MEAN"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("SUM"), Reduce::Mode::SUM}, {normalize_enum("SUM_SQR"), Reduce::Mode::SUM_SQR}, {normalize_enum("PRODUCT"), Reduce::Mode::PRODUCT}, {normalize_enum("MIN"), Reduce::Mode::MIN}, {normalize_enum("MAX"), Reduce::Mode::MAX}, {normalize_enum("MEAN"), Reduce::Mode::MEAN}}; +template<> PyObject* EnumWrapper::pyobj_insts[6] = {nullptr}; + +void _init_py_Reduce_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Reduce.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Reduce.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::Mode::SUM; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::Mode::SUM_SQR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "SUM_SQR", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::Mode::PRODUCT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "PRODUCT", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::Mode::MIN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MIN", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::Mode::MAX; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MAX", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::Mode::MEAN; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "MEAN", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Reduce.DataType"; + static constexpr std::underlying_type_t max = 6 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"DEFAULT", "FLOAT_IO16xC32", "FLOAT_O32xC32", "FLOAT_O16xC32", "QUINT_I8xO32", "QINT_I8xO32"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("DEFAULT"), Reduce::DataType::DEFAULT}, {normalize_enum("FLOAT_IO16xC32"), Reduce::DataType::FLOAT_IO16xC32}, {normalize_enum("FLOAT_O32xC32"), Reduce::DataType::FLOAT_O32xC32}, {normalize_enum("FLOAT_O16xC32"), Reduce::DataType::FLOAT_O16xC32}, {normalize_enum("QUINT_I8xO32"), Reduce::DataType::QUINT_I8xO32}, {normalize_enum("QINT_I8xO32"), Reduce::DataType::QINT_I8xO32}}; +template<> PyObject* EnumWrapper::pyobj_insts[6] = {nullptr}; + +void _init_py_Reduce_DataType(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Reduce.DataType", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("DataType").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Reduce.DataType").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::DataType::DEFAULT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "DEFAULT", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::DataType::FLOAT_IO16xC32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_IO16xC32", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::DataType::FLOAT_O32xC32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O32xC32", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::DataType::FLOAT_O16xC32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "FLOAT_O16xC32", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::DataType::QUINT_I8xO32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QUINT_I8xO32", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Reduce::DataType::QINT_I8xO32; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "QINT_I8xO32", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "DataType", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Reduce) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)}, + {"axis", serialization::dump(opdef.axis)}, + {"data_type", serialization::dump(opdef.data_type)}, + {"keepdim", serialization::dump(opdef.keepdim)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("data_type"); + if (iter != state.end()) { + opdef.data_type = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("keepdim"); + if (iter != state.end()) { + opdef.keepdim = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Reduce) + +int PyOp(Reduce)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "axis", "data_type", "keepdim", "scope", NULL}; + PyObject *mode = NULL, *axis = NULL, *data_type = NULL, *keepdim = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast(kwlist), &mode, &axis, &data_type, &keepdim, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (data_type) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().data_type = + py::cast(py::handle(data_type)); + } CATCH_ALL(-1) + } + + if (keepdim) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().keepdim = + py::cast(py::handle(keepdim)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Reduce)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(Reduce, mode), py_set_generic(Reduce, mode), const_cast("mode"), NULL}, + {const_cast("axis"), py_get_generic(Reduce, axis), py_set_generic(Reduce, axis), const_cast("axis"), NULL}, + {const_cast("data_type"), py_get_generic(Reduce, data_type), py_set_generic(Reduce, data_type), const_cast("data_type"), NULL}, + {const_cast("keepdim"), py_get_generic(Reduce, keepdim), py_set_generic(Reduce, keepdim), const_cast("keepdim"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Reduce)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Reduce)::getstate, METH_NOARGS, "Reduce getstate"}, + {const_cast("__setstate__"), PyOp(Reduce)::setstate, METH_VARARGS, "Reduce setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Reduce(py::module m) { + using py_op = PyOp(Reduce); + auto& py_type = PyOpType(Reduce); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Reduce"; + py_type.tp_basicsize = sizeof(PyOp(Reduce)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Reduce"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Reduce_Mode(py_type); + _init_py_Reduce_DataType(py_type); + + PyType_Modified(&py_type); + m.add_object("Reduce", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reduce::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Remap.InterpolationMode"; + static constexpr std::underlying_type_t max = 5 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"NEAREST", "LINEAR", "AREA", "CUBIC", "LANCZOS4"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("NEAREST"), Remap::InterpolationMode::NEAREST}, {normalize_enum("LINEAR"), Remap::InterpolationMode::LINEAR}, {normalize_enum("AREA"), Remap::InterpolationMode::AREA}, {normalize_enum("CUBIC"), Remap::InterpolationMode::CUBIC}, {normalize_enum("LANCZOS4"), Remap::InterpolationMode::LANCZOS4}}; +template<> PyObject* EnumWrapper::pyobj_insts[5] = {nullptr}; + +void _init_py_Remap_InterpolationMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Remap.InterpolationMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("InterpolationMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Remap.InterpolationMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::InterpolationMode::NEAREST; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "NEAREST", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::InterpolationMode::LINEAR; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LINEAR", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::InterpolationMode::AREA; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "AREA", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::InterpolationMode::CUBIC; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CUBIC", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::InterpolationMode::LANCZOS4; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "LANCZOS4", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "InterpolationMode", reinterpret_cast(e_type)) >= 0); +} + +template<> struct EnumTrait { + static constexpr const char *name = "Remap.BorderMode"; + static constexpr std::underlying_type_t max = 7 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"REPLICATE", "REFLECT", "REFLECT_101", "WRAP", "CONSTANT", "TRANSPARENT", "ISOLATED"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("REPLICATE"), Remap::BorderMode::REPLICATE}, {normalize_enum("REFLECT"), Remap::BorderMode::REFLECT}, {normalize_enum("REFLECT_101"), Remap::BorderMode::REFLECT_101}, {normalize_enum("WRAP"), Remap::BorderMode::WRAP}, {normalize_enum("CONSTANT"), Remap::BorderMode::CONSTANT}, {normalize_enum("TRANSPARENT"), Remap::BorderMode::TRANSPARENT}, {normalize_enum("ISOLATED"), Remap::BorderMode::ISOLATED}}; +template<> PyObject* EnumWrapper::pyobj_insts[7] = {nullptr}; + +void _init_py_Remap_BorderMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.Remap.BorderMode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("BorderMode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("Remap.BorderMode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::BorderMode::REPLICATE; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REPLICATE", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::BorderMode::REFLECT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::BorderMode::REFLECT_101; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "REFLECT_101", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::BorderMode::WRAP; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "WRAP", inst) >= 0); + EnumWrapper::pyobj_insts[3] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::BorderMode::CONSTANT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "CONSTANT", inst) >= 0); + EnumWrapper::pyobj_insts[4] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::BorderMode::TRANSPARENT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "TRANSPARENT", inst) >= 0); + EnumWrapper::pyobj_insts[5] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = Remap::BorderMode::ISOLATED; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "ISOLATED", inst) >= 0); + EnumWrapper::pyobj_insts[6] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "BorderMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Remap_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Remap) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"imode", serialization::dump(opdef.imode)}, + {"border_type", serialization::dump(opdef.border_type)}, + {"format", serialization::dump(opdef.format)}, + {"scalar", serialization::dump(opdef.scalar)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("imode"); + if (iter != state.end()) { + opdef.imode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("border_type"); + if (iter != state.end()) { + opdef.border_type = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("scalar"); + if (iter != state.end()) { + opdef.scalar = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Remap) + +int PyOp(Remap)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"imode", "border_type", "format", "scalar", "scope", NULL}; + PyObject *imode = NULL, *border_type = NULL, *format = NULL, *scalar = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast(kwlist), &imode, &border_type, &format, &scalar, &scope)) + return -1; + + if (imode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().imode = + py::cast(py::handle(imode)); + } CATCH_ALL(-1) + } + + if (border_type) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().border_type = + py::cast(py::handle(border_type)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (scalar) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().scalar = + py::cast(py::handle(scalar)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Remap)::py_getsetters[] = { + {const_cast("imode"), py_get_generic(Remap, imode), py_set_generic(Remap, imode), const_cast("imode"), NULL}, + {const_cast("border_type"), py_get_generic(Remap, border_type), py_set_generic(Remap, border_type), const_cast("border_type"), NULL}, + {const_cast("format"), py_get_generic(Remap, format), py_set_generic(Remap, format), const_cast("format"), NULL}, + {const_cast("scalar"), py_get_generic(Remap, scalar), py_set_generic(Remap, scalar), const_cast("scalar"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Remap)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Remap)::getstate, METH_NOARGS, "Remap getstate"}, + {const_cast("__setstate__"), PyOp(Remap)::setstate, METH_VARARGS, "Remap setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Remap(py::module m) { + using py_op = PyOp(Remap); + auto& py_type = PyOpType(Remap); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Remap"; + py_type.tp_basicsize = sizeof(PyOp(Remap)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Remap"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Remap_InterpolationMode(py_type); + _init_py_Remap_BorderMode(py_type); + _init_py_Remap_Format(py_type); + + PyType_Modified(&py_type); + m.add_object("Remap", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Remap::typeinfo(), &py_type).second); +} + +PyOpDefBegin(RemoteRecv) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"key", serialization::dump(opdef.key)}, + {"addr", serialization::dump(opdef.addr)}, + {"port", serialization::dump(opdef.port)}, + {"rank_from", serialization::dump(opdef.rank_from)}, + {"cn", serialization::dump(opdef.cn)}, + {"shape", serialization::dump(opdef.shape)}, + {"dtype", serialization::dump(opdef.dtype)}, + {"backend", serialization::dump(opdef.backend)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("key"); + if (iter != state.end()) { + opdef.key = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("addr"); + if (iter != state.end()) { + opdef.addr = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("port"); + if (iter != state.end()) { + opdef.port = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("rank_from"); + if (iter != state.end()) { + opdef.rank_from = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("cn"); + if (iter != state.end()) { + opdef.cn = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("shape"); + if (iter != state.end()) { + opdef.shape = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("backend"); + if (iter != state.end()) { + opdef.backend = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(RemoteRecv) + +int PyOp(RemoteRecv)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"key", "addr", "port", "rank_from", "cn", "shape", "dtype", "backend", "scope", NULL}; + PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_from = NULL, *cn = NULL, *shape = NULL, *dtype = NULL, *backend = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOO", const_cast(kwlist), &key, &addr, &port, &rank_from, &cn, &shape, &dtype, &backend, &scope)) + return -1; + + if (key) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().key = + py::cast(py::handle(key)); + } CATCH_ALL(-1) + } + + if (addr) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().addr = + py::cast(py::handle(addr)); + } CATCH_ALL(-1) + } + + if (port) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().port = + py::cast(py::handle(port)); + } CATCH_ALL(-1) + } + + if (rank_from) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().rank_from = + py::cast(py::handle(rank_from)); + } CATCH_ALL(-1) + } + + if (cn) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().cn = + py::cast(py::handle(cn)); + } CATCH_ALL(-1) + } + + if (shape) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().shape = + py::cast(py::handle(shape)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (backend) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().backend = + py::cast(py::handle(backend)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(RemoteRecv)::py_getsetters[] = { + {const_cast("key"), py_get_generic(RemoteRecv, key), py_set_generic(RemoteRecv, key), const_cast("key"), NULL}, + {const_cast("addr"), py_get_generic(RemoteRecv, addr), py_set_generic(RemoteRecv, addr), const_cast("addr"), NULL}, + {const_cast("port"), py_get_generic(RemoteRecv, port), py_set_generic(RemoteRecv, port), const_cast("port"), NULL}, + {const_cast("rank_from"), py_get_generic(RemoteRecv, rank_from), py_set_generic(RemoteRecv, rank_from), const_cast("rank_from"), NULL}, + {const_cast("cn"), py_get_generic(RemoteRecv, cn), py_set_generic(RemoteRecv, cn), const_cast("cn"), NULL}, + {const_cast("shape"), py_get_generic(RemoteRecv, shape), py_set_generic(RemoteRecv, shape), const_cast("shape"), NULL}, + {const_cast("dtype"), py_get_generic(RemoteRecv, dtype), py_set_generic(RemoteRecv, dtype), const_cast("dtype"), NULL}, + {const_cast("backend"), py_get_generic(RemoteRecv, backend), py_set_generic(RemoteRecv, backend), const_cast("backend"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(RemoteRecv)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(RemoteRecv)::getstate, METH_NOARGS, "RemoteRecv getstate"}, + {const_cast("__setstate__"), PyOp(RemoteRecv)::setstate, METH_VARARGS, "RemoteRecv setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_RemoteRecv(py::module m) { + using py_op = PyOp(RemoteRecv); + auto& py_type = PyOpType(RemoteRecv); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteRecv"; + py_type.tp_basicsize = sizeof(PyOp(RemoteRecv)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "RemoteRecv"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("RemoteRecv", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteRecv::typeinfo(), &py_type).second); +} + +PyOpDefBegin(RemoteSend) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"key", serialization::dump(opdef.key)}, + {"addr", serialization::dump(opdef.addr)}, + {"port", serialization::dump(opdef.port)}, + {"rank_to", serialization::dump(opdef.rank_to)}, + {"backend", serialization::dump(opdef.backend)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("key"); + if (iter != state.end()) { + opdef.key = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("addr"); + if (iter != state.end()) { + opdef.addr = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("port"); + if (iter != state.end()) { + opdef.port = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("rank_to"); + if (iter != state.end()) { + opdef.rank_to = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("backend"); + if (iter != state.end()) { + opdef.backend = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(RemoteSend) + +int PyOp(RemoteSend)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"key", "addr", "port", "rank_to", "backend", "scope", NULL}; + PyObject *key = NULL, *addr = NULL, *port = NULL, *rank_to = NULL, *backend = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", const_cast(kwlist), &key, &addr, &port, &rank_to, &backend, &scope)) + return -1; + + if (key) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().key = + py::cast(py::handle(key)); + } CATCH_ALL(-1) + } + + if (addr) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().addr = + py::cast(py::handle(addr)); + } CATCH_ALL(-1) + } + + if (port) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().port = + py::cast(py::handle(port)); + } CATCH_ALL(-1) + } + + if (rank_to) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().rank_to = + py::cast(py::handle(rank_to)); + } CATCH_ALL(-1) + } + + if (backend) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().backend = + py::cast(py::handle(backend)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(RemoteSend)::py_getsetters[] = { + {const_cast("key"), py_get_generic(RemoteSend, key), py_set_generic(RemoteSend, key), const_cast("key"), NULL}, + {const_cast("addr"), py_get_generic(RemoteSend, addr), py_set_generic(RemoteSend, addr), const_cast("addr"), NULL}, + {const_cast("port"), py_get_generic(RemoteSend, port), py_set_generic(RemoteSend, port), const_cast("port"), NULL}, + {const_cast("rank_to"), py_get_generic(RemoteSend, rank_to), py_set_generic(RemoteSend, rank_to), const_cast("rank_to"), NULL}, + {const_cast("backend"), py_get_generic(RemoteSend, backend), py_set_generic(RemoteSend, backend), const_cast("backend"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(RemoteSend)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(RemoteSend)::getstate, METH_NOARGS, "RemoteSend getstate"}, + {const_cast("__setstate__"), PyOp(RemoteSend)::setstate, METH_VARARGS, "RemoteSend setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_RemoteSend(py::module m) { + using py_op = PyOp(RemoteSend); + auto& py_type = PyOpType(RemoteSend); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.RemoteSend"; + py_type.tp_basicsize = sizeof(PyOp(RemoteSend)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "RemoteSend"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("RemoteSend", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoteSend::typeinfo(), &py_type).second); +} + +PyOpDefBegin(RemoveAxis) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(RemoveAxis) + +int PyOp(RemoveAxis)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "scope", NULL}; + PyObject *axis = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &axis, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(RemoveAxis)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(RemoveAxis, axis), py_set_generic(RemoveAxis, axis), const_cast("axis"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(RemoveAxis)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(RemoveAxis)::getstate, METH_NOARGS, "RemoveAxis getstate"}, + {const_cast("__setstate__"), PyOp(RemoveAxis)::setstate, METH_VARARGS, "RemoveAxis setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_RemoveAxis(py::module m) { + using py_op = PyOp(RemoveAxis); + auto& py_type = PyOpType(RemoveAxis); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.RemoveAxis"; + py_type.tp_basicsize = sizeof(PyOp(RemoveAxis)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "RemoveAxis"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("RemoveAxis", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(RemoveAxis::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Reshape) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)}, + {"shape", serialization::dump(opdef.shape)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("shape"); + if (iter != state.end()) { + opdef.shape = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Reshape) + +int PyOp(Reshape)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "shape", "scope", NULL}; + PyObject *axis = NULL, *shape = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &axis, &shape, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (shape) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().shape = + py::cast(py::handle(shape)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Reshape)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(Reshape, axis), py_set_generic(Reshape, axis), const_cast("axis"), NULL}, + {const_cast("shape"), py_get_generic(Reshape, shape), py_set_generic(Reshape, shape), const_cast("shape"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Reshape)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Reshape)::getstate, METH_NOARGS, "Reshape getstate"}, + {const_cast("__setstate__"), PyOp(Reshape)::setstate, METH_VARARGS, "Reshape setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Reshape(py::module m) { + using py_op = PyOp(Reshape); + auto& py_type = PyOpType(Reshape); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Reshape"; + py_type.tp_basicsize = sizeof(PyOp(Reshape)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Reshape"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Reshape", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Reshape::typeinfo(), &py_type).second); +} + +void _init_py_Resize_InterpolationMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "InterpolationMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_Resize_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(Resize) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"imode", serialization::dump(opdef.imode)}, + {"format", serialization::dump(opdef.format)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("imode"); + if (iter != state.end()) { + opdef.imode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Resize) + +int PyOp(Resize)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"imode", "format", "scope", NULL}; + PyObject *imode = NULL, *format = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &imode, &format, &scope)) + return -1; + + if (imode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().imode = + py::cast(py::handle(imode)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Resize)::py_getsetters[] = { + {const_cast("imode"), py_get_generic(Resize, imode), py_set_generic(Resize, imode), const_cast("imode"), NULL}, + {const_cast("format"), py_get_generic(Resize, format), py_set_generic(Resize, format), const_cast("format"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Resize)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Resize)::getstate, METH_NOARGS, "Resize getstate"}, + {const_cast("__setstate__"), PyOp(Resize)::setstate, METH_VARARGS, "Resize setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Resize(py::module m) { + using py_op = PyOp(Resize); + auto& py_type = PyOpType(Resize); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Resize"; + py_type.tp_basicsize = sizeof(PyOp(Resize)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Resize"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_Resize_InterpolationMode(py_type); + _init_py_Resize_Format(py_type); + + PyType_Modified(&py_type); + m.add_object("Resize", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Resize::typeinfo(), &py_type).second); +} + +PyOpDefBegin(SVD) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"full_matrices", serialization::dump(opdef.full_matrices)}, + {"compute_uv", serialization::dump(opdef.compute_uv)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("full_matrices"); + if (iter != state.end()) { + opdef.full_matrices = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("compute_uv"); + if (iter != state.end()) { + opdef.compute_uv = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(SVD) + +int PyOp(SVD)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"full_matrices", "compute_uv", "scope", NULL}; + PyObject *full_matrices = NULL, *compute_uv = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &full_matrices, &compute_uv, &scope)) + return -1; + + if (full_matrices) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().full_matrices = + py::cast(py::handle(full_matrices)); + } CATCH_ALL(-1) + } + + if (compute_uv) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().compute_uv = + py::cast(py::handle(compute_uv)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(SVD)::py_getsetters[] = { + {const_cast("full_matrices"), py_get_generic(SVD, full_matrices), py_set_generic(SVD, full_matrices), const_cast("full_matrices"), NULL}, + {const_cast("compute_uv"), py_get_generic(SVD, compute_uv), py_set_generic(SVD, compute_uv), const_cast("compute_uv"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(SVD)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(SVD)::getstate, METH_NOARGS, "SVD getstate"}, + {const_cast("__setstate__"), PyOp(SVD)::setstate, METH_VARARGS, "SVD setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_SVD(py::module m) { + using py_op = PyOp(SVD); + auto& py_type = PyOpType(SVD); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.SVD"; + py_type.tp_basicsize = sizeof(PyOp(SVD)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "SVD"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("SVD", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SVD::typeinfo(), &py_type).second); +} + +PyOpDefBegin(SetMeshIndexing) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(SetMeshIndexing) + +int PyOp(SetMeshIndexing)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(SetMeshIndexing)::py_getsetters[] = { + {const_cast("items"), py_get_generic(SetMeshIndexing, items), py_set_generic(SetMeshIndexing, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(SetMeshIndexing)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(SetMeshIndexing)::getstate, METH_NOARGS, "SetMeshIndexing getstate"}, + {const_cast("__setstate__"), PyOp(SetMeshIndexing)::setstate, METH_VARARGS, "SetMeshIndexing setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_SetMeshIndexing(py::module m) { + using py_op = PyOp(SetMeshIndexing); + auto& py_type = PyOpType(SetMeshIndexing); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.SetMeshIndexing"; + py_type.tp_basicsize = sizeof(PyOp(SetMeshIndexing)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "SetMeshIndexing"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("SetMeshIndexing", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetMeshIndexing::typeinfo(), &py_type).second); +} + +PyOpDefBegin(SetSubtensor) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(SetSubtensor) + +int PyOp(SetSubtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(SetSubtensor)::py_getsetters[] = { + {const_cast("items"), py_get_generic(SetSubtensor, items), py_set_generic(SetSubtensor, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(SetSubtensor)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(SetSubtensor)::getstate, METH_NOARGS, "SetSubtensor getstate"}, + {const_cast("__setstate__"), PyOp(SetSubtensor)::setstate, METH_VARARGS, "SetSubtensor setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_SetSubtensor(py::module m) { + using py_op = PyOp(SetSubtensor); + auto& py_type = PyOpType(SetSubtensor); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.SetSubtensor"; + py_type.tp_basicsize = sizeof(PyOp(SetSubtensor)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "SetSubtensor"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("SetSubtensor", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SetSubtensor::typeinfo(), &py_type).second); +} + +PyOpDefBegin(ShuffleRNG) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"seed", serialization::dump(opdef.seed)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(ShuffleRNG) + +int PyOp(ShuffleRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"seed", "handle", "scope", NULL}; + PyObject *seed = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &seed, &handle, &scope)) + return -1; + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(ShuffleRNG)::py_getsetters[] = { + {const_cast("seed"), py_get_generic(ShuffleRNG, seed), py_set_generic(ShuffleRNG, seed), const_cast("seed"), NULL}, + {const_cast("handle"), py_get_generic(ShuffleRNG, handle), py_set_generic(ShuffleRNG, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(ShuffleRNG)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(ShuffleRNG)::getstate, METH_NOARGS, "ShuffleRNG getstate"}, + {const_cast("__setstate__"), PyOp(ShuffleRNG)::setstate, METH_VARARGS, "ShuffleRNG setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_ShuffleRNG(py::module m) { + using py_op = PyOp(ShuffleRNG); + auto& py_type = PyOpType(ShuffleRNG); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.ShuffleRNG"; + py_type.tp_basicsize = sizeof(PyOp(ShuffleRNG)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "ShuffleRNG"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("ShuffleRNG", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(ShuffleRNG::typeinfo(), &py_type).second); +} + +PyOpDefBegin(SlidingWindowTranspose) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"out_h", serialization::dump(opdef.out_h)}, + {"out_w", serialization::dump(opdef.out_w)}, + {"pad_h", serialization::dump(opdef.pad_h)}, + {"pad_w", serialization::dump(opdef.pad_w)}, + {"stride_h", serialization::dump(opdef.stride_h)}, + {"stride_w", serialization::dump(opdef.stride_w)}, + {"dilate_h", serialization::dump(opdef.dilate_h)}, + {"dilate_w", serialization::dump(opdef.dilate_w)}, + {"window_h", serialization::dump(opdef.window_h)}, + {"window_w", serialization::dump(opdef.window_w)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("out_h"); + if (iter != state.end()) { + opdef.out_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("out_w"); + if (iter != state.end()) { + opdef.out_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_h"); + if (iter != state.end()) { + opdef.pad_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("pad_w"); + if (iter != state.end()) { + opdef.pad_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_h"); + if (iter != state.end()) { + opdef.stride_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("stride_w"); + if (iter != state.end()) { + opdef.stride_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_h"); + if (iter != state.end()) { + opdef.dilate_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dilate_w"); + if (iter != state.end()) { + opdef.dilate_w = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("window_h"); + if (iter != state.end()) { + opdef.window_h = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("window_w"); + if (iter != state.end()) { + opdef.window_w = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(SlidingWindowTranspose) + +int PyOp(SlidingWindowTranspose)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"out_h", "out_w", "pad_h", "pad_w", "stride_h", "stride_w", "dilate_h", "dilate_w", "window_h", "window_w", "scope", NULL}; + PyObject *out_h = NULL, *out_w = NULL, *pad_h = NULL, *pad_w = NULL, *stride_h = NULL, *stride_w = NULL, *dilate_h = NULL, *dilate_w = NULL, *window_h = NULL, *window_w = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOOOOOOO", const_cast(kwlist), &out_h, &out_w, &pad_h, &pad_w, &stride_h, &stride_w, &dilate_h, &dilate_w, &window_h, &window_w, &scope)) + return -1; + + if (out_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().out_h = + py::cast(py::handle(out_h)); + } CATCH_ALL(-1) + } + + if (out_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().out_w = + py::cast(py::handle(out_w)); + } CATCH_ALL(-1) + } + + if (pad_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_h = + py::cast(py::handle(pad_h)); + } CATCH_ALL(-1) + } + + if (pad_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().pad_w = + py::cast(py::handle(pad_w)); + } CATCH_ALL(-1) + } + + if (stride_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_h = + py::cast(py::handle(stride_h)); + } CATCH_ALL(-1) + } + + if (stride_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().stride_w = + py::cast(py::handle(stride_w)); + } CATCH_ALL(-1) + } + + if (dilate_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_h = + py::cast(py::handle(dilate_h)); + } CATCH_ALL(-1) + } + + if (dilate_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dilate_w = + py::cast(py::handle(dilate_w)); + } CATCH_ALL(-1) + } + + if (window_h) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().window_h = + py::cast(py::handle(window_h)); + } CATCH_ALL(-1) + } + + if (window_w) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().window_w = + py::cast(py::handle(window_w)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(SlidingWindowTranspose)::py_getsetters[] = { + {const_cast("out_h"), py_get_generic(SlidingWindowTranspose, out_h), py_set_generic(SlidingWindowTranspose, out_h), const_cast("out_h"), NULL}, + {const_cast("out_w"), py_get_generic(SlidingWindowTranspose, out_w), py_set_generic(SlidingWindowTranspose, out_w), const_cast("out_w"), NULL}, + {const_cast("pad_h"), py_get_generic(SlidingWindowTranspose, pad_h), py_set_generic(SlidingWindowTranspose, pad_h), const_cast("pad_h"), NULL}, + {const_cast("pad_w"), py_get_generic(SlidingWindowTranspose, pad_w), py_set_generic(SlidingWindowTranspose, pad_w), const_cast("pad_w"), NULL}, + {const_cast("stride_h"), py_get_generic(SlidingWindowTranspose, stride_h), py_set_generic(SlidingWindowTranspose, stride_h), const_cast("stride_h"), NULL}, + {const_cast("stride_w"), py_get_generic(SlidingWindowTranspose, stride_w), py_set_generic(SlidingWindowTranspose, stride_w), const_cast("stride_w"), NULL}, + {const_cast("dilate_h"), py_get_generic(SlidingWindowTranspose, dilate_h), py_set_generic(SlidingWindowTranspose, dilate_h), const_cast("dilate_h"), NULL}, + {const_cast("dilate_w"), py_get_generic(SlidingWindowTranspose, dilate_w), py_set_generic(SlidingWindowTranspose, dilate_w), const_cast("dilate_w"), NULL}, + {const_cast("window_h"), py_get_generic(SlidingWindowTranspose, window_h), py_set_generic(SlidingWindowTranspose, window_h), const_cast("window_h"), NULL}, + {const_cast("window_w"), py_get_generic(SlidingWindowTranspose, window_w), py_set_generic(SlidingWindowTranspose, window_w), const_cast("window_w"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(SlidingWindowTranspose)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(SlidingWindowTranspose)::getstate, METH_NOARGS, "SlidingWindowTranspose getstate"}, + {const_cast("__setstate__"), PyOp(SlidingWindowTranspose)::setstate, METH_VARARGS, "SlidingWindowTranspose setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_SlidingWindowTranspose(py::module m) { + using py_op = PyOp(SlidingWindowTranspose); + auto& py_type = PyOpType(SlidingWindowTranspose); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.SlidingWindowTranspose"; + py_type.tp_basicsize = sizeof(PyOp(SlidingWindowTranspose)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "SlidingWindowTranspose"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("SlidingWindowTranspose", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(SlidingWindowTranspose::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Softmax) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Softmax) + +int PyOp(Softmax)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "scope", NULL}; + PyObject *axis = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &axis, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Softmax)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(Softmax, axis), py_set_generic(Softmax, axis), const_cast("axis"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Softmax)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Softmax)::getstate, METH_NOARGS, "Softmax getstate"}, + {const_cast("__setstate__"), PyOp(Softmax)::setstate, METH_VARARGS, "Softmax setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Softmax(py::module m) { + using py_op = PyOp(Softmax); + auto& py_type = PyOpType(Softmax); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Softmax"; + py_type.tp_basicsize = sizeof(PyOp(Softmax)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Softmax"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Softmax", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Softmax::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Split) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"axis", serialization::dump(opdef.axis)}, + {"nsections", serialization::dump(opdef.nsections)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("axis"); + if (iter != state.end()) { + opdef.axis = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("nsections"); + if (iter != state.end()) { + opdef.nsections = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Split) + +int PyOp(Split)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"axis", "nsections", "scope", NULL}; + PyObject *axis = NULL, *nsections = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &axis, &nsections, &scope)) + return -1; + + if (axis) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().axis = + py::cast(py::handle(axis)); + } CATCH_ALL(-1) + } + + if (nsections) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().nsections = + py::cast(py::handle(nsections)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Split)::py_getsetters[] = { + {const_cast("axis"), py_get_generic(Split, axis), py_set_generic(Split, axis), const_cast("axis"), NULL}, + {const_cast("nsections"), py_get_generic(Split, nsections), py_set_generic(Split, nsections), const_cast("nsections"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Split)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Split)::getstate, METH_NOARGS, "Split getstate"}, + {const_cast("__setstate__"), PyOp(Split)::setstate, METH_VARARGS, "Split setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Split(py::module m) { + using py_op = PyOp(Split); + auto& py_type = PyOpType(Split); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Split"; + py_type.tp_basicsize = sizeof(PyOp(Split)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Split"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Split", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Split::typeinfo(), &py_type).second); +} + +PyOpDefBegin(Subtensor) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"items", serialization::dump(opdef.items)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("items"); + if (iter != state.end()) { + opdef.items = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(Subtensor) + +int PyOp(Subtensor)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"items", "scope", NULL}; + PyObject *items = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &items, &scope)) + return -1; + + if (items) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().items = + py::cast(py::handle(items)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(Subtensor)::py_getsetters[] = { + {const_cast("items"), py_get_generic(Subtensor, items), py_set_generic(Subtensor, items), const_cast("items"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(Subtensor)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(Subtensor)::getstate, METH_NOARGS, "Subtensor getstate"}, + {const_cast("__setstate__"), PyOp(Subtensor)::setstate, METH_VARARGS, "Subtensor setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_Subtensor(py::module m) { + using py_op = PyOp(Subtensor); + auto& py_type = PyOpType(Subtensor); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.Subtensor"; + py_type.tp_basicsize = sizeof(PyOp(Subtensor)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "Subtensor"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("Subtensor", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(Subtensor::typeinfo(), &py_type).second); +} + +PyOpDefBegin(TQT) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"qmin", serialization::dump(opdef.qmin)}, + {"qmax", serialization::dump(opdef.qmax)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("qmin"); + if (iter != state.end()) { + opdef.qmin = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("qmax"); + if (iter != state.end()) { + opdef.qmax = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(TQT) + +int PyOp(TQT)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"qmin", "qmax", "scope", NULL}; + PyObject *qmin = NULL, *qmax = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &qmin, &qmax, &scope)) + return -1; + + if (qmin) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().qmin = + py::cast(py::handle(qmin)); + } CATCH_ALL(-1) + } + + if (qmax) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().qmax = + py::cast(py::handle(qmax)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(TQT)::py_getsetters[] = { + {const_cast("qmin"), py_get_generic(TQT, qmin), py_set_generic(TQT, qmin), const_cast("qmin"), NULL}, + {const_cast("qmax"), py_get_generic(TQT, qmax), py_set_generic(TQT, qmax), const_cast("qmax"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(TQT)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(TQT)::getstate, METH_NOARGS, "TQT getstate"}, + {const_cast("__setstate__"), PyOp(TQT)::setstate, METH_VARARGS, "TQT setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_TQT(py::module m) { + using py_op = PyOp(TQT); + auto& py_type = PyOpType(TQT); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.TQT"; + py_type.tp_basicsize = sizeof(PyOp(TQT)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "TQT"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("TQT", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TQT::typeinfo(), &py_type).second); +} + +PyOpDefBegin(TensorRTRuntime) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"buf", serialization::dump(opdef.buf)}, + {"buf_size", serialization::dump(opdef.buf_size)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("buf"); + if (iter != state.end()) { + opdef.buf = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("buf_size"); + if (iter != state.end()) { + opdef.buf_size = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(TensorRTRuntime) + +int PyOp(TensorRTRuntime)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"buf", "buf_size", "scope", NULL}; + PyObject *buf = NULL, *buf_size = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", const_cast(kwlist), &buf, &buf_size, &scope)) + return -1; + + if (buf) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf = + py::cast(py::handle(buf)); + } CATCH_ALL(-1) + } + + if (buf_size) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().buf_size = + py::cast(py::handle(buf_size)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(TensorRTRuntime)::py_getsetters[] = { + {const_cast("buf"), py_get_generic(TensorRTRuntime, buf), py_set_generic(TensorRTRuntime, buf), const_cast("buf"), NULL}, + {const_cast("buf_size"), py_get_generic(TensorRTRuntime, buf_size), py_set_generic(TensorRTRuntime, buf_size), const_cast("buf_size"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(TensorRTRuntime)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(TensorRTRuntime)::getstate, METH_NOARGS, "TensorRTRuntime getstate"}, + {const_cast("__setstate__"), PyOp(TensorRTRuntime)::setstate, METH_VARARGS, "TensorRTRuntime setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_TensorRTRuntime(py::module m) { + using py_op = PyOp(TensorRTRuntime); + auto& py_type = PyOpType(TensorRTRuntime); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.TensorRTRuntime"; + py_type.tp_basicsize = sizeof(PyOp(TensorRTRuntime)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "TensorRTRuntime"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("TensorRTRuntime", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TensorRTRuntime::typeinfo(), &py_type).second); +} + +template<> struct EnumTrait { + static constexpr const char *name = "TopK.Mode"; + static constexpr std::underlying_type_t max = 3 - 1; +}; +template<> PyTypeObject* EnumWrapper::type = nullptr; + +template<> const char* +EnumWrapper::members[] = {"KTH_ONLY", "VALUE_IDX_NOSORT", "VALUE_IDX_SORTED"}; + +template<> std::unordered_map +EnumWrapper::mem2value = {{normalize_enum("KTH_ONLY"), TopK::Mode::KTH_ONLY}, {normalize_enum("VALUE_IDX_NOSORT"), TopK::Mode::VALUE_IDX_NOSORT}, {normalize_enum("VALUE_IDX_SORTED"), TopK::Mode::VALUE_IDX_SORTED}}; +template<> PyObject* EnumWrapper::pyobj_insts[3] = {nullptr}; + +void _init_py_TopK_Mode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + static PyMethodDef tp_methods[] = { + {const_cast("dump"), (PyCFunction)EnumWrapper::py_dump, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ + }; + + static PyType_Slot slots[] = { + {Py_tp_repr, (void*)EnumWrapper::py_repr}, + {Py_tp_richcompare, (void*)EnumWrapper::tp_richcompare}, + {Py_tp_methods, tp_methods}, + + {0, NULL} + }; + static PyType_Spec spec = { + // name + "megengine.core._imperative_rt.ops.TopK.Mode", + // basicsize + sizeof(EnumWrapper), + // itemsize + 0, + // flags + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE, + // slots + slots + }; + e_type = reinterpret_cast(PyType_FromSpec(&spec)); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__name__").release().ptr(), + py::cast("Mode").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__module__").release().ptr(), + py::cast("megengine.core._imperative_rt.ops").release().ptr()) >= 0); + + mgb_assert( + e_type->tp_setattro( + reinterpret_cast(e_type), + py::cast("__qualname__").release().ptr(), + py::cast("TopK.Mode").release().ptr()) >= 0); +{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = TopK::Mode::KTH_ONLY; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "KTH_ONLY", inst) >= 0); + EnumWrapper::pyobj_insts[0] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = TopK::Mode::VALUE_IDX_NOSORT; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_NOSORT", inst) >= 0); + EnumWrapper::pyobj_insts[1] = inst; +}{ + PyObject* inst = e_type->tp_alloc(e_type, 0); + reinterpret_cast*>(inst)->value = TopK::Mode::VALUE_IDX_SORTED; + mgb_assert(PyDict_SetItemString(e_type->tp_dict, "VALUE_IDX_SORTED", inst) >= 0); + EnumWrapper::pyobj_insts[2] = inst; +} + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Mode", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(TopK) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"mode", serialization::dump(opdef.mode)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("mode"); + if (iter != state.end()) { + opdef.mode = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(TopK) + +int PyOp(TopK)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"mode", "scope", NULL}; + PyObject *mode = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &mode, &scope)) + return -1; + + if (mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().mode = + py::cast(py::handle(mode)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(TopK)::py_getsetters[] = { + {const_cast("mode"), py_get_generic(TopK, mode), py_set_generic(TopK, mode), const_cast("mode"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(TopK)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(TopK)::getstate, METH_NOARGS, "TopK getstate"}, + {const_cast("__setstate__"), PyOp(TopK)::setstate, METH_VARARGS, "TopK setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_TopK(py::module m) { + using py_op = PyOp(TopK); + auto& py_type = PyOpType(TopK); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.TopK"; + py_type.tp_basicsize = sizeof(PyOp(TopK)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "TopK"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_TopK_Mode(py_type); + + PyType_Modified(&py_type); + m.add_object("TopK", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TopK::typeinfo(), &py_type).second); +} + +PyOpDefBegin(TypeCvt) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"dtype", serialization::dump(opdef.dtype)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(TypeCvt) + +int PyOp(TypeCvt)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"dtype", "scope", NULL}; + PyObject *dtype = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", const_cast(kwlist), &dtype, &scope)) + return -1; + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(TypeCvt)::py_getsetters[] = { + {const_cast("dtype"), py_get_generic(TypeCvt, dtype), py_set_generic(TypeCvt, dtype), const_cast("dtype"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(TypeCvt)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(TypeCvt)::getstate, METH_NOARGS, "TypeCvt getstate"}, + {const_cast("__setstate__"), PyOp(TypeCvt)::setstate, METH_VARARGS, "TypeCvt setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_TypeCvt(py::module m) { + using py_op = PyOp(TypeCvt); + auto& py_type = PyOpType(TypeCvt); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.TypeCvt"; + py_type.tp_basicsize = sizeof(PyOp(TypeCvt)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "TypeCvt"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("TypeCvt", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(TypeCvt::typeinfo(), &py_type).second); +} + +PyOpDefBegin(UniformRNG) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"seed", serialization::dump(opdef.seed)}, + {"dtype", serialization::dump(opdef.dtype)}, + {"handle", serialization::dump(opdef.handle)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("seed"); + if (iter != state.end()) { + opdef.seed = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("dtype"); + if (iter != state.end()) { + opdef.dtype = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("handle"); + if (iter != state.end()) { + opdef.handle = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(UniformRNG) + +int PyOp(UniformRNG)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"seed", "dtype", "handle", "scope", NULL}; + PyObject *seed = NULL, *dtype = NULL, *handle = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", const_cast(kwlist), &seed, &dtype, &handle, &scope)) + return -1; + + if (seed) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().seed = + py::cast(py::handle(seed)); + } CATCH_ALL(-1) + } + + if (dtype) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().dtype = + py::cast(py::handle(dtype)); + } CATCH_ALL(-1) + } + + if (handle) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().handle = + py::cast(py::handle(handle)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(UniformRNG)::py_getsetters[] = { + {const_cast("seed"), py_get_generic(UniformRNG, seed), py_set_generic(UniformRNG, seed), const_cast("seed"), NULL}, + {const_cast("dtype"), py_get_generic(UniformRNG, dtype), py_set_generic(UniformRNG, dtype), const_cast("dtype"), NULL}, + {const_cast("handle"), py_get_generic(UniformRNG, handle), py_set_generic(UniformRNG, handle), const_cast("handle"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(UniformRNG)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(UniformRNG)::getstate, METH_NOARGS, "UniformRNG getstate"}, + {const_cast("__setstate__"), PyOp(UniformRNG)::setstate, METH_VARARGS, "UniformRNG setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_UniformRNG(py::module m) { + using py_op = PyOp(UniformRNG); + auto& py_type = PyOpType(UniformRNG); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.UniformRNG"; + py_type.tp_basicsize = sizeof(PyOp(UniformRNG)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "UniformRNG"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + + PyType_Modified(&py_type); + m.add_object("UniformRNG", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(UniformRNG::typeinfo(), &py_type).second); +} + +void _init_py_WarpAffine_InterpolationMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "InterpolationMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_WarpAffine_BorderMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "BorderMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_WarpAffine_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(WarpAffine) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"imode", serialization::dump(opdef.imode)}, + {"border_mode", serialization::dump(opdef.border_mode)}, + {"border_val", serialization::dump(opdef.border_val)}, + {"format", serialization::dump(opdef.format)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("imode"); + if (iter != state.end()) { + opdef.imode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("border_mode"); + if (iter != state.end()) { + opdef.border_mode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("border_val"); + if (iter != state.end()) { + opdef.border_val = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(WarpAffine) + +int PyOp(WarpAffine)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"imode", "border_mode", "border_val", "format", "scope", NULL}; + PyObject *imode = NULL, *border_mode = NULL, *border_val = NULL, *format = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast(kwlist), &imode, &border_mode, &border_val, &format, &scope)) + return -1; + + if (imode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().imode = + py::cast(py::handle(imode)); + } CATCH_ALL(-1) + } + + if (border_mode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().border_mode = + py::cast(py::handle(border_mode)); + } CATCH_ALL(-1) + } + + if (border_val) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().border_val = + py::cast(py::handle(border_val)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(WarpAffine)::py_getsetters[] = { + {const_cast("imode"), py_get_generic(WarpAffine, imode), py_set_generic(WarpAffine, imode), const_cast("imode"), NULL}, + {const_cast("border_mode"), py_get_generic(WarpAffine, border_mode), py_set_generic(WarpAffine, border_mode), const_cast("border_mode"), NULL}, + {const_cast("border_val"), py_get_generic(WarpAffine, border_val), py_set_generic(WarpAffine, border_val), const_cast("border_val"), NULL}, + {const_cast("format"), py_get_generic(WarpAffine, format), py_set_generic(WarpAffine, format), const_cast("format"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(WarpAffine)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(WarpAffine)::getstate, METH_NOARGS, "WarpAffine getstate"}, + {const_cast("__setstate__"), PyOp(WarpAffine)::setstate, METH_VARARGS, "WarpAffine setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_WarpAffine(py::module m) { + using py_op = PyOp(WarpAffine); + auto& py_type = PyOpType(WarpAffine); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.WarpAffine"; + py_type.tp_basicsize = sizeof(PyOp(WarpAffine)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "WarpAffine"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_WarpAffine_InterpolationMode(py_type); + _init_py_WarpAffine_BorderMode(py_type); + _init_py_WarpAffine_Format(py_type); + + PyType_Modified(&py_type); + m.add_object("WarpAffine", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpAffine::typeinfo(), &py_type).second); +} + +void _init_py_WarpPerspective_InterpolationMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "InterpolationMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_WarpPerspective_BorderMode(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "BorderMode", reinterpret_cast(e_type)) >= 0); +} + +void _init_py_WarpPerspective_Format(PyTypeObject& py_type) { + auto& e_type = EnumWrapper::type; + + Py_INCREF(e_type); + mgb_assert(PyDict_SetItemString( + py_type.tp_dict, "Format", reinterpret_cast(e_type)) >= 0); +} + +PyOpDefBegin(WarpPerspective) // { + static PyGetSetDef py_getsetters[]; + static PyMethodDef tp_methods[]; + + static PyObject* getstate(PyObject* self, PyObject*) { + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + std::unordered_map state { + + {"imode", serialization::dump(opdef.imode)}, + {"bmode", serialization::dump(opdef.bmode)}, + {"format", serialization::dump(opdef.format)}, + {"border_val", serialization::dump(opdef.border_val)} + }; + return py::cast(state).release().ptr(); + } + static PyObject* setstate(PyObject* self, PyObject* args) { + PyObject* dict = PyTuple_GetItem(args, 0); + if (!dict) return NULL; + auto state = py::cast>(dict); + auto& opdef = reinterpret_cast(self)->inst(); + static_cast(opdef); + + { + auto&& iter = state.find("imode"); + if (iter != state.end()) { + opdef.imode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("bmode"); + if (iter != state.end()) { + opdef.bmode = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("format"); + if (iter != state.end()) { + opdef.format = serialization::load(iter->second); + } + } + + { + auto&& iter = state.find("border_val"); + if (iter != state.end()) { + opdef.border_val = serialization::load(iter->second); + } + } + Py_RETURN_NONE; + } + static int py_init(PyObject *self, PyObject *args, PyObject *kwds); +// }; +PyOpDefEnd(WarpPerspective) + +int PyOp(WarpPerspective)::py_init(PyObject *self, PyObject *args, PyObject *kwds) { + static const char* kwlist[] = {"imode", "bmode", "format", "border_val", "scope", NULL}; + PyObject *imode = NULL, *bmode = NULL, *format = NULL, *border_val = NULL, *scope = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", const_cast(kwlist), &imode, &bmode, &format, &border_val, &scope)) + return -1; + + if (imode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().imode = + py::cast(py::handle(imode)); + } CATCH_ALL(-1) + } + + if (bmode) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().bmode = + py::cast(py::handle(bmode)); + } CATCH_ALL(-1) + } + + if (format) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().format = + py::cast(py::handle(format)); + } CATCH_ALL(-1) + } + + if (border_val) { + try { + // TODO: remove this guard which is used for pybind11 implicit conversion + py::detail::loader_life_support guard{}; + reinterpret_cast(self)->inst().border_val = + py::cast(py::handle(border_val)); + } CATCH_ALL(-1) + } + + if (scope) { + try { + reinterpret_cast(self)->op + ->set_scope(py::cast(py::handle(scope))); + } CATCH_ALL(-1) + } + + return 0; +} + +PyGetSetDef PyOp(WarpPerspective)::py_getsetters[] = { + {const_cast("imode"), py_get_generic(WarpPerspective, imode), py_set_generic(WarpPerspective, imode), const_cast("imode"), NULL}, + {const_cast("bmode"), py_get_generic(WarpPerspective, bmode), py_set_generic(WarpPerspective, bmode), const_cast("bmode"), NULL}, + {const_cast("format"), py_get_generic(WarpPerspective, format), py_set_generic(WarpPerspective, format), const_cast("format"), NULL}, + {const_cast("border_val"), py_get_generic(WarpPerspective, border_val), py_set_generic(WarpPerspective, border_val), const_cast("border_val"), NULL}, + {NULL} /* Sentinel */ +}; + + PyMethodDef PyOp(WarpPerspective)::tp_methods[] = { + {const_cast("__getstate__"), PyOp(WarpPerspective)::getstate, METH_NOARGS, "WarpPerspective getstate"}, + {const_cast("__setstate__"), PyOp(WarpPerspective)::setstate, METH_VARARGS, "WarpPerspective setstate"}, + {NULL} /* Sentinel */ + }; + +void _init_py_WarpPerspective(py::module m) { + using py_op = PyOp(WarpPerspective); + auto& py_type = PyOpType(WarpPerspective); + py_type = {PyVarObject_HEAD_INIT(NULL, 0)}; + py_type.tp_name = "megengine.core._imperative_rt.ops.WarpPerspective"; + py_type.tp_basicsize = sizeof(PyOp(WarpPerspective)); + py_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; + py_type.tp_doc = "WarpPerspective"; + py_type.tp_base = &PyOpType(OpDef); + py_type.tp_dealloc = py_dealloc_generic; + py_type.tp_new = py_new_generic; + py_type.tp_init = py_op::py_init; + py_type.tp_methods = py_op::tp_methods; + py_type.tp_getset = py_op::py_getsetters; + mgb_assert(PyType_Ready(&py_type) >= 0); + _init_py_WarpPerspective_InterpolationMode(py_type); + _init_py_WarpPerspective_BorderMode(py_type); + _init_py_WarpPerspective_Format(py_type); + + PyType_Modified(&py_type); + m.add_object("WarpPerspective", reinterpret_cast(&py_type)); + mgb_assert(PyOp(OpDef)::ctype2pytype.emplace(WarpPerspective::typeinfo(), &py_type).second); +} +#define INIT_ALL_OP(m) \ + _init_py_AdaptivePooling(m); \ + _init_py_AddAxis(m); \ + _init_py_Argmax(m); \ + _init_py_Argmin(m); \ + _init_py_Argsort(m); \ + _init_py_AssertEqual(m); \ + _init_py_AtlasRuntime(m); \ + _init_py_Barrier(m); \ + _init_py_BatchConvBias(m); \ + _init_py_BatchNorm(m); \ + _init_py_BatchNormBackward(m); \ + _init_py_BatchedIncrMeshIndexing(m); \ + _init_py_BatchedMatrixMul(m); \ + _init_py_BatchedMeshIndexing(m); \ + _init_py_BatchedSetMeshIndexing(m); \ + _init_py_BetaRNG(m); \ + _init_py_Borrow(m); \ + _init_py_Broadcast(m); \ + _init_py_CambriconRuntime(m); \ + _init_py_CheckNonFinite(m); \ + _init_py_CollectiveComm(m); \ + _init_py_Concat(m); \ + _init_py_CondTake(m); \ + _init_py_ConvBias(m); \ + _init_py_Convolution(m); \ + _init_py_Convolution3D(m); \ + _init_py_Convolution3DBackwardData(m); \ + _init_py_ConvolutionBackwardData(m); \ + _init_py_Copy(m); \ + _init_py_Correlation(m); \ + _init_py_Cumsum(m); \ + _init_py_CvtColor(m); \ + _init_py_DeformableConv(m); \ + _init_py_DeformablePSROIPooling(m); \ + _init_py_Diag(m); \ + _init_py_Dimshuffle(m); \ + _init_py_Dot(m); \ + _init_py_Dropout(m); \ + _init_py_Elemwise(m); \ + _init_py_ElemwiseMultiType(m); \ + _init_py_ExternOpr(m); \ + _init_py_Eye(m); \ + _init_py_FakeQuant(m); \ + _init_py_FastpathCopy(m); \ + _init_py_GammaRNG(m); \ + _init_py_GaussianRNG(m); \ + _init_py_GetVarShape(m); \ + _init_py_GroupLocal(m); \ + _init_py_Identity(m); \ + _init_py_Images2Neibs(m); \ + _init_py_IncrMeshIndexing(m); \ + _init_py_IncrSubtensor(m); \ + _init_py_IndexingIncrMultiAxisVec(m); \ + _init_py_IndexingMultiAxisVec(m); \ + _init_py_IndexingOneHot(m); \ + _init_py_IndexingSetMultiAxisVec(m); \ + _init_py_IndexingSetOneHot(m); \ + _init_py_InplaceAdd(m); \ + _init_py_LAMBUpdate(m); \ + _init_py_LRN(m); \ + _init_py_LSQ(m); \ + _init_py_LSTM(m); \ + _init_py_LSTMCell(m); \ + _init_py_LayerNorm(m); \ + _init_py_Linspace(m); \ + _init_py_MagicMindRuntime(m); \ + _init_py_MatrixInverse(m); \ + _init_py_MatrixMul(m); \ + _init_py_MeshIndexing(m); \ + _init_py_NMSKeep(m); \ + _init_py_NvOf(m); \ + _init_py_Padding(m); \ + _init_py_ParamPackConcat(m); \ + _init_py_ParamPackSplit(m); \ + _init_py_PermutationRNG(m); \ + _init_py_PixelShuffle(m); \ + _init_py_PixelShuffleBackward(m); \ + _init_py_PoissonRNG(m); \ + _init_py_Pooling(m); \ + _init_py_RNN(m); \ + _init_py_RNNCell(m); \ + _init_py_ROIAlign(m); \ + _init_py_ROIPooling(m); \ + _init_py_Reduce(m); \ + _init_py_Remap(m); \ + _init_py_RemoteRecv(m); \ + _init_py_RemoteSend(m); \ + _init_py_RemoveAxis(m); \ + _init_py_Reshape(m); \ + _init_py_Resize(m); \ + _init_py_SVD(m); \ + _init_py_SetMeshIndexing(m); \ + _init_py_SetSubtensor(m); \ + _init_py_ShuffleRNG(m); \ + _init_py_SlidingWindowTranspose(m); \ + _init_py_Softmax(m); \ + _init_py_Split(m); \ + _init_py_Subtensor(m); \ + _init_py_TQT(m); \ + _init_py_TensorRTRuntime(m); \ + _init_py_TopK(m); \ + _init_py_TypeCvt(m); \ + _init_py_UniformRNG(m); \ + _init_py_WarpAffine(m); \ + _init_py_WarpPerspective(m); +// clang-format on diff --git a/imperative/tablegen/generated/opdef.h.inl b/imperative/tablegen/generated/opdef.h.inl new file mode 100644 index 00000000..16f5e782 --- /dev/null +++ b/imperative/tablegen/generated/opdef.h.inl @@ -0,0 +1,1789 @@ +// clang-format off +class AdaptivePooling : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::AdaptivePooling::Mode; + using Format = ::megdnn::param::AdaptivePooling::Format; + Mode mode = ::megdnn::param::AdaptivePooling::Mode::MAX; + Format format = ::megdnn::param::AdaptivePooling::Format::NCHW; + std::vector shape; + AdaptivePooling() = default; + AdaptivePooling(Mode mode_, Format format_, std::vector shape_, std::string scope_ = {}): mode(mode_), format(format_), shape(shape_) { set_scope(scope_); } + AdaptivePooling(::megdnn::param::AdaptivePooling packed_param_0, std::vector shape_): mode(packed_param_0.mode), format(packed_param_0.format), shape(shape_) {} + ::megdnn::param::AdaptivePooling param() const { + return {mode, format}; + } +}; + +class AddAxis : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector axis; + AddAxis() = default; + AddAxis(std::vector axis_, std::string scope_ = {}): axis(axis_) { set_scope(scope_); } +}; + +class Argmax : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = 0; + Argmax() = default; + Argmax(int32_t axis_, std::string scope_ = {}): axis(axis_) { set_scope(scope_); } + Argmax(::megdnn::param::Axis packed_param_0): axis(packed_param_0.axis) {} + ::megdnn::param::Axis param() const { + return {axis}; + } +}; + +class Argmin : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = 0; + Argmin() = default; + Argmin(int32_t axis_, std::string scope_ = {}): axis(axis_) { set_scope(scope_); } + Argmin(::megdnn::param::Axis packed_param_0): axis(packed_param_0.axis) {} + ::megdnn::param::Axis param() const { + return {axis}; + } +}; + +class Argsort : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Order = ::megdnn::param::Argsort::Order; + Order order = ::megdnn::param::Argsort::Order::ASCENDING; + Argsort() = default; + Argsort(Order order_, std::string scope_ = {}): order(order_) { set_scope(scope_); } + Argsort(::megdnn::param::Argsort packed_param_0): order(packed_param_0.order) {} + ::megdnn::param::Argsort param() const { + return {order}; + } +}; + +class AssertEqual : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + float maxerr = 0.0001; + bool verbose = false; + AssertEqual() = default; + AssertEqual(float maxerr_, bool verbose_, std::string scope_ = {}): maxerr(maxerr_), verbose(verbose_) { set_scope(scope_); } + AssertEqual(::megdnn::param::AssertEqual packed_param_0): maxerr(packed_param_0.maxerr), verbose(packed_param_0.verbose) {} + ::megdnn::param::AssertEqual param() const { + return {maxerr, verbose}; + } +}; + +class AtlasRuntime : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::string buf; + size_t buf_size; + AtlasRuntime() = default; + AtlasRuntime(std::string buf_, size_t buf_size_, std::string scope_ = {}): buf(buf_), buf_size(buf_size_) { set_scope(scope_); } +}; + +class Barrier : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + ::mgb::CompNode comp_node; + uint32_t nr_outputs; + Barrier() = default; + Barrier(::mgb::CompNode comp_node_, uint32_t nr_outputs_, std::string scope_ = {}): comp_node(comp_node_), nr_outputs(nr_outputs_) { set_scope(scope_); } +}; + +class BatchConvBias : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using NonlineMode = ::megdnn::param::BatchConvBias::NonlineMode; + using Mode = ::megdnn::param::BatchConvBias::Mode; + using Sparse = ::megdnn::param::BatchConvBias::Sparse; + using Format = ::megdnn::param::BatchConvBias::Format; + using ComputeMode = ::megdnn::param::BatchConvBias::ComputeMode; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + NonlineMode nonlineMode = ::megdnn::param::BatchConvBias::NonlineMode::IDENTITY; + Mode mode = ::megdnn::param::BatchConvBias::Mode::CROSS_CORRELATION; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + Sparse sparse = ::megdnn::param::BatchConvBias::Sparse::DENSE; + Format format = ::megdnn::param::BatchConvBias::Format::NCHW; + ComputeMode compute_mode = ::megdnn::param::BatchConvBias::ComputeMode::DEFAULT; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + ::megdnn::DType dtype; + BatchConvBias() = default; + BatchConvBias(NonlineMode nonlineMode_, Mode mode_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, Sparse sparse_, Format format_, ComputeMode compute_mode_, Strategy strategy_, uint64_t workspace_limit_, ::megdnn::DType dtype_, std::string scope_ = {}): nonlineMode(nonlineMode_), mode(mode_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), sparse(sparse_), format(format_), compute_mode(compute_mode_), strategy(strategy_), workspace_limit(workspace_limit_), dtype(dtype_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + BatchConvBias(::megdnn::param::BatchConvBias packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1, ::megdnn::DType dtype_): nonlineMode(packed_param_0.nonlineMode), mode(packed_param_0.mode), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), sparse(packed_param_0.sparse), format(packed_param_0.format), compute_mode(packed_param_0.compute_mode), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit), dtype(dtype_) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::BatchConvBias param() const { + return {nonlineMode, mode, pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, sparse, format, compute_mode}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class BatchNorm : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using ParamDim = ::megdnn::param::BN::ParamDim; + using FwdMode = ::megdnn::param::BN::FwdMode; + ParamDim param_dim = ::megdnn::param::BN::ParamDim::DIM_11HW; + FwdMode fwd_mode = ::megdnn::param::BN::FwdMode::TRAINING; + double epsilon = 1e-4f; + double avg_factor = 1.f; + float scale = 1.f; + float bias = 0.f; + BatchNorm() = default; + BatchNorm(ParamDim param_dim_, FwdMode fwd_mode_, double epsilon_, double avg_factor_, float scale_, float bias_, std::string scope_ = {}): param_dim(param_dim_), fwd_mode(fwd_mode_), epsilon(epsilon_), avg_factor(avg_factor_), scale(scale_), bias(bias_) { set_scope(scope_); } + BatchNorm(::megdnn::param::BN packed_param_0): param_dim(packed_param_0.param_dim), fwd_mode(packed_param_0.fwd_mode), epsilon(packed_param_0.epsilon), avg_factor(packed_param_0.avg_factor), scale(packed_param_0.scale), bias(packed_param_0.bias) {} + ::megdnn::param::BN param() const { + return {param_dim, fwd_mode, epsilon, avg_factor, scale, bias}; + } +}; + +class BatchNormBackward : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using ParamDim = ::megdnn::param::BN::ParamDim; + using FwdMode = ::megdnn::param::BN::FwdMode; + ParamDim param_dim = ::megdnn::param::BN::ParamDim::DIM_11HW; + FwdMode fwd_mode = ::megdnn::param::BN::FwdMode::TRAINING; + double epsilon = 1e-4f; + double avg_factor = 1.f; + float scale = 1.f; + float bias = 0.f; + BatchNormBackward() = default; + BatchNormBackward(ParamDim param_dim_, FwdMode fwd_mode_, double epsilon_, double avg_factor_, float scale_, float bias_, std::string scope_ = {}): param_dim(param_dim_), fwd_mode(fwd_mode_), epsilon(epsilon_), avg_factor(avg_factor_), scale(scale_), bias(bias_) { set_scope(scope_); } + BatchNormBackward(::megdnn::param::BN packed_param_0): param_dim(packed_param_0.param_dim), fwd_mode(packed_param_0.fwd_mode), epsilon(packed_param_0.epsilon), avg_factor(packed_param_0.avg_factor), scale(packed_param_0.scale), bias(packed_param_0.bias) {} + ::megdnn::param::BN param() const { + return {param_dim, fwd_mode, epsilon, avg_factor, scale, bias}; + } +}; + +class BatchedIncrMeshIndexing : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + BatchedIncrMeshIndexing() = default; + BatchedIncrMeshIndexing(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class BatchedMatrixMul : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using ComputeMode = ::megdnn::param::MatrixMul::ComputeMode; + using Format = ::megdnn::param::MatrixMul::Format; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + bool transposeA = false; + bool transposeB = false; + ComputeMode compute_mode = ::megdnn::param::MatrixMul::ComputeMode::DEFAULT; + Format format = ::megdnn::param::MatrixMul::Format::DEFAULT; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + uint32_t dimA; + uint32_t dimB; + BatchedMatrixMul() = default; + BatchedMatrixMul(bool transposeA_, bool transposeB_, ComputeMode compute_mode_, Format format_, Strategy strategy_, uint64_t workspace_limit_, uint32_t dimA_, uint32_t dimB_, std::string scope_ = {}): transposeA(transposeA_), transposeB(transposeB_), compute_mode(compute_mode_), format(format_), strategy(strategy_), workspace_limit(workspace_limit_), dimA(dimA_), dimB(dimB_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + BatchedMatrixMul(::megdnn::param::MatrixMul packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1, uint32_t dimA_, uint32_t dimB_): transposeA(packed_param_0.transposeA), transposeB(packed_param_0.transposeB), compute_mode(packed_param_0.compute_mode), format(packed_param_0.format), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit), dimA(dimA_), dimB(dimB_) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::MatrixMul param() const { + return {transposeA, transposeB, compute_mode, format}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class BatchedMeshIndexing : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + BatchedMeshIndexing() = default; + BatchedMeshIndexing(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class BatchedSetMeshIndexing : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + BatchedSetMeshIndexing() = default; + BatchedSetMeshIndexing(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class BetaRNG : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint64_t seed = 0; + size_t handle; + BetaRNG() = default; + BetaRNG(uint64_t seed_, size_t handle_, std::string scope_ = {}): seed(seed_), handle(handle_) { set_scope(scope_); } + BetaRNG(::megdnn::param::BetaRNG packed_param_0, size_t handle_): seed(packed_param_0.seed), handle(handle_) {} + ::megdnn::param::BetaRNG param() const { + return {seed}; + } +}; + +class Borrow : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + ::mgb::CompNode comp_node; + Borrow() = default; + Borrow(::mgb::CompNode comp_node_, std::string scope_ = {}): comp_node(comp_node_) { set_scope(scope_); } +}; + +class Broadcast : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector shape; + Broadcast() = default; + Broadcast(std::vector shape_, std::string scope_ = {}): shape(shape_) { set_scope(scope_); } + Broadcast(::megdnn::param::Empty, std::vector shape_): shape(shape_) {} + ::megdnn::param::Empty param() const { + return {}; + } +}; + +class CambriconRuntime : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::string buf; + size_t buf_size; + std::string symbol; + bool tensor_dim_mutable; + CambriconRuntime() = default; + CambriconRuntime(std::string buf_, size_t buf_size_, std::string symbol_, bool tensor_dim_mutable_, std::string scope_ = {}): buf(buf_), buf_size(buf_size_), symbol(symbol_), tensor_dim_mutable(tensor_dim_mutable_) { set_scope(scope_); } +}; + +class CheckNonFinite : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + float scale = 1.0; + CheckNonFinite() = default; + CheckNonFinite(float scale_, std::string scope_ = {}): scale(scale_) { set_scope(scope_); } + CheckNonFinite(::megdnn::param::CheckNonFinite packed_param_0): scale(packed_param_0.scale) {} + ::megdnn::param::CheckNonFinite param() const { + return {scale}; + } +}; + +class CollectiveComm : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::CollectiveComm::Mode; + Mode mode = ::megdnn::param::CollectiveComm::Mode::REDUCE_SUM; + std::string key; + uint32_t nr_devices; + uint32_t rank; + bool is_root; + bool local_grad; + std::string addr; + uint32_t port; + ::megdnn::DType dtype; + std::string backend; + std::string comp_node; + CollectiveComm() = default; + CollectiveComm(Mode mode_, std::string key_, uint32_t nr_devices_, uint32_t rank_, bool is_root_, bool local_grad_, std::string addr_, uint32_t port_, ::megdnn::DType dtype_, std::string backend_, std::string comp_node_, std::string scope_ = {}): mode(mode_), key(key_), nr_devices(nr_devices_), rank(rank_), is_root(is_root_), local_grad(local_grad_), addr(addr_), port(port_), dtype(dtype_), backend(backend_), comp_node(comp_node_) { set_scope(scope_); } + CollectiveComm(::megdnn::param::CollectiveComm packed_param_0, std::string key_, uint32_t nr_devices_, uint32_t rank_, bool is_root_, bool local_grad_, std::string addr_, uint32_t port_, ::megdnn::DType dtype_, std::string backend_, std::string comp_node_): mode(packed_param_0.mode), key(key_), nr_devices(nr_devices_), rank(rank_), is_root(is_root_), local_grad(local_grad_), addr(addr_), port(port_), dtype(dtype_), backend(backend_), comp_node(comp_node_) {} + ::megdnn::param::CollectiveComm param() const { + return {mode}; + } +}; + +class Concat : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = 0; + ::mgb::CompNode comp_node; + Concat() = default; + Concat(int32_t axis_, ::mgb::CompNode comp_node_, std::string scope_ = {}): axis(axis_), comp_node(comp_node_) { set_scope(scope_); } + Concat(::megdnn::param::Axis packed_param_0, ::mgb::CompNode comp_node_): axis(packed_param_0.axis), comp_node(comp_node_) {} + ::megdnn::param::Axis param() const { + return {axis}; + } +}; + +class CondTake : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + CondTake() = default; +}; + +class ConvBias : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using NonlineMode = ::megdnn::param::ConvBias::NonlineMode; + using Mode = ::megdnn::param::ConvBias::Mode; + using Sparse = ::megdnn::param::ConvBias::Sparse; + using Format = ::megdnn::param::ConvBias::Format; + using ComputeMode = ::megdnn::param::ConvBias::ComputeMode; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + NonlineMode nonlineMode = ::megdnn::param::ConvBias::NonlineMode::IDENTITY; + Mode mode = ::megdnn::param::ConvBias::Mode::CROSS_CORRELATION; + Sparse sparse = ::megdnn::param::ConvBias::Sparse::DENSE; + Format format = ::megdnn::param::ConvBias::Format::NCHW; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + ComputeMode compute_mode = ::megdnn::param::ConvBias::ComputeMode::DEFAULT; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + ::megdnn::DType dtype; + ConvBias() = default; + ConvBias(NonlineMode nonlineMode_, Mode mode_, Sparse sparse_, Format format_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, ComputeMode compute_mode_, Strategy strategy_, uint64_t workspace_limit_, ::megdnn::DType dtype_, std::string scope_ = {}): nonlineMode(nonlineMode_), mode(mode_), sparse(sparse_), format(format_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), compute_mode(compute_mode_), strategy(strategy_), workspace_limit(workspace_limit_), dtype(dtype_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ConvBias(::megdnn::param::ConvBias packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1, ::megdnn::DType dtype_): nonlineMode(packed_param_0.nonlineMode), mode(packed_param_0.mode), sparse(packed_param_0.sparse), format(packed_param_0.format), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), compute_mode(packed_param_0.compute_mode), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit), dtype(dtype_) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::ConvBias param() const { + return {nonlineMode, mode, sparse, format, pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, compute_mode}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class Convolution : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Convolution::Mode; + using Sparse = ::megdnn::param::Convolution::Sparse; + using Format = ::megdnn::param::Convolution::Format; + using ComputeMode = ::megdnn::param::Convolution::ComputeMode; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + Mode mode = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + Sparse sparse = ::megdnn::param::Convolution::Sparse::DENSE; + Format format = ::megdnn::param::Convolution::Format::NCHW; + ComputeMode compute_mode = ::megdnn::param::Convolution::ComputeMode::DEFAULT; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + Convolution() = default; + Convolution(Mode mode_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, Sparse sparse_, Format format_, ComputeMode compute_mode_, Strategy strategy_, uint64_t workspace_limit_, std::string scope_ = {}): mode(mode_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), sparse(sparse_), format(format_), compute_mode(compute_mode_), strategy(strategy_), workspace_limit(workspace_limit_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + Convolution(::megdnn::param::Convolution packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1): mode(packed_param_0.mode), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), sparse(packed_param_0.sparse), format(packed_param_0.format), compute_mode(packed_param_0.compute_mode), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::Convolution param() const { + return {mode, pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, sparse, format, compute_mode}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class Convolution3D : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Convolution3D::Mode; + using Sparse = ::megdnn::param::Convolution3D::Sparse; + using DataType = ::megdnn::param::Convolution3D::DataType; + using Format = ::megdnn::param::Convolution3D::Format; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + Mode mode = ::megdnn::param::Convolution3D::Mode::CROSS_CORRELATION; + uint32_t pad_d = 0; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_d = 1; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_d = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + Sparse sparse = ::megdnn::param::Convolution3D::Sparse::DENSE; + DataType data_type = ::megdnn::param::Convolution3D::DataType::FLOAT; + Format format = ::megdnn::param::Convolution3D::Format::NCDHW; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + Convolution3D() = default; + Convolution3D(Mode mode_, uint32_t pad_d_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_d_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_d_, uint32_t dilate_h_, uint32_t dilate_w_, Sparse sparse_, DataType data_type_, Format format_, Strategy strategy_, uint64_t workspace_limit_, std::string scope_ = {}): mode(mode_), pad_d(pad_d_), pad_h(pad_h_), pad_w(pad_w_), stride_d(stride_d_), stride_h(stride_h_), stride_w(stride_w_), dilate_d(dilate_d_), dilate_h(dilate_h_), dilate_w(dilate_w_), sparse(sparse_), data_type(data_type_), format(format_), strategy(strategy_), workspace_limit(workspace_limit_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + Convolution3D(::megdnn::param::Convolution3D packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1): mode(packed_param_0.mode), pad_d(packed_param_0.pad_d), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_d(packed_param_0.stride_d), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_d(packed_param_0.dilate_d), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), sparse(packed_param_0.sparse), data_type(packed_param_0.data_type), format(packed_param_0.format), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::Convolution3D param() const { + return {mode, pad_d, pad_h, pad_w, stride_d, stride_h, stride_w, dilate_d, dilate_h, dilate_w, sparse, data_type, format}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class Convolution3DBackwardData : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Convolution3D::Mode; + using Sparse = ::megdnn::param::Convolution3D::Sparse; + using DataType = ::megdnn::param::Convolution3D::DataType; + using Format = ::megdnn::param::Convolution3D::Format; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + Mode mode = ::megdnn::param::Convolution3D::Mode::CROSS_CORRELATION; + uint32_t pad_d = 0; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_d = 1; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_d = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + Sparse sparse = ::megdnn::param::Convolution3D::Sparse::DENSE; + DataType data_type = ::megdnn::param::Convolution3D::DataType::FLOAT; + Format format = ::megdnn::param::Convolution3D::Format::NCDHW; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + Convolution3DBackwardData() = default; + Convolution3DBackwardData(Mode mode_, uint32_t pad_d_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_d_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_d_, uint32_t dilate_h_, uint32_t dilate_w_, Sparse sparse_, DataType data_type_, Format format_, Strategy strategy_, uint64_t workspace_limit_, std::string scope_ = {}): mode(mode_), pad_d(pad_d_), pad_h(pad_h_), pad_w(pad_w_), stride_d(stride_d_), stride_h(stride_h_), stride_w(stride_w_), dilate_d(dilate_d_), dilate_h(dilate_h_), dilate_w(dilate_w_), sparse(sparse_), data_type(data_type_), format(format_), strategy(strategy_), workspace_limit(workspace_limit_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + Convolution3DBackwardData(::megdnn::param::Convolution3D packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1): mode(packed_param_0.mode), pad_d(packed_param_0.pad_d), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_d(packed_param_0.stride_d), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_d(packed_param_0.dilate_d), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), sparse(packed_param_0.sparse), data_type(packed_param_0.data_type), format(packed_param_0.format), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::Convolution3D param() const { + return {mode, pad_d, pad_h, pad_w, stride_d, stride_h, stride_w, dilate_d, dilate_h, dilate_w, sparse, data_type, format}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class ConvolutionBackwardData : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Convolution::Mode; + using Sparse = ::megdnn::param::Convolution::Sparse; + using Format = ::megdnn::param::Convolution::Format; + using ComputeMode = ::megdnn::param::Convolution::ComputeMode; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + Mode mode = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + Sparse sparse = ::megdnn::param::Convolution::Sparse::DENSE; + Format format = ::megdnn::param::Convolution::Format::NCHW; + ComputeMode compute_mode = ::megdnn::param::Convolution::ComputeMode::DEFAULT; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + ::megdnn::DType dtype; + ConvolutionBackwardData() = default; + ConvolutionBackwardData(Mode mode_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, Sparse sparse_, Format format_, ComputeMode compute_mode_, Strategy strategy_, uint64_t workspace_limit_, ::megdnn::DType dtype_, std::string scope_ = {}): mode(mode_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), sparse(sparse_), format(format_), compute_mode(compute_mode_), strategy(strategy_), workspace_limit(workspace_limit_), dtype(dtype_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ConvolutionBackwardData(::megdnn::param::Convolution packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1, ::megdnn::DType dtype_): mode(packed_param_0.mode), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), sparse(packed_param_0.sparse), format(packed_param_0.format), compute_mode(packed_param_0.compute_mode), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit), dtype(dtype_) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::Convolution param() const { + return {mode, pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, sparse, format, compute_mode}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class Copy : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + ::mgb::CompNode comp_node; + Copy() = default; + Copy(::mgb::CompNode comp_node_, std::string scope_ = {}): comp_node(comp_node_) { set_scope(scope_); } +}; + +class Correlation : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Format = ::megdnn::param::Correlation::Format; + Format format = ::megdnn::param::Correlation::Format::NCHW; + uint32_t kernel_size = 1; + uint32_t max_displacement = 1; + uint32_t stride1 = 1; + uint32_t stride2 = 1; + uint32_t pad_size = 0; + bool is_multiply = true; + Correlation() = default; + Correlation(Format format_, uint32_t kernel_size_, uint32_t max_displacement_, uint32_t stride1_, uint32_t stride2_, uint32_t pad_size_, bool is_multiply_, std::string scope_ = {}): format(format_), kernel_size(kernel_size_), max_displacement(max_displacement_), stride1(stride1_), stride2(stride2_), pad_size(pad_size_), is_multiply(is_multiply_) { set_scope(scope_); } + Correlation(::megdnn::param::Correlation packed_param_0): format(packed_param_0.format), kernel_size(packed_param_0.kernel_size), max_displacement(packed_param_0.max_displacement), stride1(packed_param_0.stride1), stride2(packed_param_0.stride2), pad_size(packed_param_0.pad_size), is_multiply(packed_param_0.is_multiply) {} + ::megdnn::param::Correlation param() const { + return {format, kernel_size, max_displacement, stride1, stride2, pad_size, is_multiply}; + } +}; + +class Cumsum : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = 2147483647; + bool exclusive = true; + bool reverse = false; + Cumsum() = default; + Cumsum(int32_t axis_, bool exclusive_, bool reverse_, std::string scope_ = {}): axis(axis_), exclusive(exclusive_), reverse(reverse_) { set_scope(scope_); } + Cumsum(::megdnn::param::Cumsum packed_param_0): axis(packed_param_0.axis), exclusive(packed_param_0.exclusive), reverse(packed_param_0.reverse) {} + ::megdnn::param::Cumsum param() const { + return {axis, exclusive, reverse}; + } +}; + +class CvtColor : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::CvtColor::Mode; + Mode mode = ::megdnn::param::CvtColor::Mode::RGB2GRAY; + CvtColor() = default; + CvtColor(Mode mode_, std::string scope_ = {}): mode(mode_) { set_scope(scope_); } + CvtColor(::megdnn::param::CvtColor packed_param_0): mode(packed_param_0.mode) {} + ::megdnn::param::CvtColor param() const { + return {mode}; + } +}; + +class DeformableConv : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Convolution::Mode; + using Sparse = ::megdnn::param::Convolution::Sparse; + using Format = ::megdnn::param::Convolution::Format; + using ComputeMode = ::megdnn::param::Convolution::ComputeMode; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + Mode mode = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + Sparse sparse = ::megdnn::param::Convolution::Sparse::DENSE; + Format format = ::megdnn::param::Convolution::Format::NCHW; + ComputeMode compute_mode = ::megdnn::param::Convolution::ComputeMode::DEFAULT; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + DeformableConv() = default; + DeformableConv(Mode mode_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, Sparse sparse_, Format format_, ComputeMode compute_mode_, Strategy strategy_, uint64_t workspace_limit_, std::string scope_ = {}): mode(mode_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), sparse(sparse_), format(format_), compute_mode(compute_mode_), strategy(strategy_), workspace_limit(workspace_limit_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + DeformableConv(::megdnn::param::Convolution packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1): mode(packed_param_0.mode), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), sparse(packed_param_0.sparse), format(packed_param_0.format), compute_mode(packed_param_0.compute_mode), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::Convolution param() const { + return {mode, pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, sparse, format, compute_mode}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class DeformablePSROIPooling : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + bool no_trans = true; + float spatial_scale = 1; + float trans_std = 1; + uint32_t pooled_h = 1; + uint32_t pooled_w = 1; + uint32_t part_size = 1; + uint32_t sample_per_part = 1; + DeformablePSROIPooling() = default; + DeformablePSROIPooling(bool no_trans_, float spatial_scale_, float trans_std_, uint32_t pooled_h_, uint32_t pooled_w_, uint32_t part_size_, uint32_t sample_per_part_, std::string scope_ = {}): no_trans(no_trans_), spatial_scale(spatial_scale_), trans_std(trans_std_), pooled_h(pooled_h_), pooled_w(pooled_w_), part_size(part_size_), sample_per_part(sample_per_part_) { set_scope(scope_); } + DeformablePSROIPooling(::megdnn::param::DeformablePSROIPooling packed_param_0): no_trans(packed_param_0.no_trans), spatial_scale(packed_param_0.spatial_scale), trans_std(packed_param_0.trans_std), pooled_h(packed_param_0.pooled_h), pooled_w(packed_param_0.pooled_w), part_size(packed_param_0.part_size), sample_per_part(packed_param_0.sample_per_part) {} + ::megdnn::param::DeformablePSROIPooling param() const { + return {no_trans, spatial_scale, trans_std, pooled_h, pooled_w, part_size, sample_per_part}; + } +}; + +class Diag : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t k = 0; + Diag() = default; + Diag(int32_t k_, std::string scope_ = {}): k(k_) { set_scope(scope_); } + Diag(::megdnn::param::Diag packed_param_0): k(packed_param_0.k) {} + ::megdnn::param::Diag param() const { + return {k}; + } +}; + +class Dimshuffle : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector pattern; + Dimshuffle() = default; + Dimshuffle(std::vector pattern_, std::string scope_ = {}): pattern(pattern_) { set_scope(scope_); } +}; + +class Dot : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + Dot() = default; + Dot(::megdnn::param::Empty) {} + ::megdnn::param::Empty param() const { + return {}; + } +}; + +class Dropout : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + float drop_prob = 0; + uint64_t seed = 0; + size_t handle; + Dropout() = default; + Dropout(float drop_prob_, uint64_t seed_, size_t handle_, std::string scope_ = {}): drop_prob(drop_prob_), seed(seed_), handle(handle_) { set_scope(scope_); } + Dropout(::megdnn::param::Dropout packed_param_0, size_t handle_): drop_prob(packed_param_0.drop_prob), seed(packed_param_0.seed), handle(handle_) {} + ::megdnn::param::Dropout param() const { + return {drop_prob, seed}; + } +}; + +class Elemwise : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Elemwise::Mode; + Mode mode = ::megdnn::param::Elemwise::Mode::RELU; + Elemwise() = default; + Elemwise(Mode mode_, std::string scope_ = {}): mode(mode_) { set_scope(scope_); } + Elemwise(::megdnn::param::Elemwise packed_param_0): mode(packed_param_0.mode) {} + ::megdnn::param::Elemwise param() const { + return {mode}; + } +}; + + +template <> +struct ToStringTrait { + std::string operator()(Elemwise::Mode e) const { + switch (e) { + case Elemwise::Mode::RELU: return "RELU"; +case Elemwise::Mode::ABS: return "ABS"; +case Elemwise::Mode::ACOS: return "ACOS"; +case Elemwise::Mode::ASIN: return "ASIN"; +case Elemwise::Mode::CEIL: return "CEIL"; +case Elemwise::Mode::COS: return "COS"; +case Elemwise::Mode::EXP: return "EXP"; +case Elemwise::Mode::EXPM1: return "EXPM1"; +case Elemwise::Mode::FLOOR: return "FLOOR"; +case Elemwise::Mode::LOG: return "LOG"; +case Elemwise::Mode::LOG1P: return "LOG1P"; +case Elemwise::Mode::NEGATE: return "NEGATE"; +case Elemwise::Mode::SIGMOID: return "SIGMOID"; +case Elemwise::Mode::SIN: return "SIN"; +case Elemwise::Mode::TANH: return "TANH"; +case Elemwise::Mode::ABS_GRAD: return "ABS_GRAD"; +case Elemwise::Mode::ADD: return "ADD"; +case Elemwise::Mode::FLOOR_DIV: return "FLOOR_DIV"; +case Elemwise::Mode::MAX: return "MAX"; +case Elemwise::Mode::MIN: return "MIN"; +case Elemwise::Mode::MOD: return "MOD"; +case Elemwise::Mode::MUL: return "MUL"; +case Elemwise::Mode::POW: return "POW"; +case Elemwise::Mode::SIGMOID_GRAD: return "SIGMOID_GRAD"; +case Elemwise::Mode::SUB: return "SUB"; +case Elemwise::Mode::SWITCH_GT0: return "SWITCH_GT0"; +case Elemwise::Mode::TANH_GRAD: return "TANH_GRAD"; +case Elemwise::Mode::TRUE_DIV: return "TRUE_DIV"; +case Elemwise::Mode::LOG_SUM_EXP: return "LOG_SUM_EXP"; +case Elemwise::Mode::LT: return "LT"; +case Elemwise::Mode::LEQ: return "LEQ"; +case Elemwise::Mode::EQ: return "EQ"; +case Elemwise::Mode::SHL: return "SHL"; +case Elemwise::Mode::SHR: return "SHR"; +case Elemwise::Mode::COND_LEQ_MOV: return "COND_LEQ_MOV"; +case Elemwise::Mode::FUSE_MUL_ADD3: return "FUSE_MUL_ADD3"; +case Elemwise::Mode::FUSE_MUL_ADD4: return "FUSE_MUL_ADD4"; +case Elemwise::Mode::FUSE_ADD_RELU: return "FUSE_ADD_RELU"; +case Elemwise::Mode::FUSE_ADD_SIGMOID: return "FUSE_ADD_SIGMOID"; +case Elemwise::Mode::FUSE_ADD_TANH: return "FUSE_ADD_TANH"; +case Elemwise::Mode::FAST_TANH: return "FAST_TANH"; +case Elemwise::Mode::FAST_TANH_GRAD: return "FAST_TANH_GRAD"; +case Elemwise::Mode::ROUND: return "ROUND"; +case Elemwise::Mode::RMULH: return "RMULH"; +case Elemwise::Mode::ATAN2: return "ATAN2"; +case Elemwise::Mode::ERF: return "ERF"; +case Elemwise::Mode::ERFINV: return "ERFINV"; +case Elemwise::Mode::ERFC: return "ERFC"; +case Elemwise::Mode::ERFCINV: return "ERFCINV"; +case Elemwise::Mode::H_SWISH: return "H_SWISH"; +case Elemwise::Mode::H_SWISH_GRAD: return "H_SWISH_GRAD"; +case Elemwise::Mode::FUSE_ADD_H_SWISH: return "FUSE_ADD_H_SWISH"; +case Elemwise::Mode::NOT: return "NOT"; +case Elemwise::Mode::AND: return "AND"; +case Elemwise::Mode::OR: return "OR"; +case Elemwise::Mode::XOR: return "XOR"; +case Elemwise::Mode::SILU: return "SILU"; +case Elemwise::Mode::SILU_GRAD: return "SILU_GRAD"; +case Elemwise::Mode::GELU: return "GELU"; +case Elemwise::Mode::GELU_GRAD: return "GELU_GRAD"; +case Elemwise::Mode::COND_LT_MOV: return "COND_LT_MOV"; + default: + return "Elemwise::Mode::Unknown"; + } + } +}; +class ElemwiseMultiType : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::ElemwiseMultiType::Mode; + Mode mode = ::megdnn::param::ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32; + ::megdnn::DType dtype; + ElemwiseMultiType() = default; + ElemwiseMultiType(Mode mode_, ::megdnn::DType dtype_, std::string scope_ = {}): mode(mode_), dtype(dtype_) { set_scope(scope_); } + ElemwiseMultiType(::megdnn::param::ElemwiseMultiType packed_param_0, ::megdnn::DType dtype_): mode(packed_param_0.mode), dtype(dtype_) {} + ::megdnn::param::ElemwiseMultiType param() const { + return {mode}; + } +}; + + +template <> +struct ToStringTrait { + std::string operator()(ElemwiseMultiType::Mode e) const { + switch (e) { + case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32: return "FUSE_MUL_ADD3_INT16x32x32x32"; +case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8: return "FUSE_MUL_ADD3_IXxF32xF32xI8"; +case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8: return "ROUND_SHR_SATURATE_IXxI8xI8"; +case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8: return "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8"; +case ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8: return "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8"; +case ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16: return "ROUND_SHR_SATURATE_IXxI8xI16"; +case ElemwiseMultiType::Mode::QADD: return "QADD"; +case ElemwiseMultiType::Mode::QFUSE_ADD_RELU: return "QFUSE_ADD_RELU"; +case ElemwiseMultiType::Mode::QMUL: return "QMUL"; +case ElemwiseMultiType::Mode::QMIN: return "QMIN"; +case ElemwiseMultiType::Mode::QMAX: return "QMAX"; +case ElemwiseMultiType::Mode::QSUB: return "QSUB"; +case ElemwiseMultiType::Mode::QTRUE_DIV: return "QTRUE_DIV"; +case ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID: return "QFUSE_ADD_SIGMOID"; +case ElemwiseMultiType::Mode::QFUSE_ADD_TANH: return "QFUSE_ADD_TANH"; +case ElemwiseMultiType::Mode::QRELU: return "QRELU"; +case ElemwiseMultiType::Mode::QABS: return "QABS"; +case ElemwiseMultiType::Mode::QSIGMOID: return "QSIGMOID"; +case ElemwiseMultiType::Mode::QEXP: return "QEXP"; +case ElemwiseMultiType::Mode::QTANH: return "QTANH"; +case ElemwiseMultiType::Mode::QFUSE_MUL_ADD3: return "QFUSE_MUL_ADD3"; +case ElemwiseMultiType::Mode::QFAST_TANH: return "QFAST_TANH"; +case ElemwiseMultiType::Mode::QNEGATE: return "QNEGATE"; +case ElemwiseMultiType::Mode::QACOS: return "QACOS"; +case ElemwiseMultiType::Mode::QASIN: return "QASIN"; +case ElemwiseMultiType::Mode::QCEIL: return "QCEIL"; +case ElemwiseMultiType::Mode::QCOS: return "QCOS"; +case ElemwiseMultiType::Mode::QEXPM1: return "QEXPM1"; +case ElemwiseMultiType::Mode::QFLOOR: return "QFLOOR"; +case ElemwiseMultiType::Mode::QLOG: return "QLOG"; +case ElemwiseMultiType::Mode::QLOG1P: return "QLOG1P"; +case ElemwiseMultiType::Mode::QSIN: return "QSIN"; +case ElemwiseMultiType::Mode::QROUND: return "QROUND"; +case ElemwiseMultiType::Mode::QERF: return "QERF"; +case ElemwiseMultiType::Mode::QERFINV: return "QERFINV"; +case ElemwiseMultiType::Mode::QERFC: return "QERFC"; +case ElemwiseMultiType::Mode::QERFCINV: return "QERFCINV"; +case ElemwiseMultiType::Mode::QABS_GRAD: return "QABS_GRAD"; +case ElemwiseMultiType::Mode::QFLOOR_DIV: return "QFLOOR_DIV"; +case ElemwiseMultiType::Mode::QMOD: return "QMOD"; +case ElemwiseMultiType::Mode::QSIGMOID_GRAD: return "QSIGMOID_GRAD"; +case ElemwiseMultiType::Mode::QSWITCH_GT0: return "QSWITCH_GT0"; +case ElemwiseMultiType::Mode::QTANH_GRAD: return "QTANH_GRAD"; +case ElemwiseMultiType::Mode::QLT: return "QLT"; +case ElemwiseMultiType::Mode::QLEQ: return "QLEQ"; +case ElemwiseMultiType::Mode::QEQ: return "QEQ"; +case ElemwiseMultiType::Mode::QPOW: return "QPOW"; +case ElemwiseMultiType::Mode::QLOG_SUM_EXP: return "QLOG_SUM_EXP"; +case ElemwiseMultiType::Mode::QFAST_TANH_GRAD: return "QFAST_TANH_GRAD"; +case ElemwiseMultiType::Mode::QATAN2: return "QATAN2"; +case ElemwiseMultiType::Mode::QCOND_LEQ_MOV: return "QCOND_LEQ_MOV"; +case ElemwiseMultiType::Mode::QH_SWISH: return "QH_SWISH"; +case ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH: return "QFUSE_ADD_H_SWISH"; +case ElemwiseMultiType::Mode::QH_SWISH_GRAD: return "QH_SWISH_GRAD"; +case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32: return "FUSE_MUL_ADD3_INT16xF32xF32xF32"; +case ElemwiseMultiType::Mode::MUL_INT16xF32xF32: return "MUL_INT16xF32xF32"; +case ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32: return "FUSE_MUL_ADD3_UINT8xF32xF32xF32"; +case ElemwiseMultiType::Mode::QCOND_LT_MOV: return "QCOND_LT_MOV"; + default: + return "ElemwiseMultiType::Mode::Unknown"; + } + } +}; +class ExternOpr : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> output_shapes; + std::string name; + std::string data; + size_t data_len; + std::vector<::megdnn::DType> output_dtypes; + ExternOpr() = default; + ExternOpr(std::vector> output_shapes_, std::string name_, std::string data_, size_t data_len_, std::vector<::megdnn::DType> output_dtypes_, std::string scope_ = {}): output_shapes(output_shapes_), name(name_), data(data_), data_len(data_len_), output_dtypes(output_dtypes_) { set_scope(scope_); } +}; + +class Eye : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t k = 0; + ::megdnn::DType dtype = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32); + ::mgb::CompNode comp_node; + Eye() = default; + Eye(int32_t k_, ::megdnn::DType dtype_, ::mgb::CompNode comp_node_, std::string scope_ = {}): k(k_), dtype(dtype_), comp_node(comp_node_) { set_scope(scope_); } +}; + +class FakeQuant : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t qmin = -2147483648; + int32_t qmax = 2147483647; + FakeQuant() = default; + FakeQuant(int32_t qmin_, int32_t qmax_, std::string scope_ = {}): qmin(qmin_), qmax(qmax_) { set_scope(scope_); } + FakeQuant(::megdnn::param::FakeQuant packed_param_0): qmin(packed_param_0.qmin), qmax(packed_param_0.qmax) {} + ::megdnn::param::FakeQuant param() const { + return {qmin, qmax}; + } +}; + +class FastpathCopy : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + FastpathCopy() = default; +}; + +class GammaRNG : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint64_t seed = 0; + size_t handle; + GammaRNG() = default; + GammaRNG(uint64_t seed_, size_t handle_, std::string scope_ = {}): seed(seed_), handle(handle_) { set_scope(scope_); } + GammaRNG(::megdnn::param::GammaRNG packed_param_0, size_t handle_): seed(packed_param_0.seed), handle(handle_) {} + ::megdnn::param::GammaRNG param() const { + return {seed}; + } +}; + +class GaussianRNG : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint64_t seed = 0; + float mean = 0; + float std = 1; + ::megdnn::DType dtype = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32); + size_t handle; + GaussianRNG() = default; + GaussianRNG(uint64_t seed_, float mean_, float std_, ::megdnn::DType dtype_, size_t handle_, std::string scope_ = {}): seed(seed_), mean(mean_), std(std_), dtype(dtype_), handle(handle_) { set_scope(scope_); } +}; + +class GetVarShape : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = ::megdnn::param::OptionalAxisV1::INVALID_AXIS; + GetVarShape() = default; + GetVarShape(int32_t axis_, std::string scope_ = {}): axis(axis_) { set_scope(scope_); } + GetVarShape(::megdnn::param::OptionalAxisV1 packed_param_0): axis(packed_param_0.axis) {} + ::megdnn::param::OptionalAxisV1 param() const { + return {axis}; + } +}; + +class GroupLocal : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Convolution::Mode; + using Sparse = ::megdnn::param::Convolution::Sparse; + using Format = ::megdnn::param::Convolution::Format; + using ComputeMode = ::megdnn::param::Convolution::ComputeMode; + Mode mode = ::megdnn::param::Convolution::Mode::CROSS_CORRELATION; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + Sparse sparse = ::megdnn::param::Convolution::Sparse::DENSE; + Format format = ::megdnn::param::Convolution::Format::NCHW; + ComputeMode compute_mode = ::megdnn::param::Convolution::ComputeMode::DEFAULT; + GroupLocal() = default; + GroupLocal(Mode mode_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, Sparse sparse_, Format format_, ComputeMode compute_mode_, std::string scope_ = {}): mode(mode_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), sparse(sparse_), format(format_), compute_mode(compute_mode_) { set_scope(scope_); } + GroupLocal(::megdnn::param::Convolution packed_param_0): mode(packed_param_0.mode), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), sparse(packed_param_0.sparse), format(packed_param_0.format), compute_mode(packed_param_0.compute_mode) {} + ::megdnn::param::Convolution param() const { + return {mode, pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, sparse, format, compute_mode}; + } +}; + +class Identity : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + Identity() = default; +}; + +class Images2Neibs : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + uint32_t window_h = 3; + uint32_t window_w = 3; + Images2Neibs() = default; + Images2Neibs(uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, uint32_t window_h_, uint32_t window_w_, std::string scope_ = {}): pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), window_h(window_h_), window_w(window_w_) { set_scope(scope_); } + Images2Neibs(::megdnn::param::Images2Neibs packed_param_0): pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), window_h(packed_param_0.window_h), window_w(packed_param_0.window_w) {} + ::megdnn::param::Images2Neibs param() const { + return {pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, window_h, window_w}; + } +}; + +class IncrMeshIndexing : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + IncrMeshIndexing() = default; + IncrMeshIndexing(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class IncrSubtensor : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + IncrSubtensor() = default; + IncrSubtensor(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class IndexingIncrMultiAxisVec : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + IndexingIncrMultiAxisVec() = default; + IndexingIncrMultiAxisVec(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class IndexingMultiAxisVec : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + IndexingMultiAxisVec() = default; + IndexingMultiAxisVec(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class IndexingOneHot : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = 0; + int32_t ndim; + IndexingOneHot() = default; + IndexingOneHot(int32_t axis_, int32_t ndim_, std::string scope_ = {}): axis(axis_), ndim(ndim_) { set_scope(scope_); } + IndexingOneHot(::megdnn::param::Axis packed_param_0, int32_t ndim_): axis(packed_param_0.axis), ndim(ndim_) {} + ::megdnn::param::Axis param() const { + return {axis}; + } +}; + +class IndexingSetMultiAxisVec : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + IndexingSetMultiAxisVec() = default; + IndexingSetMultiAxisVec(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class IndexingSetOneHot : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = 0; + int32_t ndim; + IndexingSetOneHot() = default; + IndexingSetOneHot(int32_t axis_, int32_t ndim_, std::string scope_ = {}): axis(axis_), ndim(ndim_) { set_scope(scope_); } + IndexingSetOneHot(::megdnn::param::Axis packed_param_0, int32_t ndim_): axis(packed_param_0.axis), ndim(ndim_) {} + ::megdnn::param::Axis param() const { + return {axis}; + } +}; + +class InplaceAdd : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + InplaceAdd() = default; + InplaceAdd(::megdnn::param::Empty) {} + ::megdnn::param::Empty param() const { + return {}; + } +}; + +class LAMBUpdate : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + float beta_1 = 1.f; + float beta_2 = 1.f; + float step = 1.f; + float lr = 1.f; + float weight_decay = 1.f; + float eps = 1.f; + bool bias_correction = true; + bool always_adapt = false; + LAMBUpdate() = default; + LAMBUpdate(float beta_1_, float beta_2_, float step_, float lr_, float weight_decay_, float eps_, bool bias_correction_, bool always_adapt_, std::string scope_ = {}): beta_1(beta_1_), beta_2(beta_2_), step(step_), lr(lr_), weight_decay(weight_decay_), eps(eps_), bias_correction(bias_correction_), always_adapt(always_adapt_) { set_scope(scope_); } + LAMBUpdate(::megdnn::param::LAMBUpdate packed_param_0): beta_1(packed_param_0.beta_1), beta_2(packed_param_0.beta_2), step(packed_param_0.step), lr(packed_param_0.lr), weight_decay(packed_param_0.weight_decay), eps(packed_param_0.eps), bias_correction(packed_param_0.bias_correction), always_adapt(packed_param_0.always_adapt) {} + ::megdnn::param::LAMBUpdate param() const { + return {beta_1, beta_2, step, lr, weight_decay, eps, bias_correction, always_adapt}; + } +}; + +class LRN : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint32_t n = 5; + float k = 2.f; + float alpha = 1e-4f; + float beta = 0.75f; + LRN() = default; + LRN(uint32_t n_, float k_, float alpha_, float beta_, std::string scope_ = {}): n(n_), k(k_), alpha(alpha_), beta(beta_) { set_scope(scope_); } + LRN(::megdnn::param::LRN packed_param_0): n(packed_param_0.n), k(packed_param_0.k), alpha(packed_param_0.alpha), beta(packed_param_0.beta) {} + ::megdnn::param::LRN param() const { + return {n, k, alpha, beta}; + } +}; + +class LSQ : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t qmin = -2147483648; + int32_t qmax = 2147483647; + LSQ() = default; + LSQ(int32_t qmin_, int32_t qmax_, std::string scope_ = {}): qmin(qmin_), qmax(qmax_) { set_scope(scope_); } + LSQ(::megdnn::param::LSQ packed_param_0): qmin(packed_param_0.qmin), qmax(packed_param_0.qmax) {} + ::megdnn::param::LSQ param() const { + return {qmin, qmax}; + } +}; + +class LSTM : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using FwdMode = ::megdnn::param::LSTM::FwdMode; + uint32_t num_layers = 1; + bool bidirectional = false; + bool bias = true; + uint32_t hidden_size = 128; + uint32_t proj_size = 0; + float dropout = 0.f; + FwdMode fwd_mode = ::megdnn::param::LSTM::FwdMode::TRAINING; + LSTM() = default; + LSTM(uint32_t num_layers_, bool bidirectional_, bool bias_, uint32_t hidden_size_, uint32_t proj_size_, float dropout_, FwdMode fwd_mode_, std::string scope_ = {}): num_layers(num_layers_), bidirectional(bidirectional_), bias(bias_), hidden_size(hidden_size_), proj_size(proj_size_), dropout(dropout_), fwd_mode(fwd_mode_) { set_scope(scope_); } + LSTM(::megdnn::param::LSTM packed_param_0): num_layers(packed_param_0.num_layers), bidirectional(packed_param_0.bidirectional), bias(packed_param_0.bias), hidden_size(packed_param_0.hidden_size), proj_size(packed_param_0.proj_size), dropout(packed_param_0.dropout), fwd_mode(packed_param_0.fwd_mode) {} + ::megdnn::param::LSTM param() const { + return {num_layers, bidirectional, bias, hidden_size, proj_size, dropout, fwd_mode}; + } +}; + +class LSTMCell : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + LSTMCell() = default; + LSTMCell(::megdnn::param::Empty) {} + ::megdnn::param::Empty param() const { + return {}; + } +}; + +class LayerNorm : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + bool affine = true; + float eps = 1e-5f; + uint64_t normalized_dim = 1; + uint64_t normalized_size = 1; + LayerNorm() = default; + LayerNorm(bool affine_, float eps_, uint64_t normalized_dim_, uint64_t normalized_size_, std::string scope_ = {}): affine(affine_), eps(eps_), normalized_dim(normalized_dim_), normalized_size(normalized_size_) { set_scope(scope_); } + LayerNorm(::megdnn::param::LayerNorm packed_param_0): affine(packed_param_0.affine), eps(packed_param_0.eps), normalized_dim(packed_param_0.normalized_dim), normalized_size(packed_param_0.normalized_size) {} + ::megdnn::param::LayerNorm param() const { + return {affine, eps, normalized_dim, normalized_size}; + } +}; + +class Linspace : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + bool endpoint = true; + ::mgb::CompNode comp_node; + Linspace() = default; + Linspace(bool endpoint_, ::mgb::CompNode comp_node_, std::string scope_ = {}): endpoint(endpoint_), comp_node(comp_node_) { set_scope(scope_); } + Linspace(::megdnn::param::Linspace packed_param_0, ::mgb::CompNode comp_node_): endpoint(packed_param_0.endpoint), comp_node(comp_node_) {} + ::megdnn::param::Linspace param() const { + return {endpoint}; + } +}; + +class MagicMindRuntime : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::string buf; + size_t buf_size; + MagicMindRuntime() = default; + MagicMindRuntime(std::string buf_, size_t buf_size_, std::string scope_ = {}): buf(buf_), buf_size(buf_size_) { set_scope(scope_); } +}; + +class MatrixInverse : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + MatrixInverse() = default; + MatrixInverse(::megdnn::param::Empty) {} + ::megdnn::param::Empty param() const { + return {}; + } +}; + +class MatrixMul : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using ComputeMode = ::megdnn::param::MatrixMul::ComputeMode; + using Format = ::megdnn::param::MatrixMul::Format; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + bool transposeA = false; + bool transposeB = false; + ComputeMode compute_mode = ::megdnn::param::MatrixMul::ComputeMode::DEFAULT; + Format format = ::megdnn::param::MatrixMul::Format::DEFAULT; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + uint32_t dimA; + uint32_t dimB; + MatrixMul() = default; + MatrixMul(bool transposeA_, bool transposeB_, ComputeMode compute_mode_, Format format_, Strategy strategy_, uint64_t workspace_limit_, uint32_t dimA_, uint32_t dimB_, std::string scope_ = {}): transposeA(transposeA_), transposeB(transposeB_), compute_mode(compute_mode_), format(format_), strategy(strategy_), workspace_limit(workspace_limit_), dimA(dimA_), dimB(dimB_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + MatrixMul(::megdnn::param::MatrixMul packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1, uint32_t dimA_, uint32_t dimB_): transposeA(packed_param_0.transposeA), transposeB(packed_param_0.transposeB), compute_mode(packed_param_0.compute_mode), format(packed_param_0.format), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit), dimA(dimA_), dimB(dimB_) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::MatrixMul param() const { + return {transposeA, transposeB, compute_mode, format}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class MeshIndexing : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + MeshIndexing() = default; + MeshIndexing(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class NMSKeep : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + float iou_thresh; + uint32_t max_output; + NMSKeep() = default; + NMSKeep(float iou_thresh_, uint32_t max_output_, std::string scope_ = {}): iou_thresh(iou_thresh_), max_output(max_output_) { set_scope(scope_); } +}; + +class NvOf : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint32_t precision = 1; + NvOf() = default; + NvOf(uint32_t precision_, std::string scope_ = {}): precision(precision_) { set_scope(scope_); } + NvOf(::megdnn::param::NvOf packed_param_0): precision(packed_param_0.precision) {} + ::megdnn::param::NvOf param() const { + return {precision}; + } +}; + +class Padding : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using PaddingMode = ::megdnn::param::Padding::PaddingMode; + uint32_t front_offset_dim0 = 0; + uint32_t front_offset_dim1 = 0; + uint32_t front_offset_dim2 = 0; + uint32_t front_offset_dim3 = 0; + uint32_t front_offset_dim4 = 0; + uint32_t front_offset_dim5 = 0; + uint32_t front_offset_dim6 = 0; + uint32_t back_offset_dim0 = 0; + uint32_t back_offset_dim1 = 0; + uint32_t back_offset_dim2 = 0; + uint32_t back_offset_dim3 = 0; + uint32_t back_offset_dim4 = 0; + uint32_t back_offset_dim5 = 0; + uint32_t back_offset_dim6 = 0; + float padding_val = 0; + PaddingMode padding_mode = ::megdnn::param::Padding::PaddingMode::CONSTANT; + Padding() = default; + Padding(uint32_t front_offset_dim0_, uint32_t front_offset_dim1_, uint32_t front_offset_dim2_, uint32_t front_offset_dim3_, uint32_t front_offset_dim4_, uint32_t front_offset_dim5_, uint32_t front_offset_dim6_, uint32_t back_offset_dim0_, uint32_t back_offset_dim1_, uint32_t back_offset_dim2_, uint32_t back_offset_dim3_, uint32_t back_offset_dim4_, uint32_t back_offset_dim5_, uint32_t back_offset_dim6_, float padding_val_, PaddingMode padding_mode_, std::string scope_ = {}): front_offset_dim0(front_offset_dim0_), front_offset_dim1(front_offset_dim1_), front_offset_dim2(front_offset_dim2_), front_offset_dim3(front_offset_dim3_), front_offset_dim4(front_offset_dim4_), front_offset_dim5(front_offset_dim5_), front_offset_dim6(front_offset_dim6_), back_offset_dim0(back_offset_dim0_), back_offset_dim1(back_offset_dim1_), back_offset_dim2(back_offset_dim2_), back_offset_dim3(back_offset_dim3_), back_offset_dim4(back_offset_dim4_), back_offset_dim5(back_offset_dim5_), back_offset_dim6(back_offset_dim6_), padding_val(padding_val_), padding_mode(padding_mode_) { set_scope(scope_); } + Padding(::megdnn::param::Padding packed_param_0): front_offset_dim0(packed_param_0.front_offset_dim0), front_offset_dim1(packed_param_0.front_offset_dim1), front_offset_dim2(packed_param_0.front_offset_dim2), front_offset_dim3(packed_param_0.front_offset_dim3), front_offset_dim4(packed_param_0.front_offset_dim4), front_offset_dim5(packed_param_0.front_offset_dim5), front_offset_dim6(packed_param_0.front_offset_dim6), back_offset_dim0(packed_param_0.back_offset_dim0), back_offset_dim1(packed_param_0.back_offset_dim1), back_offset_dim2(packed_param_0.back_offset_dim2), back_offset_dim3(packed_param_0.back_offset_dim3), back_offset_dim4(packed_param_0.back_offset_dim4), back_offset_dim5(packed_param_0.back_offset_dim5), back_offset_dim6(packed_param_0.back_offset_dim6), padding_val(packed_param_0.padding_val), padding_mode(packed_param_0.padding_mode) {} + ::megdnn::param::Padding param() const { + return {front_offset_dim0, front_offset_dim1, front_offset_dim2, front_offset_dim3, front_offset_dim4, front_offset_dim5, front_offset_dim6, back_offset_dim0, back_offset_dim1, back_offset_dim2, back_offset_dim3, back_offset_dim4, back_offset_dim5, back_offset_dim6, padding_val, padding_mode}; + } +}; + +class ParamPackConcat : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector offsets; + ParamPackConcat() = default; + ParamPackConcat(std::vector offsets_, std::string scope_ = {}): offsets(offsets_) { set_scope(scope_); } +}; + +class ParamPackSplit : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector offsets; + std::vector> shapes; + ParamPackSplit() = default; + ParamPackSplit(std::vector offsets_, std::vector> shapes_, std::string scope_ = {}): offsets(offsets_), shapes(shapes_) { set_scope(scope_); } +}; + +class PermutationRNG : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint64_t seed = 0; + ::megdnn::DType dtype = megdnn::DType::from_enum(megdnn::DTypeEnum::Int32); + size_t handle; + PermutationRNG() = default; + PermutationRNG(uint64_t seed_, ::megdnn::DType dtype_, size_t handle_, std::string scope_ = {}): seed(seed_), dtype(dtype_), handle(handle_) { set_scope(scope_); } +}; + +class PixelShuffle : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t factor; + PixelShuffle() = default; + PixelShuffle(int32_t factor_, std::string scope_ = {}): factor(factor_) { set_scope(scope_); } +}; + +class PixelShuffleBackward : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t factor; + PixelShuffleBackward() = default; + PixelShuffleBackward(int32_t factor_, std::string scope_ = {}): factor(factor_) { set_scope(scope_); } +}; + +class PoissonRNG : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint64_t seed = 0; + size_t handle; + PoissonRNG() = default; + PoissonRNG(uint64_t seed_, size_t handle_, std::string scope_ = {}): seed(seed_), handle(handle_) { set_scope(scope_); } + PoissonRNG(::megdnn::param::PoissonRNG packed_param_0, size_t handle_): seed(packed_param_0.seed), handle(handle_) {} + ::megdnn::param::PoissonRNG param() const { + return {seed}; + } +}; + +class Pooling : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Pooling::Mode; + using Format = ::megdnn::param::Pooling::Format; + using Strategy = ::megdnn::param::ExecutionPolicy::Strategy; + Mode mode = ::megdnn::param::Pooling::Mode::MAX; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 2; + uint32_t stride_w = 2; + uint32_t window_h = 2; + uint32_t window_w = 2; + Format format = ::megdnn::param::Pooling::Format::NCHW; + Strategy strategy = static_cast<::megdnn::param::ExecutionPolicy::Strategy>(1); + uint64_t workspace_limit = 18446744073709551615ull; + Pooling() = default; + Pooling(Mode mode_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t window_h_, uint32_t window_w_, Format format_, Strategy strategy_, uint64_t workspace_limit_, std::string scope_ = {}): mode(mode_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), window_h(window_h_), window_w(window_w_), format(format_), strategy(strategy_), workspace_limit(workspace_limit_) { + set_scope(scope_); + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + Pooling(::megdnn::param::Pooling packed_param_0, ::megdnn::param::ExecutionPolicy packed_param_1): mode(packed_param_0.mode), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), window_h(packed_param_0.window_h), window_w(packed_param_0.window_w), format(packed_param_0.format), strategy(packed_param_1.strategy), workspace_limit(packed_param_1.workspace_limit) { + mgb_assert(static_cast(strategy) <= uint32_t(8)); + } + ::megdnn::param::Pooling param() const { + return {mode, pad_h, pad_w, stride_h, stride_w, window_h, window_w, format}; + } + ::megdnn::param::ExecutionPolicy policy() const { + return {strategy, workspace_limit}; + } +}; + +class RNN : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using NonlineMode = ::megdnn::param::RNN::NonlineMode; + using FwdMode = ::megdnn::param::RNN::FwdMode; + uint32_t num_layers = 1; + bool bidirectional = false; + bool bias = true; + uint32_t hidden_size = 128; + float dropout = 0.f; + NonlineMode nonlineMode = ::megdnn::param::RNN::NonlineMode::IDENTITY; + FwdMode fwd_mode = ::megdnn::param::RNN::FwdMode::TRAINING; + RNN() = default; + RNN(uint32_t num_layers_, bool bidirectional_, bool bias_, uint32_t hidden_size_, float dropout_, NonlineMode nonlineMode_, FwdMode fwd_mode_, std::string scope_ = {}): num_layers(num_layers_), bidirectional(bidirectional_), bias(bias_), hidden_size(hidden_size_), dropout(dropout_), nonlineMode(nonlineMode_), fwd_mode(fwd_mode_) { set_scope(scope_); } + RNN(::megdnn::param::RNN packed_param_0): num_layers(packed_param_0.num_layers), bidirectional(packed_param_0.bidirectional), bias(packed_param_0.bias), hidden_size(packed_param_0.hidden_size), dropout(packed_param_0.dropout), nonlineMode(packed_param_0.nonlineMode), fwd_mode(packed_param_0.fwd_mode) {} + ::megdnn::param::RNN param() const { + return {num_layers, bidirectional, bias, hidden_size, dropout, nonlineMode, fwd_mode}; + } +}; + +class RNNCell : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using NonlineMode = ::megdnn::param::RNNCell::NonlineMode; + NonlineMode nonlineMode = ::megdnn::param::RNNCell::NonlineMode::IDENTITY; + RNNCell() = default; + RNNCell(NonlineMode nonlineMode_, std::string scope_ = {}): nonlineMode(nonlineMode_) { set_scope(scope_); } + RNNCell(::megdnn::param::RNNCell packed_param_0): nonlineMode(packed_param_0.nonlineMode) {} + ::megdnn::param::RNNCell param() const { + return {nonlineMode}; + } +}; + +class ROIAlign : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::ROIAlign::Mode; + using Format = ::megdnn::param::ROIAlign::Format; + Mode mode = ::megdnn::param::ROIAlign::Mode::MAX; + Format format = ::megdnn::param::ROIAlign::Format::NCHW; + float spatial_scale = 1.0; + float offset = 0.0; + uint32_t pooled_height = 1; + uint32_t pooled_width = 1; + uint32_t sample_height = 2; + uint32_t sample_width = 2; + ROIAlign() = default; + ROIAlign(Mode mode_, Format format_, float spatial_scale_, float offset_, uint32_t pooled_height_, uint32_t pooled_width_, uint32_t sample_height_, uint32_t sample_width_, std::string scope_ = {}): mode(mode_), format(format_), spatial_scale(spatial_scale_), offset(offset_), pooled_height(pooled_height_), pooled_width(pooled_width_), sample_height(sample_height_), sample_width(sample_width_) { set_scope(scope_); } + ROIAlign(::megdnn::param::ROIAlign packed_param_0): mode(packed_param_0.mode), format(packed_param_0.format), spatial_scale(packed_param_0.spatial_scale), offset(packed_param_0.offset), pooled_height(packed_param_0.pooled_height), pooled_width(packed_param_0.pooled_width), sample_height(packed_param_0.sample_height), sample_width(packed_param_0.sample_width) {} + ::megdnn::param::ROIAlign param() const { + return {mode, format, spatial_scale, offset, pooled_height, pooled_width, sample_height, sample_width}; + } +}; + +class ROIPooling : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::ROIPooling::Mode; + Mode mode = ::megdnn::param::ROIPooling::Mode::MAX; + float scale = 1.f; + ROIPooling() = default; + ROIPooling(Mode mode_, float scale_, std::string scope_ = {}): mode(mode_), scale(scale_) { set_scope(scope_); } + ROIPooling(::megdnn::param::ROIPooling packed_param_0): mode(packed_param_0.mode), scale(packed_param_0.scale) {} + ::megdnn::param::ROIPooling param() const { + return {mode, scale}; + } +}; + +class Reduce : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::Reduce::Mode; + using DataType = ::megdnn::param::Reduce::DataType; + Mode mode = ::megdnn::param::Reduce::Mode::SUM; + int32_t axis = 2147483647; + DataType data_type = ::megdnn::param::Reduce::DataType::DEFAULT; + bool keepdim = true; + Reduce() = default; + Reduce(Mode mode_, int32_t axis_, DataType data_type_, bool keepdim_, std::string scope_ = {}): mode(mode_), axis(axis_), data_type(data_type_), keepdim(keepdim_) { set_scope(scope_); } + Reduce(::megdnn::param::Reduce packed_param_0, bool keepdim_): mode(packed_param_0.mode), axis(packed_param_0.axis), data_type(packed_param_0.data_type), keepdim(keepdim_) {} + ::megdnn::param::Reduce param() const { + return {mode, axis, data_type}; + } +}; + +class Remap : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using InterpolationMode = ::megdnn::param::Remap::InterpolationMode; + using BorderMode = ::megdnn::param::Remap::BorderMode; + using Format = ::megdnn::param::Remap::Format; + InterpolationMode imode = ::megdnn::param::Remap::InterpolationMode::LINEAR; + BorderMode border_type = ::megdnn::param::Remap::BorderMode::REPLICATE; + Format format = ::megdnn::param::Remap::Format::NHWC; + float scalar = 0.f; + Remap() = default; + Remap(InterpolationMode imode_, BorderMode border_type_, Format format_, float scalar_, std::string scope_ = {}): imode(imode_), border_type(border_type_), format(format_), scalar(scalar_) { set_scope(scope_); } + Remap(::megdnn::param::Remap packed_param_0): imode(packed_param_0.imode), border_type(packed_param_0.border_type), format(packed_param_0.format), scalar(packed_param_0.scalar) {} + ::megdnn::param::Remap param() const { + return {imode, border_type, format, scalar}; + } +}; + +class RemoteRecv : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::string key; + std::string addr; + uint32_t port; + uint32_t rank_from; + ::mgb::CompNode cn; + std::vector shape; + ::megdnn::DType dtype; + std::string backend; + RemoteRecv() = default; + RemoteRecv(std::string key_, std::string addr_, uint32_t port_, uint32_t rank_from_, ::mgb::CompNode cn_, std::vector shape_, ::megdnn::DType dtype_, std::string backend_, std::string scope_ = {}): key(key_), addr(addr_), port(port_), rank_from(rank_from_), cn(cn_), shape(shape_), dtype(dtype_), backend(backend_) { set_scope(scope_); } +}; + +class RemoteSend : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::string key; + std::string addr; + uint32_t port; + uint32_t rank_to; + std::string backend; + RemoteSend() = default; + RemoteSend(std::string key_, std::string addr_, uint32_t port_, uint32_t rank_to_, std::string backend_, std::string scope_ = {}): key(key_), addr(addr_), port(port_), rank_to(rank_to_), backend(backend_) { set_scope(scope_); } +}; + +class RemoveAxis : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector axis; + RemoveAxis() = default; + RemoveAxis(std::vector axis_, std::string scope_ = {}): axis(axis_) { set_scope(scope_); } +}; + +class Reshape : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = ::megdnn::param::OptionalAxisV1::INVALID_AXIS; + std::vector shape; + Reshape() = default; + Reshape(int32_t axis_, std::vector shape_, std::string scope_ = {}): axis(axis_), shape(shape_) { set_scope(scope_); } + Reshape(::megdnn::param::OptionalAxisV1 packed_param_0, std::vector shape_): axis(packed_param_0.axis), shape(shape_) {} + ::megdnn::param::OptionalAxisV1 param() const { + return {axis}; + } +}; + +class Resize : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using InterpolationMode = ::megdnn::param::Resize::InterpolationMode; + using Format = ::megdnn::param::Resize::Format; + InterpolationMode imode = ::megdnn::param::Resize::InterpolationMode::LINEAR; + Format format = ::megdnn::param::Resize::Format::NHWC; + Resize() = default; + Resize(InterpolationMode imode_, Format format_, std::string scope_ = {}): imode(imode_), format(format_) { set_scope(scope_); } + Resize(::megdnn::param::Resize packed_param_0): imode(packed_param_0.imode), format(packed_param_0.format) {} + ::megdnn::param::Resize param() const { + return {imode, format}; + } +}; + +class SVD : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + bool full_matrices = false; + bool compute_uv = true; + SVD() = default; + SVD(bool full_matrices_, bool compute_uv_, std::string scope_ = {}): full_matrices(full_matrices_), compute_uv(compute_uv_) { set_scope(scope_); } + SVD(::megdnn::param::SVD packed_param_0): full_matrices(packed_param_0.full_matrices), compute_uv(packed_param_0.compute_uv) {} + ::megdnn::param::SVD param() const { + return {full_matrices, compute_uv}; + } +}; + +class SetMeshIndexing : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + SetMeshIndexing() = default; + SetMeshIndexing(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class SetSubtensor : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + SetSubtensor() = default; + SetSubtensor(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class ShuffleRNG : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint64_t seed = 0; + size_t handle; + ShuffleRNG() = default; + ShuffleRNG(uint64_t seed_, size_t handle_, std::string scope_ = {}): seed(seed_), handle(handle_) { set_scope(scope_); } + ShuffleRNG(::megdnn::param::ShuffleRNG packed_param_0, size_t handle_): seed(packed_param_0.seed), handle(handle_) {} + ::megdnn::param::ShuffleRNG param() const { + return {seed}; + } +}; + +class SlidingWindowTranspose : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint32_t out_h = 0; + uint32_t out_w = 0; + uint32_t pad_h = 0; + uint32_t pad_w = 0; + uint32_t stride_h = 1; + uint32_t stride_w = 1; + uint32_t dilate_h = 1; + uint32_t dilate_w = 1; + uint32_t window_h = 3; + uint32_t window_w = 3; + SlidingWindowTranspose() = default; + SlidingWindowTranspose(uint32_t out_h_, uint32_t out_w_, uint32_t pad_h_, uint32_t pad_w_, uint32_t stride_h_, uint32_t stride_w_, uint32_t dilate_h_, uint32_t dilate_w_, uint32_t window_h_, uint32_t window_w_, std::string scope_ = {}): out_h(out_h_), out_w(out_w_), pad_h(pad_h_), pad_w(pad_w_), stride_h(stride_h_), stride_w(stride_w_), dilate_h(dilate_h_), dilate_w(dilate_w_), window_h(window_h_), window_w(window_w_) { set_scope(scope_); } + SlidingWindowTranspose(::megdnn::param::SlidingWindowTranspose packed_param_0): out_h(packed_param_0.out_h), out_w(packed_param_0.out_w), pad_h(packed_param_0.pad_h), pad_w(packed_param_0.pad_w), stride_h(packed_param_0.stride_h), stride_w(packed_param_0.stride_w), dilate_h(packed_param_0.dilate_h), dilate_w(packed_param_0.dilate_w), window_h(packed_param_0.window_h), window_w(packed_param_0.window_w) {} + ::megdnn::param::SlidingWindowTranspose param() const { + return {out_h, out_w, pad_h, pad_w, stride_h, stride_w, dilate_h, dilate_w, window_h, window_w}; + } +}; + +class Softmax : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis = -1; + Softmax() = default; + Softmax(int32_t axis_, std::string scope_ = {}): axis(axis_) { set_scope(scope_); } + Softmax(::megdnn::param::Softmax packed_param_0): axis(packed_param_0.axis) {} + ::megdnn::param::Softmax param() const { + return {axis}; + } +}; + +class Split : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t axis; + int32_t nsections; + Split() = default; + Split(int32_t axis_, int32_t nsections_, std::string scope_ = {}): axis(axis_), nsections(nsections_) { set_scope(scope_); } + Split(::megdnn::param::Empty, int32_t axis_, int32_t nsections_): axis(axis_), nsections(nsections_) {} + ::megdnn::param::Empty param() const { + return {}; + } +}; + +class Subtensor : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::vector> items; + Subtensor() = default; + Subtensor(std::vector> items_, std::string scope_ = {}): items(items_) { set_scope(scope_); } +}; + +class TQT : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + int32_t qmin = -2147483648; + int32_t qmax = 2147483647; + TQT() = default; + TQT(int32_t qmin_, int32_t qmax_, std::string scope_ = {}): qmin(qmin_), qmax(qmax_) { set_scope(scope_); } + TQT(::megdnn::param::TQT packed_param_0): qmin(packed_param_0.qmin), qmax(packed_param_0.qmax) {} + ::megdnn::param::TQT param() const { + return {qmin, qmax}; + } +}; + +class TensorRTRuntime : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + std::string buf; + size_t buf_size; + TensorRTRuntime() = default; + TensorRTRuntime(std::string buf_, size_t buf_size_, std::string scope_ = {}): buf(buf_), buf_size(buf_size_) { set_scope(scope_); } +}; + +class TopK : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using Mode = ::megdnn::param::TopK::Mode; + Mode mode = ::megdnn::param::TopK::Mode::KTH_ONLY; + TopK() = default; + TopK(Mode mode_, std::string scope_ = {}): mode(mode_) { set_scope(scope_); } + TopK(::megdnn::param::TopK packed_param_0): mode(packed_param_0.mode) {} + ::megdnn::param::TopK param() const { + return {mode}; + } +}; + +class TypeCvt : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + ::megdnn::DType dtype; + TypeCvt() = default; + TypeCvt(::megdnn::DType dtype_, std::string scope_ = {}): dtype(dtype_) { set_scope(scope_); } +}; + +class UniformRNG : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + uint64_t seed = 0; + ::megdnn::DType dtype = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32); + size_t handle; + UniformRNG() = default; + UniformRNG(uint64_t seed_, ::megdnn::DType dtype_, size_t handle_, std::string scope_ = {}): seed(seed_), dtype(dtype_), handle(handle_) { set_scope(scope_); } +}; + +class WarpAffine : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using InterpolationMode = ::megdnn::param::WarpAffine::InterpolationMode; + using BorderMode = ::megdnn::param::WarpAffine::BorderMode; + using Format = ::megdnn::param::WarpAffine::Format; + InterpolationMode imode = ::megdnn::param::WarpAffine::InterpolationMode::LINEAR; + BorderMode border_mode = ::megdnn::param::WarpAffine::BorderMode::REPLICATE; + float border_val = .0f; + Format format = ::megdnn::param::WarpAffine::Format::NHWC; + WarpAffine() = default; + WarpAffine(InterpolationMode imode_, BorderMode border_mode_, float border_val_, Format format_, std::string scope_ = {}): imode(imode_), border_mode(border_mode_), border_val(border_val_), format(format_) { set_scope(scope_); } + WarpAffine(::megdnn::param::WarpAffine packed_param_0): imode(packed_param_0.imode), border_mode(packed_param_0.border_mode), border_val(packed_param_0.border_val), format(packed_param_0.format) {} + ::megdnn::param::WarpAffine param() const { + return {imode, border_mode, border_val, format}; + } +}; + +class WarpPerspective : public OpDefImplBase { + MGB_DYN_TYPE_OBJ_FINAL_DECL; + +public: + using InterpolationMode = ::megdnn::param::WarpPerspective::InterpolationMode; + using BorderMode = ::megdnn::param::WarpPerspective::BorderMode; + using Format = ::megdnn::param::WarpPerspective::Format; + InterpolationMode imode = ::megdnn::param::WarpPerspective::InterpolationMode::LINEAR; + BorderMode bmode = ::megdnn::param::WarpPerspective::BorderMode::REPLICATE; + Format format = ::megdnn::param::WarpPerspective::Format::NCHW; + float border_val = .0f; + WarpPerspective() = default; + WarpPerspective(InterpolationMode imode_, BorderMode bmode_, Format format_, float border_val_, std::string scope_ = {}): imode(imode_), bmode(bmode_), format(format_), border_val(border_val_) { set_scope(scope_); } + WarpPerspective(::megdnn::param::WarpPerspective packed_param_0): imode(packed_param_0.imode), bmode(packed_param_0.bmode), format(packed_param_0.format), border_val(packed_param_0.border_val) {} + ::megdnn::param::WarpPerspective param() const { + return {imode, bmode, format, border_val}; + } +}; + +// clang-format on diff --git a/imperative/tablegen/generated/opdef.py.inl b/imperative/tablegen/generated/opdef.py.inl new file mode 100644 index 00000000..2dfcc0b2 --- /dev/null +++ b/imperative/tablegen/generated/opdef.py.inl @@ -0,0 +1,1843 @@ +// clang-format off +py::class_, OpDef> AdaptivePoolingInst(m, "AdaptivePooling"); + +py::enum_(AdaptivePoolingInst, "Mode") + .value("MAX", AdaptivePooling::Mode::MAX) + .value("AVERAGE", AdaptivePooling::Mode::AVERAGE) + .value("AVERAGE_COUNT_EXCLUDE_PADDING", AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "MAX") return AdaptivePooling::Mode::MAX; + if (str == "AVERAGE") return AdaptivePooling::Mode::AVERAGE; + if (str == "AVERAGE_COUNT_EXCLUDE_PADDING") return AdaptivePooling::Mode::AVERAGE_COUNT_EXCLUDE_PADDING; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(AdaptivePoolingInst, "Format") + .value("NCHW", AdaptivePooling::Format::NCHW) + .value("NHWC", AdaptivePooling::Format::NHWC) + .value("NHWCD4", AdaptivePooling::Format::NHWCD4) + .value("NCHW4", AdaptivePooling::Format::NCHW4) + .value("NCHW8", AdaptivePooling::Format::NCHW8) + .value("NCHW32", AdaptivePooling::Format::NCHW32) + .value("NCHW88", AdaptivePooling::Format::NCHW88) + .value("NCHW44", AdaptivePooling::Format::NCHW44) + .value("NCHW44_DOT", AdaptivePooling::Format::NCHW44_DOT) + .value("NCHW4_NCHW32", AdaptivePooling::Format::NCHW4_NCHW32) + .value("NCHW32_NCHW4", AdaptivePooling::Format::NCHW32_NCHW4) + .value("NCHW4_NCHW", AdaptivePooling::Format::NCHW4_NCHW) + .value("NHWC_NCHW", AdaptivePooling::Format::NHWC_NCHW) + .value("NHWC_NCHW4_IC_SMALL", AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL) + .value("NCHW_NCHW4_IC_SMALL", AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL) + .value("CHWN4", AdaptivePooling::Format::CHWN4) + .value("NCHW64", AdaptivePooling::Format::NCHW64) + .value("NCHW4_NHWC", AdaptivePooling::Format::NCHW4_NHWC) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "NCHW") return AdaptivePooling::Format::NCHW; + if (str == "NHWC") return AdaptivePooling::Format::NHWC; + if (str == "NHWCD4") return AdaptivePooling::Format::NHWCD4; + if (str == "NCHW4") return AdaptivePooling::Format::NCHW4; + if (str == "NCHW8") return AdaptivePooling::Format::NCHW8; + if (str == "NCHW32") return AdaptivePooling::Format::NCHW32; + if (str == "NCHW88") return AdaptivePooling::Format::NCHW88; + if (str == "NCHW44") return AdaptivePooling::Format::NCHW44; + if (str == "NCHW44_DOT") return AdaptivePooling::Format::NCHW44_DOT; + if (str == "NCHW4_NCHW32") return AdaptivePooling::Format::NCHW4_NCHW32; + if (str == "NCHW32_NCHW4") return AdaptivePooling::Format::NCHW32_NCHW4; + if (str == "NCHW4_NCHW") return AdaptivePooling::Format::NCHW4_NCHW; + if (str == "NHWC_NCHW") return AdaptivePooling::Format::NHWC_NCHW; + if (str == "NHWC_NCHW4_IC_SMALL") return AdaptivePooling::Format::NHWC_NCHW4_IC_SMALL; + if (str == "NCHW_NCHW4_IC_SMALL") return AdaptivePooling::Format::NCHW_NCHW4_IC_SMALL; + if (str == "CHWN4") return AdaptivePooling::Format::CHWN4; + if (str == "NCHW64") return AdaptivePooling::Format::NCHW64; + if (str == "NCHW4_NHWC") return AdaptivePooling::Format::NCHW4_NHWC; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +AdaptivePoolingInst + .def(py::init<::megdnn::param::AdaptivePooling::Mode, ::megdnn::param::AdaptivePooling::Format, std::vector, std::string>(), py::arg("mode") = ::megdnn::param::AdaptivePooling::Mode::MAX, py::arg("format") = ::megdnn::param::AdaptivePooling::Format::NCHW, py::arg("shape"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("mode", &AdaptivePooling::mode) + .def_readwrite("format", &AdaptivePooling::format) + .def_readwrite("shape", &AdaptivePooling::shape); + +py::class_, OpDef> AddAxisInst(m, "AddAxis"); + +AddAxisInst + .def(py::init, std::string>(), py::arg("axis"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("axis", &AddAxis::axis); + +py::class_, OpDef> ArgmaxInst(m, "Argmax"); + +ArgmaxInst + .def(py::init(), py::arg("axis") = 0, py::arg("scope") = {}) + .def_readwrite("axis", &Argmax::axis); + +py::class_, OpDef> ArgminInst(m, "Argmin"); + +ArgminInst + .def(py::init(), py::arg("axis") = 0, py::arg("scope") = {}) + .def_readwrite("axis", &Argmin::axis); + +py::class_, OpDef> ArgsortInst(m, "Argsort"); + +py::enum_(ArgsortInst, "Order") + .value("ASCENDING", Argsort::Order::ASCENDING) + .value("DESCENDING", Argsort::Order::DESCENDING) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "ASCENDING") return Argsort::Order::ASCENDING; + if (str == "DESCENDING") return Argsort::Order::DESCENDING; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +ArgsortInst + .def(py::init<::megdnn::param::Argsort::Order, std::string>(), py::arg("order") = ::megdnn::param::Argsort::Order::ASCENDING, py::arg("scope") = {}) + .def_readwrite("order", &Argsort::order); + +py::class_, OpDef> AssertEqualInst(m, "AssertEqual"); + +AssertEqualInst + .def(py::init(), py::arg("maxerr") = 0.0001, py::arg("verbose") = false, py::arg("scope") = {}) + .def_readwrite("maxerr", &AssertEqual::maxerr) + .def_readwrite("verbose", &AssertEqual::verbose); + +py::class_, OpDef> AtlasRuntimeInst(m, "AtlasRuntime"); + +AtlasRuntimeInst + .def(py::init(), py::arg("buf"), py::arg("buf_size"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("buf", &AtlasRuntime::buf) + .def_readwrite("buf_size", &AtlasRuntime::buf_size); + +py::class_, OpDef> BarrierInst(m, "Barrier"); + +BarrierInst + .def(py::init<::mgb::CompNode, uint32_t, std::string>(), py::arg("comp_node"), py::arg("nr_outputs"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("comp_node", &Barrier::comp_node) + .def_readwrite("nr_outputs", &Barrier::nr_outputs); + +py::class_, OpDef> BatchConvBiasInst(m, "BatchConvBias"); + +py::enum_(BatchConvBiasInst, "NonlineMode") + .value("IDENTITY", BatchConvBias::NonlineMode::IDENTITY) + .value("RELU", BatchConvBias::NonlineMode::RELU) + .value("SIGMOID", BatchConvBias::NonlineMode::SIGMOID) + .value("H_SWISH", BatchConvBias::NonlineMode::H_SWISH) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "IDENTITY") return BatchConvBias::NonlineMode::IDENTITY; + if (str == "RELU") return BatchConvBias::NonlineMode::RELU; + if (str == "SIGMOID") return BatchConvBias::NonlineMode::SIGMOID; + if (str == "H_SWISH") return BatchConvBias::NonlineMode::H_SWISH; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(BatchConvBiasInst, "Mode") + .value("CROSS_CORRELATION", BatchConvBias::Mode::CROSS_CORRELATION) + .value("CONVOLUTION", BatchConvBias::Mode::CONVOLUTION) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "CROSS_CORRELATION") return BatchConvBias::Mode::CROSS_CORRELATION; + if (str == "CONVOLUTION") return BatchConvBias::Mode::CONVOLUTION; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(BatchConvBiasInst, "Sparse") + .value("DENSE", BatchConvBias::Sparse::DENSE) + .value("GROUP", BatchConvBias::Sparse::GROUP) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "DENSE") return BatchConvBias::Sparse::DENSE; + if (str == "GROUP") return BatchConvBias::Sparse::GROUP; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +BatchConvBiasInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +py::enum_(BatchConvBiasInst, "ComputeMode") + .value("DEFAULT", BatchConvBias::ComputeMode::DEFAULT) + .value("FLOAT32", BatchConvBias::ComputeMode::FLOAT32) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "DEFAULT") return BatchConvBias::ComputeMode::DEFAULT; + if (str == "FLOAT32") return BatchConvBias::ComputeMode::FLOAT32; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(BatchConvBiasInst, "Strategy") + .value("HEURISTIC", BatchConvBias::Strategy::HEURISTIC) + .value("PROFILE", BatchConvBias::Strategy::PROFILE) + .value("REPRODUCIBLE", BatchConvBias::Strategy::REPRODUCIBLE) + .value("OPTIMIZED", BatchConvBias::Strategy::OPTIMIZED) + .def("__or__", [](BatchConvBias::Strategy s0, BatchConvBias::Strategy s1) { + return static_cast(uint32_t(s0) | uint32_t(s1)); + }) + .def("__and__", [](BatchConvBias::Strategy s0, BatchConvBias::Strategy s1) { + return static_cast(uint32_t(s0) & uint32_t(s1)); + }) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "HEURISTIC") return BatchConvBias::Strategy::HEURISTIC; + if (str == "PROFILE") return BatchConvBias::Strategy::PROFILE; + if (str == "REPRODUCIBLE") return BatchConvBias::Strategy::REPRODUCIBLE; + if (str == "OPTIMIZED") return BatchConvBias::Strategy::OPTIMIZED; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +BatchConvBiasInst + .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") = {}) + .def(py::init<>()) + .def_readwrite("nonlineMode", &BatchConvBias::nonlineMode) + .def_readwrite("mode", &BatchConvBias::mode) + .def_readwrite("pad_h", &BatchConvBias::pad_h) + .def_readwrite("pad_w", &BatchConvBias::pad_w) + .def_readwrite("stride_h", &BatchConvBias::stride_h) + .def_readwrite("stride_w", &BatchConvBias::stride_w) + .def_readwrite("dilate_h", &BatchConvBias::dilate_h) + .def_readwrite("dilate_w", &BatchConvBias::dilate_w) + .def_readwrite("sparse", &BatchConvBias::sparse) + .def_readwrite("format", &BatchConvBias::format) + .def_readwrite("compute_mode", &BatchConvBias::compute_mode) + .def_readwrite("strategy", &BatchConvBias::strategy) + .def_readwrite("workspace_limit", &BatchConvBias::workspace_limit) + .def_readwrite("dtype", &BatchConvBias::dtype); + +py::class_, OpDef> BatchNormInst(m, "BatchNorm"); + +py::enum_(BatchNormInst, "ParamDim") + .value("DIM_11HW", BatchNorm::ParamDim::DIM_11HW) + .value("DIM_1CHW", BatchNorm::ParamDim::DIM_1CHW) + .value("DIM_1C11", BatchNorm::ParamDim::DIM_1C11) + .value("DIM_111C", BatchNorm::ParamDim::DIM_111C) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "DIM_11HW") return BatchNorm::ParamDim::DIM_11HW; + if (str == "DIM_1CHW") return BatchNorm::ParamDim::DIM_1CHW; + if (str == "DIM_1C11") return BatchNorm::ParamDim::DIM_1C11; + if (str == "DIM_111C") return BatchNorm::ParamDim::DIM_111C; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(BatchNormInst, "FwdMode") + .value("TRAINING", BatchNorm::FwdMode::TRAINING) + .value("INFERENCE", BatchNorm::FwdMode::INFERENCE) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "TRAINING") return BatchNorm::FwdMode::TRAINING; + if (str == "INFERENCE") return BatchNorm::FwdMode::INFERENCE; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +BatchNormInst + .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") = {}) + .def_readwrite("param_dim", &BatchNorm::param_dim) + .def_readwrite("fwd_mode", &BatchNorm::fwd_mode) + .def_readwrite("epsilon", &BatchNorm::epsilon) + .def_readwrite("avg_factor", &BatchNorm::avg_factor) + .def_readwrite("scale", &BatchNorm::scale) + .def_readwrite("bias", &BatchNorm::bias); + +py::class_, OpDef> BatchNormBackwardInst(m, "BatchNormBackward"); + +BatchNormBackwardInst.attr("ParamDim") = BatchNormInst.attr("ParamDim"); + +BatchNormBackwardInst.attr("FwdMode") = BatchNormInst.attr("FwdMode"); + +BatchNormBackwardInst + .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") = {}) + .def_readwrite("param_dim", &BatchNormBackward::param_dim) + .def_readwrite("fwd_mode", &BatchNormBackward::fwd_mode) + .def_readwrite("epsilon", &BatchNormBackward::epsilon) + .def_readwrite("avg_factor", &BatchNormBackward::avg_factor) + .def_readwrite("scale", &BatchNormBackward::scale) + .def_readwrite("bias", &BatchNormBackward::bias); + +py::class_, OpDef> BatchedIncrMeshIndexingInst(m, "BatchedIncrMeshIndexing"); + +BatchedIncrMeshIndexingInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &BatchedIncrMeshIndexing::items); + +py::class_, OpDef> BatchedMatrixMulInst(m, "BatchedMatrixMul"); + +py::enum_(BatchedMatrixMulInst, "ComputeMode") + .value("DEFAULT", BatchedMatrixMul::ComputeMode::DEFAULT) + .value("FLOAT32", BatchedMatrixMul::ComputeMode::FLOAT32) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "DEFAULT") return BatchedMatrixMul::ComputeMode::DEFAULT; + if (str == "FLOAT32") return BatchedMatrixMul::ComputeMode::FLOAT32; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(BatchedMatrixMulInst, "Format") + .value("DEFAULT", BatchedMatrixMul::Format::DEFAULT) + .value("MK4", BatchedMatrixMul::Format::MK4) + .value("MK8", BatchedMatrixMul::Format::MK8) + .value("MK4_DOT", BatchedMatrixMul::Format::MK4_DOT) + .value("N32K4_DOT", BatchedMatrixMul::Format::N32K4_DOT) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "DEFAULT") return BatchedMatrixMul::Format::DEFAULT; + if (str == "MK4") return BatchedMatrixMul::Format::MK4; + if (str == "MK8") return BatchedMatrixMul::Format::MK8; + if (str == "MK4_DOT") return BatchedMatrixMul::Format::MK4_DOT; + if (str == "N32K4_DOT") return BatchedMatrixMul::Format::N32K4_DOT; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +BatchedMatrixMulInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +BatchedMatrixMulInst + .def(py::init(), 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") = {}) + .def(py::init<>()) + .def_readwrite("transposeA", &BatchedMatrixMul::transposeA) + .def_readwrite("transposeB", &BatchedMatrixMul::transposeB) + .def_readwrite("compute_mode", &BatchedMatrixMul::compute_mode) + .def_readwrite("format", &BatchedMatrixMul::format) + .def_readwrite("strategy", &BatchedMatrixMul::strategy) + .def_readwrite("workspace_limit", &BatchedMatrixMul::workspace_limit) + .def_readwrite("dimA", &BatchedMatrixMul::dimA) + .def_readwrite("dimB", &BatchedMatrixMul::dimB); + +py::class_, OpDef> BatchedMeshIndexingInst(m, "BatchedMeshIndexing"); + +BatchedMeshIndexingInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &BatchedMeshIndexing::items); + +py::class_, OpDef> BatchedSetMeshIndexingInst(m, "BatchedSetMeshIndexing"); + +BatchedSetMeshIndexingInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &BatchedSetMeshIndexing::items); + +py::class_, OpDef> BetaRNGInst(m, "BetaRNG"); + +BetaRNGInst + .def(py::init(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("seed", &BetaRNG::seed) + .def_readwrite("handle", &BetaRNG::handle); + +py::class_, OpDef> BorrowInst(m, "Borrow"); + +BorrowInst + .def(py::init<::mgb::CompNode, std::string>(), py::arg("comp_node"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("comp_node", &Borrow::comp_node); + +py::class_, OpDef> BroadcastInst(m, "Broadcast"); + +BroadcastInst + .def(py::init, std::string>(), py::arg("shape"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("shape", &Broadcast::shape); + +py::class_, OpDef> CambriconRuntimeInst(m, "CambriconRuntime"); + +CambriconRuntimeInst + .def(py::init(), py::arg("buf"), py::arg("buf_size"), py::arg("symbol"), py::arg("tensor_dim_mutable"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("buf", &CambriconRuntime::buf) + .def_readwrite("buf_size", &CambriconRuntime::buf_size) + .def_readwrite("symbol", &CambriconRuntime::symbol) + .def_readwrite("tensor_dim_mutable", &CambriconRuntime::tensor_dim_mutable); + +py::class_, OpDef> CheckNonFiniteInst(m, "CheckNonFinite"); + +CheckNonFiniteInst + .def(py::init(), py::arg("scale") = 1.0, py::arg("scope") = {}) + .def_readwrite("scale", &CheckNonFinite::scale); + +py::class_, OpDef> CollectiveCommInst(m, "CollectiveComm"); + +py::enum_(CollectiveCommInst, "Mode") + .value("REDUCE_SUM", CollectiveComm::Mode::REDUCE_SUM) + .value("BROADCAST", CollectiveComm::Mode::BROADCAST) + .value("ALL_GATHER", CollectiveComm::Mode::ALL_GATHER) + .value("REDUCE_SCATTER_SUM", CollectiveComm::Mode::REDUCE_SCATTER_SUM) + .value("ALL_REDUCE_SUM", CollectiveComm::Mode::ALL_REDUCE_SUM) + .value("ALL_REDUCE_MAX", CollectiveComm::Mode::ALL_REDUCE_MAX) + .value("ALL_REDUCE_MIN", CollectiveComm::Mode::ALL_REDUCE_MIN) + .value("ALL_REDUCE_PROD", CollectiveComm::Mode::ALL_REDUCE_PROD) + .value("GATHER", CollectiveComm::Mode::GATHER) + .value("SCATTER", CollectiveComm::Mode::SCATTER) + .value("ALL_TO_ALL", CollectiveComm::Mode::ALL_TO_ALL) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "REDUCE_SUM") return CollectiveComm::Mode::REDUCE_SUM; + if (str == "BROADCAST") return CollectiveComm::Mode::BROADCAST; + if (str == "ALL_GATHER") return CollectiveComm::Mode::ALL_GATHER; + if (str == "REDUCE_SCATTER_SUM") return CollectiveComm::Mode::REDUCE_SCATTER_SUM; + if (str == "ALL_REDUCE_SUM") return CollectiveComm::Mode::ALL_REDUCE_SUM; + if (str == "ALL_REDUCE_MAX") return CollectiveComm::Mode::ALL_REDUCE_MAX; + if (str == "ALL_REDUCE_MIN") return CollectiveComm::Mode::ALL_REDUCE_MIN; + if (str == "ALL_REDUCE_PROD") return CollectiveComm::Mode::ALL_REDUCE_PROD; + if (str == "GATHER") return CollectiveComm::Mode::GATHER; + if (str == "SCATTER") return CollectiveComm::Mode::SCATTER; + if (str == "ALL_TO_ALL") return CollectiveComm::Mode::ALL_TO_ALL; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +CollectiveCommInst + .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") = {}) + .def(py::init<>()) + .def_readwrite("mode", &CollectiveComm::mode) + .def_readwrite("key", &CollectiveComm::key) + .def_readwrite("nr_devices", &CollectiveComm::nr_devices) + .def_readwrite("rank", &CollectiveComm::rank) + .def_readwrite("is_root", &CollectiveComm::is_root) + .def_readwrite("local_grad", &CollectiveComm::local_grad) + .def_readwrite("addr", &CollectiveComm::addr) + .def_readwrite("port", &CollectiveComm::port) + .def_readwrite("dtype", &CollectiveComm::dtype) + .def_readwrite("backend", &CollectiveComm::backend) + .def_readwrite("comp_node", &CollectiveComm::comp_node); + +py::class_, OpDef> ConcatInst(m, "Concat"); + +ConcatInst + .def(py::init(), py::arg("axis") = 0, py::arg("comp_node"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("axis", &Concat::axis) + .def_readwrite("comp_node", &Concat::comp_node); + +py::class_, OpDef> CondTakeInst(m, "CondTake"); + +CondTakeInst + .def(py::init<>()); + +py::class_, OpDef> ConvBiasInst(m, "ConvBias"); + +ConvBiasInst.attr("NonlineMode") = BatchConvBiasInst.attr("NonlineMode"); + +ConvBiasInst.attr("Mode") = BatchConvBiasInst.attr("Mode"); + +ConvBiasInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse"); + +ConvBiasInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +ConvBiasInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode"); + +ConvBiasInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +ConvBiasInst + .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") = {}) + .def(py::init<>()) + .def_readwrite("nonlineMode", &ConvBias::nonlineMode) + .def_readwrite("mode", &ConvBias::mode) + .def_readwrite("sparse", &ConvBias::sparse) + .def_readwrite("format", &ConvBias::format) + .def_readwrite("pad_h", &ConvBias::pad_h) + .def_readwrite("pad_w", &ConvBias::pad_w) + .def_readwrite("stride_h", &ConvBias::stride_h) + .def_readwrite("stride_w", &ConvBias::stride_w) + .def_readwrite("dilate_h", &ConvBias::dilate_h) + .def_readwrite("dilate_w", &ConvBias::dilate_w) + .def_readwrite("compute_mode", &ConvBias::compute_mode) + .def_readwrite("strategy", &ConvBias::strategy) + .def_readwrite("workspace_limit", &ConvBias::workspace_limit) + .def_readwrite("dtype", &ConvBias::dtype); + +py::class_, OpDef> ConvolutionInst(m, "Convolution"); + +ConvolutionInst.attr("Mode") = BatchConvBiasInst.attr("Mode"); + +ConvolutionInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse"); + +ConvolutionInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +ConvolutionInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode"); + +ConvolutionInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +ConvolutionInst + .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") = {}) + .def_readwrite("mode", &Convolution::mode) + .def_readwrite("pad_h", &Convolution::pad_h) + .def_readwrite("pad_w", &Convolution::pad_w) + .def_readwrite("stride_h", &Convolution::stride_h) + .def_readwrite("stride_w", &Convolution::stride_w) + .def_readwrite("dilate_h", &Convolution::dilate_h) + .def_readwrite("dilate_w", &Convolution::dilate_w) + .def_readwrite("sparse", &Convolution::sparse) + .def_readwrite("format", &Convolution::format) + .def_readwrite("compute_mode", &Convolution::compute_mode) + .def_readwrite("strategy", &Convolution::strategy) + .def_readwrite("workspace_limit", &Convolution::workspace_limit); + +py::class_, OpDef> Convolution3DInst(m, "Convolution3D"); + +py::enum_(Convolution3DInst, "Mode") + .value("CROSS_CORRELATION", Convolution3D::Mode::CROSS_CORRELATION) + .value("CONVOLUTION", Convolution3D::Mode::CONVOLUTION) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "CROSS_CORRELATION") return Convolution3D::Mode::CROSS_CORRELATION; + if (str == "CONVOLUTION") return Convolution3D::Mode::CONVOLUTION; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(Convolution3DInst, "Sparse") + .value("DENSE", Convolution3D::Sparse::DENSE) + .value("GROUP", Convolution3D::Sparse::GROUP) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "DENSE") return Convolution3D::Sparse::DENSE; + if (str == "GROUP") return Convolution3D::Sparse::GROUP; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(Convolution3DInst, "DataType") + .value("FLOAT", Convolution3D::DataType::FLOAT) + .value("FLOAT_IO16xC32", Convolution3D::DataType::FLOAT_IO16xC32) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "FLOAT") return Convolution3D::DataType::FLOAT; + if (str == "FLOAT_IO16xC32") return Convolution3D::DataType::FLOAT_IO16xC32; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(Convolution3DInst, "Format") + .value("NCDHW", Convolution3D::Format::NCDHW) + .value("NDHWC", Convolution3D::Format::NDHWC) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "NCDHW") return Convolution3D::Format::NCDHW; + if (str == "NDHWC") return Convolution3D::Format::NDHWC; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +Convolution3DInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +Convolution3DInst + .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") = {}) + .def_readwrite("mode", &Convolution3D::mode) + .def_readwrite("pad_d", &Convolution3D::pad_d) + .def_readwrite("pad_h", &Convolution3D::pad_h) + .def_readwrite("pad_w", &Convolution3D::pad_w) + .def_readwrite("stride_d", &Convolution3D::stride_d) + .def_readwrite("stride_h", &Convolution3D::stride_h) + .def_readwrite("stride_w", &Convolution3D::stride_w) + .def_readwrite("dilate_d", &Convolution3D::dilate_d) + .def_readwrite("dilate_h", &Convolution3D::dilate_h) + .def_readwrite("dilate_w", &Convolution3D::dilate_w) + .def_readwrite("sparse", &Convolution3D::sparse) + .def_readwrite("data_type", &Convolution3D::data_type) + .def_readwrite("format", &Convolution3D::format) + .def_readwrite("strategy", &Convolution3D::strategy) + .def_readwrite("workspace_limit", &Convolution3D::workspace_limit); + +py::class_, OpDef> Convolution3DBackwardDataInst(m, "Convolution3DBackwardData"); + +Convolution3DBackwardDataInst.attr("Mode") = Convolution3DInst.attr("Mode"); + +Convolution3DBackwardDataInst.attr("Sparse") = Convolution3DInst.attr("Sparse"); + +Convolution3DBackwardDataInst.attr("DataType") = Convolution3DInst.attr("DataType"); + +Convolution3DBackwardDataInst.attr("Format") = Convolution3DInst.attr("Format"); + +Convolution3DBackwardDataInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +Convolution3DBackwardDataInst + .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") = {}) + .def_readwrite("mode", &Convolution3DBackwardData::mode) + .def_readwrite("pad_d", &Convolution3DBackwardData::pad_d) + .def_readwrite("pad_h", &Convolution3DBackwardData::pad_h) + .def_readwrite("pad_w", &Convolution3DBackwardData::pad_w) + .def_readwrite("stride_d", &Convolution3DBackwardData::stride_d) + .def_readwrite("stride_h", &Convolution3DBackwardData::stride_h) + .def_readwrite("stride_w", &Convolution3DBackwardData::stride_w) + .def_readwrite("dilate_d", &Convolution3DBackwardData::dilate_d) + .def_readwrite("dilate_h", &Convolution3DBackwardData::dilate_h) + .def_readwrite("dilate_w", &Convolution3DBackwardData::dilate_w) + .def_readwrite("sparse", &Convolution3DBackwardData::sparse) + .def_readwrite("data_type", &Convolution3DBackwardData::data_type) + .def_readwrite("format", &Convolution3DBackwardData::format) + .def_readwrite("strategy", &Convolution3DBackwardData::strategy) + .def_readwrite("workspace_limit", &Convolution3DBackwardData::workspace_limit); + +py::class_, OpDef> ConvolutionBackwardDataInst(m, "ConvolutionBackwardData"); + +ConvolutionBackwardDataInst.attr("Mode") = BatchConvBiasInst.attr("Mode"); + +ConvolutionBackwardDataInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse"); + +ConvolutionBackwardDataInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +ConvolutionBackwardDataInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode"); + +ConvolutionBackwardDataInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +ConvolutionBackwardDataInst + .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") = {}) + .def(py::init<>()) + .def_readwrite("mode", &ConvolutionBackwardData::mode) + .def_readwrite("pad_h", &ConvolutionBackwardData::pad_h) + .def_readwrite("pad_w", &ConvolutionBackwardData::pad_w) + .def_readwrite("stride_h", &ConvolutionBackwardData::stride_h) + .def_readwrite("stride_w", &ConvolutionBackwardData::stride_w) + .def_readwrite("dilate_h", &ConvolutionBackwardData::dilate_h) + .def_readwrite("dilate_w", &ConvolutionBackwardData::dilate_w) + .def_readwrite("sparse", &ConvolutionBackwardData::sparse) + .def_readwrite("format", &ConvolutionBackwardData::format) + .def_readwrite("compute_mode", &ConvolutionBackwardData::compute_mode) + .def_readwrite("strategy", &ConvolutionBackwardData::strategy) + .def_readwrite("workspace_limit", &ConvolutionBackwardData::workspace_limit) + .def_readwrite("dtype", &ConvolutionBackwardData::dtype); + +py::class_, OpDef> CopyInst(m, "Copy"); + +CopyInst + .def(py::init<::mgb::CompNode, std::string>(), py::arg("comp_node"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("comp_node", &Copy::comp_node); + +py::class_, OpDef> CorrelationInst(m, "Correlation"); + +py::enum_(CorrelationInst, "Format") + .value("NCHW", Correlation::Format::NCHW) + .value("NHWC", Correlation::Format::NHWC) + .value("NHWCD4", Correlation::Format::NHWCD4) + .value("NCHW4", Correlation::Format::NCHW4) + .value("NCHW8", Correlation::Format::NCHW8) + .value("NCHW32", Correlation::Format::NCHW32) + .value("NCHW88", Correlation::Format::NCHW88) + .value("NCHW44", Correlation::Format::NCHW44) + .value("NCHW44_DOT", Correlation::Format::NCHW44_DOT) + .value("NCHW_WINOGRAD", Correlation::Format::NCHW_WINOGRAD) + .value("NCHW88_WINOGRAD", Correlation::Format::NCHW88_WINOGRAD) + .value("NCHW44_WINOGRAD", Correlation::Format::NCHW44_WINOGRAD) + .value("NCHW4_NCHW32", Correlation::Format::NCHW4_NCHW32) + .value("NCHW32_NCHW4", Correlation::Format::NCHW32_NCHW4) + .value("NCHW4_NCHW", Correlation::Format::NCHW4_NCHW) + .value("NHWC_NCHW", Correlation::Format::NHWC_NCHW) + .value("NHWC_NCHW4_IC_SMALL", Correlation::Format::NHWC_NCHW4_IC_SMALL) + .value("NCHW_NCHW4_IC_SMALL", Correlation::Format::NCHW_NCHW4_IC_SMALL) + .value("CHWN4", Correlation::Format::CHWN4) + .value("NCHW4_NHWC", Correlation::Format::NCHW4_NHWC) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "NCHW") return Correlation::Format::NCHW; + if (str == "NHWC") return Correlation::Format::NHWC; + if (str == "NHWCD4") return Correlation::Format::NHWCD4; + if (str == "NCHW4") return Correlation::Format::NCHW4; + if (str == "NCHW8") return Correlation::Format::NCHW8; + if (str == "NCHW32") return Correlation::Format::NCHW32; + if (str == "NCHW88") return Correlation::Format::NCHW88; + if (str == "NCHW44") return Correlation::Format::NCHW44; + if (str == "NCHW44_DOT") return Correlation::Format::NCHW44_DOT; + if (str == "NCHW_WINOGRAD") return Correlation::Format::NCHW_WINOGRAD; + if (str == "NCHW88_WINOGRAD") return Correlation::Format::NCHW88_WINOGRAD; + if (str == "NCHW44_WINOGRAD") return Correlation::Format::NCHW44_WINOGRAD; + if (str == "NCHW4_NCHW32") return Correlation::Format::NCHW4_NCHW32; + if (str == "NCHW32_NCHW4") return Correlation::Format::NCHW32_NCHW4; + if (str == "NCHW4_NCHW") return Correlation::Format::NCHW4_NCHW; + if (str == "NHWC_NCHW") return Correlation::Format::NHWC_NCHW; + if (str == "NHWC_NCHW4_IC_SMALL") return Correlation::Format::NHWC_NCHW4_IC_SMALL; + if (str == "NCHW_NCHW4_IC_SMALL") return Correlation::Format::NCHW_NCHW4_IC_SMALL; + if (str == "CHWN4") return Correlation::Format::CHWN4; + if (str == "NCHW4_NHWC") return Correlation::Format::NCHW4_NHWC; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +CorrelationInst + .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") = {}) + .def_readwrite("format", &Correlation::format) + .def_readwrite("kernel_size", &Correlation::kernel_size) + .def_readwrite("max_displacement", &Correlation::max_displacement) + .def_readwrite("stride1", &Correlation::stride1) + .def_readwrite("stride2", &Correlation::stride2) + .def_readwrite("pad_size", &Correlation::pad_size) + .def_readwrite("is_multiply", &Correlation::is_multiply); + +py::class_, OpDef> CumsumInst(m, "Cumsum"); + +CumsumInst + .def(py::init(), py::arg("axis") = 2147483647, py::arg("exclusive") = true, py::arg("reverse") = false, py::arg("scope") = {}) + .def_readwrite("axis", &Cumsum::axis) + .def_readwrite("exclusive", &Cumsum::exclusive) + .def_readwrite("reverse", &Cumsum::reverse); + +py::class_, OpDef> CvtColorInst(m, "CvtColor"); + +py::enum_(CvtColorInst, "Mode") + .value("RGB2GRAY", CvtColor::Mode::RGB2GRAY) + .value("RGB2YUV", CvtColor::Mode::RGB2YUV) + .value("YUV2RGB", CvtColor::Mode::YUV2RGB) + .value("GRAY2RGB", CvtColor::Mode::GRAY2RGB) + .value("RGBA2RGB", CvtColor::Mode::RGBA2RGB) + .value("RGBA2BGR", CvtColor::Mode::RGBA2BGR) + .value("RGBA2GRAY", CvtColor::Mode::RGBA2GRAY) + .value("RGB2BGR", CvtColor::Mode::RGB2BGR) + .value("BGR2GRAY", CvtColor::Mode::BGR2GRAY) + .value("BGR2RGB", CvtColor::Mode::BGR2RGB) + .value("YUV2GRAY_NV21", CvtColor::Mode::YUV2GRAY_NV21) + .value("YUV2RGB_NV21", CvtColor::Mode::YUV2RGB_NV21) + .value("YUV2BGR_NV21", CvtColor::Mode::YUV2BGR_NV21) + .value("YUV2GRAY_NV12", CvtColor::Mode::YUV2GRAY_NV12) + .value("YUV2RGB_NV12", CvtColor::Mode::YUV2RGB_NV12) + .value("YUV2BGR_NV12", CvtColor::Mode::YUV2BGR_NV12) + .value("YUV2GRAY_YV12", CvtColor::Mode::YUV2GRAY_YV12) + .value("YUV2RGB_YV12", CvtColor::Mode::YUV2RGB_YV12) + .value("YUV2BGR_YV12", CvtColor::Mode::YUV2BGR_YV12) + .value("YUV2GRAY_YU12", CvtColor::Mode::YUV2GRAY_YU12) + .value("YUV2RGB_YU12", CvtColor::Mode::YUV2RGB_YU12) + .value("YUV2BGR_YU12", CvtColor::Mode::YUV2BGR_YU12) + .value("YCrCb2RGB", CvtColor::Mode::YCrCb2RGB) + .value("YCrCb2BGR", CvtColor::Mode::YCrCb2BGR) + .value("BT601_YUV2RGB_NV21", CvtColor::Mode::BT601_YUV2RGB_NV21) + .value("BT601_YUV2BGR_NV21", CvtColor::Mode::BT601_YUV2BGR_NV21) + .value("BT601_YUV2RGB_NV12", CvtColor::Mode::BT601_YUV2RGB_NV12) + .value("BT601_YUV2BGR_NV12", CvtColor::Mode::BT601_YUV2BGR_NV12) + .value("BT601_YUV2RGB_YV12", CvtColor::Mode::BT601_YUV2RGB_YV12) + .value("BT601_YUV2BGR_YV12", CvtColor::Mode::BT601_YUV2BGR_YV12) + .value("BT601_YUV2RGB_YU12", CvtColor::Mode::BT601_YUV2RGB_YU12) + .value("BT601_YUV2BGR_YU12", CvtColor::Mode::BT601_YUV2BGR_YU12) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "RGB2GRAY") return CvtColor::Mode::RGB2GRAY; + if (str == "RGB2YUV") return CvtColor::Mode::RGB2YUV; + if (str == "YUV2RGB") return CvtColor::Mode::YUV2RGB; + if (str == "GRAY2RGB") return CvtColor::Mode::GRAY2RGB; + if (str == "RGBA2RGB") return CvtColor::Mode::RGBA2RGB; + if (str == "RGBA2BGR") return CvtColor::Mode::RGBA2BGR; + if (str == "RGBA2GRAY") return CvtColor::Mode::RGBA2GRAY; + if (str == "RGB2BGR") return CvtColor::Mode::RGB2BGR; + if (str == "BGR2GRAY") return CvtColor::Mode::BGR2GRAY; + if (str == "BGR2RGB") return CvtColor::Mode::BGR2RGB; + if (str == "YUV2GRAY_NV21") return CvtColor::Mode::YUV2GRAY_NV21; + if (str == "YUV2RGB_NV21") return CvtColor::Mode::YUV2RGB_NV21; + if (str == "YUV2BGR_NV21") return CvtColor::Mode::YUV2BGR_NV21; + if (str == "YUV2GRAY_NV12") return CvtColor::Mode::YUV2GRAY_NV12; + if (str == "YUV2RGB_NV12") return CvtColor::Mode::YUV2RGB_NV12; + if (str == "YUV2BGR_NV12") return CvtColor::Mode::YUV2BGR_NV12; + if (str == "YUV2GRAY_YV12") return CvtColor::Mode::YUV2GRAY_YV12; + if (str == "YUV2RGB_YV12") return CvtColor::Mode::YUV2RGB_YV12; + if (str == "YUV2BGR_YV12") return CvtColor::Mode::YUV2BGR_YV12; + if (str == "YUV2GRAY_YU12") return CvtColor::Mode::YUV2GRAY_YU12; + if (str == "YUV2RGB_YU12") return CvtColor::Mode::YUV2RGB_YU12; + if (str == "YUV2BGR_YU12") return CvtColor::Mode::YUV2BGR_YU12; + if (str == "YCrCb2RGB") return CvtColor::Mode::YCrCb2RGB; + if (str == "YCrCb2BGR") return CvtColor::Mode::YCrCb2BGR; + if (str == "BT601_YUV2RGB_NV21") return CvtColor::Mode::BT601_YUV2RGB_NV21; + if (str == "BT601_YUV2BGR_NV21") return CvtColor::Mode::BT601_YUV2BGR_NV21; + if (str == "BT601_YUV2RGB_NV12") return CvtColor::Mode::BT601_YUV2RGB_NV12; + if (str == "BT601_YUV2BGR_NV12") return CvtColor::Mode::BT601_YUV2BGR_NV12; + if (str == "BT601_YUV2RGB_YV12") return CvtColor::Mode::BT601_YUV2RGB_YV12; + if (str == "BT601_YUV2BGR_YV12") return CvtColor::Mode::BT601_YUV2BGR_YV12; + if (str == "BT601_YUV2RGB_YU12") return CvtColor::Mode::BT601_YUV2RGB_YU12; + if (str == "BT601_YUV2BGR_YU12") return CvtColor::Mode::BT601_YUV2BGR_YU12; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +CvtColorInst + .def(py::init<::megdnn::param::CvtColor::Mode, std::string>(), py::arg("mode") = ::megdnn::param::CvtColor::Mode::RGB2GRAY, py::arg("scope") = {}) + .def_readwrite("mode", &CvtColor::mode); + +py::class_, OpDef> DeformableConvInst(m, "DeformableConv"); + +DeformableConvInst.attr("Mode") = BatchConvBiasInst.attr("Mode"); + +DeformableConvInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse"); + +DeformableConvInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +DeformableConvInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode"); + +DeformableConvInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +DeformableConvInst + .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") = {}) + .def_readwrite("mode", &DeformableConv::mode) + .def_readwrite("pad_h", &DeformableConv::pad_h) + .def_readwrite("pad_w", &DeformableConv::pad_w) + .def_readwrite("stride_h", &DeformableConv::stride_h) + .def_readwrite("stride_w", &DeformableConv::stride_w) + .def_readwrite("dilate_h", &DeformableConv::dilate_h) + .def_readwrite("dilate_w", &DeformableConv::dilate_w) + .def_readwrite("sparse", &DeformableConv::sparse) + .def_readwrite("format", &DeformableConv::format) + .def_readwrite("compute_mode", &DeformableConv::compute_mode) + .def_readwrite("strategy", &DeformableConv::strategy) + .def_readwrite("workspace_limit", &DeformableConv::workspace_limit); + +py::class_, OpDef> DeformablePSROIPoolingInst(m, "DeformablePSROIPooling"); + +DeformablePSROIPoolingInst + .def(py::init(), 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") = {}) + .def_readwrite("no_trans", &DeformablePSROIPooling::no_trans) + .def_readwrite("spatial_scale", &DeformablePSROIPooling::spatial_scale) + .def_readwrite("trans_std", &DeformablePSROIPooling::trans_std) + .def_readwrite("pooled_h", &DeformablePSROIPooling::pooled_h) + .def_readwrite("pooled_w", &DeformablePSROIPooling::pooled_w) + .def_readwrite("part_size", &DeformablePSROIPooling::part_size) + .def_readwrite("sample_per_part", &DeformablePSROIPooling::sample_per_part); + +py::class_, OpDef> DiagInst(m, "Diag"); + +DiagInst + .def(py::init(), py::arg("k") = 0, py::arg("scope") = {}) + .def_readwrite("k", &Diag::k); + +py::class_, OpDef> DimshuffleInst(m, "Dimshuffle"); + +DimshuffleInst + .def(py::init, std::string>(), py::arg("pattern"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("pattern", &Dimshuffle::pattern); + +py::class_, OpDef> DotInst(m, "Dot"); + +DotInst + .def(py::init<>()); + +py::class_, OpDef> DropoutInst(m, "Dropout"); + +DropoutInst + .def(py::init(), py::arg("drop_prob") = 0, py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("drop_prob", &Dropout::drop_prob) + .def_readwrite("seed", &Dropout::seed) + .def_readwrite("handle", &Dropout::handle); + +py::class_, OpDef> ElemwiseInst(m, "Elemwise"); + +py::enum_(ElemwiseInst, "Mode") + .value("RELU", Elemwise::Mode::RELU) + .value("ABS", Elemwise::Mode::ABS) + .value("ACOS", Elemwise::Mode::ACOS) + .value("ASIN", Elemwise::Mode::ASIN) + .value("CEIL", Elemwise::Mode::CEIL) + .value("COS", Elemwise::Mode::COS) + .value("EXP", Elemwise::Mode::EXP) + .value("EXPM1", Elemwise::Mode::EXPM1) + .value("FLOOR", Elemwise::Mode::FLOOR) + .value("LOG", Elemwise::Mode::LOG) + .value("LOG1P", Elemwise::Mode::LOG1P) + .value("NEGATE", Elemwise::Mode::NEGATE) + .value("SIGMOID", Elemwise::Mode::SIGMOID) + .value("SIN", Elemwise::Mode::SIN) + .value("TANH", Elemwise::Mode::TANH) + .value("ABS_GRAD", Elemwise::Mode::ABS_GRAD) + .value("ADD", Elemwise::Mode::ADD) + .value("FLOOR_DIV", Elemwise::Mode::FLOOR_DIV) + .value("MAX", Elemwise::Mode::MAX) + .value("MIN", Elemwise::Mode::MIN) + .value("MOD", Elemwise::Mode::MOD) + .value("MUL", Elemwise::Mode::MUL) + .value("POW", Elemwise::Mode::POW) + .value("SIGMOID_GRAD", Elemwise::Mode::SIGMOID_GRAD) + .value("SUB", Elemwise::Mode::SUB) + .value("SWITCH_GT0", Elemwise::Mode::SWITCH_GT0) + .value("TANH_GRAD", Elemwise::Mode::TANH_GRAD) + .value("TRUE_DIV", Elemwise::Mode::TRUE_DIV) + .value("LOG_SUM_EXP", Elemwise::Mode::LOG_SUM_EXP) + .value("LT", Elemwise::Mode::LT) + .value("LEQ", Elemwise::Mode::LEQ) + .value("EQ", Elemwise::Mode::EQ) + .value("SHL", Elemwise::Mode::SHL) + .value("SHR", Elemwise::Mode::SHR) + .value("COND_LEQ_MOV", Elemwise::Mode::COND_LEQ_MOV) + .value("FUSE_MUL_ADD3", Elemwise::Mode::FUSE_MUL_ADD3) + .value("FUSE_MUL_ADD4", Elemwise::Mode::FUSE_MUL_ADD4) + .value("FUSE_ADD_RELU", Elemwise::Mode::FUSE_ADD_RELU) + .value("FUSE_ADD_SIGMOID", Elemwise::Mode::FUSE_ADD_SIGMOID) + .value("FUSE_ADD_TANH", Elemwise::Mode::FUSE_ADD_TANH) + .value("FAST_TANH", Elemwise::Mode::FAST_TANH) + .value("FAST_TANH_GRAD", Elemwise::Mode::FAST_TANH_GRAD) + .value("ROUND", Elemwise::Mode::ROUND) + .value("RMULH", Elemwise::Mode::RMULH) + .value("ATAN2", Elemwise::Mode::ATAN2) + .value("ERF", Elemwise::Mode::ERF) + .value("ERFINV", Elemwise::Mode::ERFINV) + .value("ERFC", Elemwise::Mode::ERFC) + .value("ERFCINV", Elemwise::Mode::ERFCINV) + .value("H_SWISH", Elemwise::Mode::H_SWISH) + .value("H_SWISH_GRAD", Elemwise::Mode::H_SWISH_GRAD) + .value("FUSE_ADD_H_SWISH", Elemwise::Mode::FUSE_ADD_H_SWISH) + .value("NOT", Elemwise::Mode::NOT) + .value("AND", Elemwise::Mode::AND) + .value("OR", Elemwise::Mode::OR) + .value("XOR", Elemwise::Mode::XOR) + .value("SILU", Elemwise::Mode::SILU) + .value("SILU_GRAD", Elemwise::Mode::SILU_GRAD) + .value("GELU", Elemwise::Mode::GELU) + .value("GELU_GRAD", Elemwise::Mode::GELU_GRAD) + .value("COND_LT_MOV", Elemwise::Mode::COND_LT_MOV) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "RELU") return Elemwise::Mode::RELU; + if (str == "ABS") return Elemwise::Mode::ABS; + if (str == "ACOS") return Elemwise::Mode::ACOS; + if (str == "ASIN") return Elemwise::Mode::ASIN; + if (str == "CEIL") return Elemwise::Mode::CEIL; + if (str == "COS") return Elemwise::Mode::COS; + if (str == "EXP") return Elemwise::Mode::EXP; + if (str == "EXPM1") return Elemwise::Mode::EXPM1; + if (str == "FLOOR") return Elemwise::Mode::FLOOR; + if (str == "LOG") return Elemwise::Mode::LOG; + if (str == "LOG1P") return Elemwise::Mode::LOG1P; + if (str == "NEGATE") return Elemwise::Mode::NEGATE; + if (str == "SIGMOID") return Elemwise::Mode::SIGMOID; + if (str == "SIN") return Elemwise::Mode::SIN; + if (str == "TANH") return Elemwise::Mode::TANH; + if (str == "ABS_GRAD") return Elemwise::Mode::ABS_GRAD; + if (str == "ADD") return Elemwise::Mode::ADD; + if (str == "FLOOR_DIV") return Elemwise::Mode::FLOOR_DIV; + if (str == "MAX") return Elemwise::Mode::MAX; + if (str == "MIN") return Elemwise::Mode::MIN; + if (str == "MOD") return Elemwise::Mode::MOD; + if (str == "MUL") return Elemwise::Mode::MUL; + if (str == "POW") return Elemwise::Mode::POW; + if (str == "SIGMOID_GRAD") return Elemwise::Mode::SIGMOID_GRAD; + if (str == "SUB") return Elemwise::Mode::SUB; + if (str == "SWITCH_GT0") return Elemwise::Mode::SWITCH_GT0; + if (str == "TANH_GRAD") return Elemwise::Mode::TANH_GRAD; + if (str == "TRUE_DIV") return Elemwise::Mode::TRUE_DIV; + if (str == "LOG_SUM_EXP") return Elemwise::Mode::LOG_SUM_EXP; + if (str == "LT") return Elemwise::Mode::LT; + if (str == "LEQ") return Elemwise::Mode::LEQ; + if (str == "EQ") return Elemwise::Mode::EQ; + if (str == "SHL") return Elemwise::Mode::SHL; + if (str == "SHR") return Elemwise::Mode::SHR; + if (str == "COND_LEQ_MOV") return Elemwise::Mode::COND_LEQ_MOV; + if (str == "FUSE_MUL_ADD3") return Elemwise::Mode::FUSE_MUL_ADD3; + if (str == "FUSE_MUL_ADD4") return Elemwise::Mode::FUSE_MUL_ADD4; + if (str == "FUSE_ADD_RELU") return Elemwise::Mode::FUSE_ADD_RELU; + if (str == "FUSE_ADD_SIGMOID") return Elemwise::Mode::FUSE_ADD_SIGMOID; + if (str == "FUSE_ADD_TANH") return Elemwise::Mode::FUSE_ADD_TANH; + if (str == "FAST_TANH") return Elemwise::Mode::FAST_TANH; + if (str == "FAST_TANH_GRAD") return Elemwise::Mode::FAST_TANH_GRAD; + if (str == "ROUND") return Elemwise::Mode::ROUND; + if (str == "RMULH") return Elemwise::Mode::RMULH; + if (str == "ATAN2") return Elemwise::Mode::ATAN2; + if (str == "ERF") return Elemwise::Mode::ERF; + if (str == "ERFINV") return Elemwise::Mode::ERFINV; + if (str == "ERFC") return Elemwise::Mode::ERFC; + if (str == "ERFCINV") return Elemwise::Mode::ERFCINV; + if (str == "H_SWISH") return Elemwise::Mode::H_SWISH; + if (str == "H_SWISH_GRAD") return Elemwise::Mode::H_SWISH_GRAD; + if (str == "FUSE_ADD_H_SWISH") return Elemwise::Mode::FUSE_ADD_H_SWISH; + if (str == "NOT") return Elemwise::Mode::NOT; + if (str == "AND") return Elemwise::Mode::AND; + if (str == "OR") return Elemwise::Mode::OR; + if (str == "XOR") return Elemwise::Mode::XOR; + if (str == "SILU") return Elemwise::Mode::SILU; + if (str == "SILU_GRAD") return Elemwise::Mode::SILU_GRAD; + if (str == "GELU") return Elemwise::Mode::GELU; + if (str == "GELU_GRAD") return Elemwise::Mode::GELU_GRAD; + if (str == "COND_LT_MOV") return Elemwise::Mode::COND_LT_MOV; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +ElemwiseInst + .def(py::init<::megdnn::param::Elemwise::Mode, std::string>(), py::arg("mode") = ::megdnn::param::Elemwise::Mode::RELU, py::arg("scope") = {}) + .def_readwrite("mode", &Elemwise::mode); + +py::class_, OpDef> ElemwiseMultiTypeInst(m, "ElemwiseMultiType"); + +py::enum_(ElemwiseMultiTypeInst, "Mode") + .value("FUSE_MUL_ADD3_INT16x32x32x32", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32) + .value("FUSE_MUL_ADD3_IXxF32xF32xI8", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8) + .value("ROUND_SHR_SATURATE_IXxI8xI8", ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8) + .value("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8", ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8) + .value("FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8", ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8) + .value("ROUND_SHR_SATURATE_IXxI8xI16", ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16) + .value("QADD", ElemwiseMultiType::Mode::QADD) + .value("QFUSE_ADD_RELU", ElemwiseMultiType::Mode::QFUSE_ADD_RELU) + .value("QMUL", ElemwiseMultiType::Mode::QMUL) + .value("QMIN", ElemwiseMultiType::Mode::QMIN) + .value("QMAX", ElemwiseMultiType::Mode::QMAX) + .value("QSUB", ElemwiseMultiType::Mode::QSUB) + .value("QTRUE_DIV", ElemwiseMultiType::Mode::QTRUE_DIV) + .value("QFUSE_ADD_SIGMOID", ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID) + .value("QFUSE_ADD_TANH", ElemwiseMultiType::Mode::QFUSE_ADD_TANH) + .value("QRELU", ElemwiseMultiType::Mode::QRELU) + .value("QABS", ElemwiseMultiType::Mode::QABS) + .value("QSIGMOID", ElemwiseMultiType::Mode::QSIGMOID) + .value("QEXP", ElemwiseMultiType::Mode::QEXP) + .value("QTANH", ElemwiseMultiType::Mode::QTANH) + .value("QFUSE_MUL_ADD3", ElemwiseMultiType::Mode::QFUSE_MUL_ADD3) + .value("QFAST_TANH", ElemwiseMultiType::Mode::QFAST_TANH) + .value("QNEGATE", ElemwiseMultiType::Mode::QNEGATE) + .value("QACOS", ElemwiseMultiType::Mode::QACOS) + .value("QASIN", ElemwiseMultiType::Mode::QASIN) + .value("QCEIL", ElemwiseMultiType::Mode::QCEIL) + .value("QCOS", ElemwiseMultiType::Mode::QCOS) + .value("QEXPM1", ElemwiseMultiType::Mode::QEXPM1) + .value("QFLOOR", ElemwiseMultiType::Mode::QFLOOR) + .value("QLOG", ElemwiseMultiType::Mode::QLOG) + .value("QLOG1P", ElemwiseMultiType::Mode::QLOG1P) + .value("QSIN", ElemwiseMultiType::Mode::QSIN) + .value("QROUND", ElemwiseMultiType::Mode::QROUND) + .value("QERF", ElemwiseMultiType::Mode::QERF) + .value("QERFINV", ElemwiseMultiType::Mode::QERFINV) + .value("QERFC", ElemwiseMultiType::Mode::QERFC) + .value("QERFCINV", ElemwiseMultiType::Mode::QERFCINV) + .value("QABS_GRAD", ElemwiseMultiType::Mode::QABS_GRAD) + .value("QFLOOR_DIV", ElemwiseMultiType::Mode::QFLOOR_DIV) + .value("QMOD", ElemwiseMultiType::Mode::QMOD) + .value("QSIGMOID_GRAD", ElemwiseMultiType::Mode::QSIGMOID_GRAD) + .value("QSWITCH_GT0", ElemwiseMultiType::Mode::QSWITCH_GT0) + .value("QTANH_GRAD", ElemwiseMultiType::Mode::QTANH_GRAD) + .value("QLT", ElemwiseMultiType::Mode::QLT) + .value("QLEQ", ElemwiseMultiType::Mode::QLEQ) + .value("QEQ", ElemwiseMultiType::Mode::QEQ) + .value("QPOW", ElemwiseMultiType::Mode::QPOW) + .value("QLOG_SUM_EXP", ElemwiseMultiType::Mode::QLOG_SUM_EXP) + .value("QFAST_TANH_GRAD", ElemwiseMultiType::Mode::QFAST_TANH_GRAD) + .value("QATAN2", ElemwiseMultiType::Mode::QATAN2) + .value("QCOND_LEQ_MOV", ElemwiseMultiType::Mode::QCOND_LEQ_MOV) + .value("QH_SWISH", ElemwiseMultiType::Mode::QH_SWISH) + .value("QFUSE_ADD_H_SWISH", ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH) + .value("QH_SWISH_GRAD", ElemwiseMultiType::Mode::QH_SWISH_GRAD) + .value("FUSE_MUL_ADD3_INT16xF32xF32xF32", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32) + .value("MUL_INT16xF32xF32", ElemwiseMultiType::Mode::MUL_INT16xF32xF32) + .value("FUSE_MUL_ADD3_UINT8xF32xF32xF32", ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32) + .value("QCOND_LT_MOV", ElemwiseMultiType::Mode::QCOND_LT_MOV) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "FUSE_MUL_ADD3_INT16x32x32x32") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16x32x32x32; + if (str == "FUSE_MUL_ADD3_IXxF32xF32xI8") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_IXxF32xF32xI8; + if (str == "ROUND_SHR_SATURATE_IXxI8xI8") return ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI8; + if (str == "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8") return ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8; + if (str == "FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8") return ElemwiseMultiType::Mode::FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8; + if (str == "ROUND_SHR_SATURATE_IXxI8xI16") return ElemwiseMultiType::Mode::ROUND_SHR_SATURATE_IXxI8xI16; + if (str == "QADD") return ElemwiseMultiType::Mode::QADD; + if (str == "QFUSE_ADD_RELU") return ElemwiseMultiType::Mode::QFUSE_ADD_RELU; + if (str == "QMUL") return ElemwiseMultiType::Mode::QMUL; + if (str == "QMIN") return ElemwiseMultiType::Mode::QMIN; + if (str == "QMAX") return ElemwiseMultiType::Mode::QMAX; + if (str == "QSUB") return ElemwiseMultiType::Mode::QSUB; + if (str == "QTRUE_DIV") return ElemwiseMultiType::Mode::QTRUE_DIV; + if (str == "QFUSE_ADD_SIGMOID") return ElemwiseMultiType::Mode::QFUSE_ADD_SIGMOID; + if (str == "QFUSE_ADD_TANH") return ElemwiseMultiType::Mode::QFUSE_ADD_TANH; + if (str == "QRELU") return ElemwiseMultiType::Mode::QRELU; + if (str == "QABS") return ElemwiseMultiType::Mode::QABS; + if (str == "QSIGMOID") return ElemwiseMultiType::Mode::QSIGMOID; + if (str == "QEXP") return ElemwiseMultiType::Mode::QEXP; + if (str == "QTANH") return ElemwiseMultiType::Mode::QTANH; + if (str == "QFUSE_MUL_ADD3") return ElemwiseMultiType::Mode::QFUSE_MUL_ADD3; + if (str == "QFAST_TANH") return ElemwiseMultiType::Mode::QFAST_TANH; + if (str == "QNEGATE") return ElemwiseMultiType::Mode::QNEGATE; + if (str == "QACOS") return ElemwiseMultiType::Mode::QACOS; + if (str == "QASIN") return ElemwiseMultiType::Mode::QASIN; + if (str == "QCEIL") return ElemwiseMultiType::Mode::QCEIL; + if (str == "QCOS") return ElemwiseMultiType::Mode::QCOS; + if (str == "QEXPM1") return ElemwiseMultiType::Mode::QEXPM1; + if (str == "QFLOOR") return ElemwiseMultiType::Mode::QFLOOR; + if (str == "QLOG") return ElemwiseMultiType::Mode::QLOG; + if (str == "QLOG1P") return ElemwiseMultiType::Mode::QLOG1P; + if (str == "QSIN") return ElemwiseMultiType::Mode::QSIN; + if (str == "QROUND") return ElemwiseMultiType::Mode::QROUND; + if (str == "QERF") return ElemwiseMultiType::Mode::QERF; + if (str == "QERFINV") return ElemwiseMultiType::Mode::QERFINV; + if (str == "QERFC") return ElemwiseMultiType::Mode::QERFC; + if (str == "QERFCINV") return ElemwiseMultiType::Mode::QERFCINV; + if (str == "QABS_GRAD") return ElemwiseMultiType::Mode::QABS_GRAD; + if (str == "QFLOOR_DIV") return ElemwiseMultiType::Mode::QFLOOR_DIV; + if (str == "QMOD") return ElemwiseMultiType::Mode::QMOD; + if (str == "QSIGMOID_GRAD") return ElemwiseMultiType::Mode::QSIGMOID_GRAD; + if (str == "QSWITCH_GT0") return ElemwiseMultiType::Mode::QSWITCH_GT0; + if (str == "QTANH_GRAD") return ElemwiseMultiType::Mode::QTANH_GRAD; + if (str == "QLT") return ElemwiseMultiType::Mode::QLT; + if (str == "QLEQ") return ElemwiseMultiType::Mode::QLEQ; + if (str == "QEQ") return ElemwiseMultiType::Mode::QEQ; + if (str == "QPOW") return ElemwiseMultiType::Mode::QPOW; + if (str == "QLOG_SUM_EXP") return ElemwiseMultiType::Mode::QLOG_SUM_EXP; + if (str == "QFAST_TANH_GRAD") return ElemwiseMultiType::Mode::QFAST_TANH_GRAD; + if (str == "QATAN2") return ElemwiseMultiType::Mode::QATAN2; + if (str == "QCOND_LEQ_MOV") return ElemwiseMultiType::Mode::QCOND_LEQ_MOV; + if (str == "QH_SWISH") return ElemwiseMultiType::Mode::QH_SWISH; + if (str == "QFUSE_ADD_H_SWISH") return ElemwiseMultiType::Mode::QFUSE_ADD_H_SWISH; + if (str == "QH_SWISH_GRAD") return ElemwiseMultiType::Mode::QH_SWISH_GRAD; + if (str == "FUSE_MUL_ADD3_INT16xF32xF32xF32") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_INT16xF32xF32xF32; + if (str == "MUL_INT16xF32xF32") return ElemwiseMultiType::Mode::MUL_INT16xF32xF32; + if (str == "FUSE_MUL_ADD3_UINT8xF32xF32xF32") return ElemwiseMultiType::Mode::FUSE_MUL_ADD3_UINT8xF32xF32xF32; + if (str == "QCOND_LT_MOV") return ElemwiseMultiType::Mode::QCOND_LT_MOV; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +ElemwiseMultiTypeInst + .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") = {}) + .def(py::init<>()) + .def_readwrite("mode", &ElemwiseMultiType::mode) + .def_readwrite("dtype", &ElemwiseMultiType::dtype); + +py::class_, OpDef> ExternOprInst(m, "ExternOpr"); + +ExternOprInst + .def(py::init>, 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") = {}) + .def(py::init<>()) + .def_readwrite("output_shapes", &ExternOpr::output_shapes) + .def_readwrite("name", &ExternOpr::name) + .def_readwrite("data", &ExternOpr::data) + .def_readwrite("data_len", &ExternOpr::data_len) + .def_readwrite("output_dtypes", &ExternOpr::output_dtypes); + +py::class_, OpDef> EyeInst(m, "Eye"); + +EyeInst + .def(py::init(), py::arg("k") = 0, py::arg("dtype") = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32), py::arg("comp_node"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("k", &Eye::k) + .def_readwrite("dtype", &Eye::dtype) + .def_readwrite("comp_node", &Eye::comp_node); + +py::class_, OpDef> FakeQuantInst(m, "FakeQuant"); + +FakeQuantInst + .def(py::init(), py::arg("qmin") = -2147483648, py::arg("qmax") = 2147483647, py::arg("scope") = {}) + .def_readwrite("qmin", &FakeQuant::qmin) + .def_readwrite("qmax", &FakeQuant::qmax); + +py::class_, OpDef> FastpathCopyInst(m, "FastpathCopy"); + +FastpathCopyInst + .def(py::init<>()); + +py::class_, OpDef> GammaRNGInst(m, "GammaRNG"); + +GammaRNGInst + .def(py::init(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("seed", &GammaRNG::seed) + .def_readwrite("handle", &GammaRNG::handle); + +py::class_, OpDef> GaussianRNGInst(m, "GaussianRNG"); + +GaussianRNGInst + .def(py::init(), 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") = {}) + .def(py::init<>()) + .def_readwrite("seed", &GaussianRNG::seed) + .def_readwrite("mean", &GaussianRNG::mean) + .def_readwrite("std", &GaussianRNG::std) + .def_readwrite("dtype", &GaussianRNG::dtype) + .def_readwrite("handle", &GaussianRNG::handle); + +py::class_, OpDef> GetVarShapeInst(m, "GetVarShape"); + +GetVarShapeInst + .def(py::init(), py::arg("axis") = ::megdnn::param::OptionalAxisV1::INVALID_AXIS, py::arg("scope") = {}) + .def_readwrite("axis", &GetVarShape::axis); + +py::class_, OpDef> GroupLocalInst(m, "GroupLocal"); + +GroupLocalInst.attr("Mode") = BatchConvBiasInst.attr("Mode"); + +GroupLocalInst.attr("Sparse") = BatchConvBiasInst.attr("Sparse"); + +GroupLocalInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +GroupLocalInst.attr("ComputeMode") = BatchConvBiasInst.attr("ComputeMode"); + +GroupLocalInst + .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") = {}) + .def_readwrite("mode", &GroupLocal::mode) + .def_readwrite("pad_h", &GroupLocal::pad_h) + .def_readwrite("pad_w", &GroupLocal::pad_w) + .def_readwrite("stride_h", &GroupLocal::stride_h) + .def_readwrite("stride_w", &GroupLocal::stride_w) + .def_readwrite("dilate_h", &GroupLocal::dilate_h) + .def_readwrite("dilate_w", &GroupLocal::dilate_w) + .def_readwrite("sparse", &GroupLocal::sparse) + .def_readwrite("format", &GroupLocal::format) + .def_readwrite("compute_mode", &GroupLocal::compute_mode); + +py::class_, OpDef> IdentityInst(m, "Identity"); + +IdentityInst + .def(py::init<>()); + +py::class_, OpDef> Images2NeibsInst(m, "Images2Neibs"); + +Images2NeibsInst + .def(py::init(), 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") = {}) + .def_readwrite("pad_h", &Images2Neibs::pad_h) + .def_readwrite("pad_w", &Images2Neibs::pad_w) + .def_readwrite("stride_h", &Images2Neibs::stride_h) + .def_readwrite("stride_w", &Images2Neibs::stride_w) + .def_readwrite("dilate_h", &Images2Neibs::dilate_h) + .def_readwrite("dilate_w", &Images2Neibs::dilate_w) + .def_readwrite("window_h", &Images2Neibs::window_h) + .def_readwrite("window_w", &Images2Neibs::window_w); + +py::class_, OpDef> IncrMeshIndexingInst(m, "IncrMeshIndexing"); + +IncrMeshIndexingInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &IncrMeshIndexing::items); + +py::class_, OpDef> IncrSubtensorInst(m, "IncrSubtensor"); + +IncrSubtensorInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &IncrSubtensor::items); + +py::class_, OpDef> IndexingIncrMultiAxisVecInst(m, "IndexingIncrMultiAxisVec"); + +IndexingIncrMultiAxisVecInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &IndexingIncrMultiAxisVec::items); + +py::class_, OpDef> IndexingMultiAxisVecInst(m, "IndexingMultiAxisVec"); + +IndexingMultiAxisVecInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &IndexingMultiAxisVec::items); + +py::class_, OpDef> IndexingOneHotInst(m, "IndexingOneHot"); + +IndexingOneHotInst + .def(py::init(), py::arg("axis") = 0, py::arg("ndim"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("axis", &IndexingOneHot::axis) + .def_readwrite("ndim", &IndexingOneHot::ndim); + +py::class_, OpDef> IndexingSetMultiAxisVecInst(m, "IndexingSetMultiAxisVec"); + +IndexingSetMultiAxisVecInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &IndexingSetMultiAxisVec::items); + +py::class_, OpDef> IndexingSetOneHotInst(m, "IndexingSetOneHot"); + +IndexingSetOneHotInst + .def(py::init(), py::arg("axis") = 0, py::arg("ndim"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("axis", &IndexingSetOneHot::axis) + .def_readwrite("ndim", &IndexingSetOneHot::ndim); + +py::class_, OpDef> InplaceAddInst(m, "InplaceAdd"); + +InplaceAddInst + .def(py::init<>()); + +py::class_, OpDef> LAMBUpdateInst(m, "LAMBUpdate"); + +LAMBUpdateInst + .def(py::init(), 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") = {}) + .def_readwrite("beta_1", &LAMBUpdate::beta_1) + .def_readwrite("beta_2", &LAMBUpdate::beta_2) + .def_readwrite("step", &LAMBUpdate::step) + .def_readwrite("lr", &LAMBUpdate::lr) + .def_readwrite("weight_decay", &LAMBUpdate::weight_decay) + .def_readwrite("eps", &LAMBUpdate::eps) + .def_readwrite("bias_correction", &LAMBUpdate::bias_correction) + .def_readwrite("always_adapt", &LAMBUpdate::always_adapt); + +py::class_, OpDef> LRNInst(m, "LRN"); + +LRNInst + .def(py::init(), py::arg("n") = 5, py::arg("k") = 2.f, py::arg("alpha") = 1e-4f, py::arg("beta") = 0.75f, py::arg("scope") = {}) + .def_readwrite("n", &LRN::n) + .def_readwrite("k", &LRN::k) + .def_readwrite("alpha", &LRN::alpha) + .def_readwrite("beta", &LRN::beta); + +py::class_, OpDef> LSQInst(m, "LSQ"); + +LSQInst + .def(py::init(), py::arg("qmin") = -2147483648, py::arg("qmax") = 2147483647, py::arg("scope") = {}) + .def_readwrite("qmin", &LSQ::qmin) + .def_readwrite("qmax", &LSQ::qmax); + +py::class_, OpDef> LSTMInst(m, "LSTM"); + +LSTMInst.attr("FwdMode") = BatchNormInst.attr("FwdMode"); + +LSTMInst + .def(py::init(), 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") = {}) + .def_readwrite("num_layers", &LSTM::num_layers) + .def_readwrite("bidirectional", &LSTM::bidirectional) + .def_readwrite("bias", &LSTM::bias) + .def_readwrite("hidden_size", &LSTM::hidden_size) + .def_readwrite("proj_size", &LSTM::proj_size) + .def_readwrite("dropout", &LSTM::dropout) + .def_readwrite("fwd_mode", &LSTM::fwd_mode); + +py::class_, OpDef> LSTMCellInst(m, "LSTMCell"); + +LSTMCellInst + .def(py::init<>()); + +py::class_, OpDef> LayerNormInst(m, "LayerNorm"); + +LayerNormInst + .def(py::init(), py::arg("affine") = true, py::arg("eps") = 1e-5f, py::arg("normalized_dim") = 1, py::arg("normalized_size") = 1, py::arg("scope") = {}) + .def_readwrite("affine", &LayerNorm::affine) + .def_readwrite("eps", &LayerNorm::eps) + .def_readwrite("normalized_dim", &LayerNorm::normalized_dim) + .def_readwrite("normalized_size", &LayerNorm::normalized_size); + +py::class_, OpDef> LinspaceInst(m, "Linspace"); + +LinspaceInst + .def(py::init(), py::arg("endpoint") = true, py::arg("comp_node"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("endpoint", &Linspace::endpoint) + .def_readwrite("comp_node", &Linspace::comp_node); + +py::class_, OpDef> MagicMindRuntimeInst(m, "MagicMindRuntime"); + +MagicMindRuntimeInst + .def(py::init(), py::arg("buf"), py::arg("buf_size"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("buf", &MagicMindRuntime::buf) + .def_readwrite("buf_size", &MagicMindRuntime::buf_size); + +py::class_, OpDef> MatrixInverseInst(m, "MatrixInverse"); + +MatrixInverseInst + .def(py::init<>()); + +py::class_, OpDef> MatrixMulInst(m, "MatrixMul"); + +MatrixMulInst.attr("ComputeMode") = BatchedMatrixMulInst.attr("ComputeMode"); + +MatrixMulInst.attr("Format") = BatchedMatrixMulInst.attr("Format"); + +MatrixMulInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +MatrixMulInst + .def(py::init(), 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") = {}) + .def(py::init<>()) + .def_readwrite("transposeA", &MatrixMul::transposeA) + .def_readwrite("transposeB", &MatrixMul::transposeB) + .def_readwrite("compute_mode", &MatrixMul::compute_mode) + .def_readwrite("format", &MatrixMul::format) + .def_readwrite("strategy", &MatrixMul::strategy) + .def_readwrite("workspace_limit", &MatrixMul::workspace_limit) + .def_readwrite("dimA", &MatrixMul::dimA) + .def_readwrite("dimB", &MatrixMul::dimB); + +py::class_, OpDef> MeshIndexingInst(m, "MeshIndexing"); + +MeshIndexingInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &MeshIndexing::items); + +py::class_, OpDef> NMSKeepInst(m, "NMSKeep"); + +NMSKeepInst + .def(py::init(), py::arg("iou_thresh"), py::arg("max_output"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("iou_thresh", &NMSKeep::iou_thresh) + .def_readwrite("max_output", &NMSKeep::max_output); + +py::class_, OpDef> NvOfInst(m, "NvOf"); + +NvOfInst + .def(py::init(), py::arg("precision") = 1, py::arg("scope") = {}) + .def_readwrite("precision", &NvOf::precision); + +py::class_, OpDef> PaddingInst(m, "Padding"); + +py::enum_(PaddingInst, "PaddingMode") + .value("REPLICATE", Padding::PaddingMode::REPLICATE) + .value("REFLECT", Padding::PaddingMode::REFLECT) + .value("CONSTANT", Padding::PaddingMode::CONSTANT) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "REPLICATE") return Padding::PaddingMode::REPLICATE; + if (str == "REFLECT") return Padding::PaddingMode::REFLECT; + if (str == "CONSTANT") return Padding::PaddingMode::CONSTANT; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +PaddingInst + .def(py::init(), 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") = {}) + .def_readwrite("front_offset_dim0", &Padding::front_offset_dim0) + .def_readwrite("front_offset_dim1", &Padding::front_offset_dim1) + .def_readwrite("front_offset_dim2", &Padding::front_offset_dim2) + .def_readwrite("front_offset_dim3", &Padding::front_offset_dim3) + .def_readwrite("front_offset_dim4", &Padding::front_offset_dim4) + .def_readwrite("front_offset_dim5", &Padding::front_offset_dim5) + .def_readwrite("front_offset_dim6", &Padding::front_offset_dim6) + .def_readwrite("back_offset_dim0", &Padding::back_offset_dim0) + .def_readwrite("back_offset_dim1", &Padding::back_offset_dim1) + .def_readwrite("back_offset_dim2", &Padding::back_offset_dim2) + .def_readwrite("back_offset_dim3", &Padding::back_offset_dim3) + .def_readwrite("back_offset_dim4", &Padding::back_offset_dim4) + .def_readwrite("back_offset_dim5", &Padding::back_offset_dim5) + .def_readwrite("back_offset_dim6", &Padding::back_offset_dim6) + .def_readwrite("padding_val", &Padding::padding_val) + .def_readwrite("padding_mode", &Padding::padding_mode); + +py::class_, OpDef> ParamPackConcatInst(m, "ParamPackConcat"); + +ParamPackConcatInst + .def(py::init, std::string>(), py::arg("offsets"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("offsets", &ParamPackConcat::offsets); + +py::class_, OpDef> ParamPackSplitInst(m, "ParamPackSplit"); + +ParamPackSplitInst + .def(py::init, std::vector>, std::string>(), py::arg("offsets"), py::arg("shapes"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("offsets", &ParamPackSplit::offsets) + .def_readwrite("shapes", &ParamPackSplit::shapes); + +py::class_, OpDef> PermutationRNGInst(m, "PermutationRNG"); + +PermutationRNGInst + .def(py::init(), py::arg("seed") = 0, py::arg("dtype") = megdnn::DType::from_enum(megdnn::DTypeEnum::Int32), py::arg("handle"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("seed", &PermutationRNG::seed) + .def_readwrite("dtype", &PermutationRNG::dtype) + .def_readwrite("handle", &PermutationRNG::handle); + +py::class_, OpDef> PixelShuffleInst(m, "PixelShuffle"); + +PixelShuffleInst + .def(py::init(), py::arg("factor"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("factor", &PixelShuffle::factor); + +py::class_, OpDef> PixelShuffleBackwardInst(m, "PixelShuffleBackward"); + +PixelShuffleBackwardInst + .def(py::init(), py::arg("factor"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("factor", &PixelShuffleBackward::factor); + +py::class_, OpDef> PoissonRNGInst(m, "PoissonRNG"); + +PoissonRNGInst + .def(py::init(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("seed", &PoissonRNG::seed) + .def_readwrite("handle", &PoissonRNG::handle); + +py::class_, OpDef> PoolingInst(m, "Pooling"); + +PoolingInst.attr("Mode") = AdaptivePoolingInst.attr("Mode"); + +PoolingInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +PoolingInst.attr("Strategy") = BatchConvBiasInst.attr("Strategy"); + +PoolingInst + .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") = {}) + .def_readwrite("mode", &Pooling::mode) + .def_readwrite("pad_h", &Pooling::pad_h) + .def_readwrite("pad_w", &Pooling::pad_w) + .def_readwrite("stride_h", &Pooling::stride_h) + .def_readwrite("stride_w", &Pooling::stride_w) + .def_readwrite("window_h", &Pooling::window_h) + .def_readwrite("window_w", &Pooling::window_w) + .def_readwrite("format", &Pooling::format) + .def_readwrite("strategy", &Pooling::strategy) + .def_readwrite("workspace_limit", &Pooling::workspace_limit); + +py::class_, OpDef> RNNInst(m, "RNN"); + +py::enum_(RNNInst, "NonlineMode") + .value("IDENTITY", RNN::NonlineMode::IDENTITY) + .value("RELU", RNN::NonlineMode::RELU) + .value("TANH", RNN::NonlineMode::TANH) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "IDENTITY") return RNN::NonlineMode::IDENTITY; + if (str == "RELU") return RNN::NonlineMode::RELU; + if (str == "TANH") return RNN::NonlineMode::TANH; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +RNNInst.attr("FwdMode") = BatchNormInst.attr("FwdMode"); + +RNNInst + .def(py::init(), 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") = {}) + .def_readwrite("num_layers", &RNN::num_layers) + .def_readwrite("bidirectional", &RNN::bidirectional) + .def_readwrite("bias", &RNN::bias) + .def_readwrite("hidden_size", &RNN::hidden_size) + .def_readwrite("dropout", &RNN::dropout) + .def_readwrite("nonlineMode", &RNN::nonlineMode) + .def_readwrite("fwd_mode", &RNN::fwd_mode); + +py::class_, OpDef> RNNCellInst(m, "RNNCell"); + +RNNCellInst.attr("NonlineMode") = RNNInst.attr("NonlineMode"); + +RNNCellInst + .def(py::init<::megdnn::param::RNNCell::NonlineMode, std::string>(), py::arg("nonlineMode") = ::megdnn::param::RNNCell::NonlineMode::IDENTITY, py::arg("scope") = {}) + .def_readwrite("nonlineMode", &RNNCell::nonlineMode); + +py::class_, OpDef> ROIAlignInst(m, "ROIAlign"); + +py::enum_(ROIAlignInst, "Mode") + .value("MAX", ROIAlign::Mode::MAX) + .value("AVERAGE", ROIAlign::Mode::AVERAGE) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "MAX") return ROIAlign::Mode::MAX; + if (str == "AVERAGE") return ROIAlign::Mode::AVERAGE; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +ROIAlignInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +ROIAlignInst + .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") = {}) + .def_readwrite("mode", &ROIAlign::mode) + .def_readwrite("format", &ROIAlign::format) + .def_readwrite("spatial_scale", &ROIAlign::spatial_scale) + .def_readwrite("offset", &ROIAlign::offset) + .def_readwrite("pooled_height", &ROIAlign::pooled_height) + .def_readwrite("pooled_width", &ROIAlign::pooled_width) + .def_readwrite("sample_height", &ROIAlign::sample_height) + .def_readwrite("sample_width", &ROIAlign::sample_width); + +py::class_, OpDef> ROIPoolingInst(m, "ROIPooling"); + +py::enum_(ROIPoolingInst, "Mode") + .value("MAX", ROIPooling::Mode::MAX) + .value("AVERAGE", ROIPooling::Mode::AVERAGE) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "MAX") return ROIPooling::Mode::MAX; + if (str == "AVERAGE") return ROIPooling::Mode::AVERAGE; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +ROIPoolingInst + .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") = {}) + .def_readwrite("mode", &ROIPooling::mode) + .def_readwrite("scale", &ROIPooling::scale); + +py::class_, OpDef> ReduceInst(m, "Reduce"); + +py::enum_(ReduceInst, "Mode") + .value("SUM", Reduce::Mode::SUM) + .value("SUM_SQR", Reduce::Mode::SUM_SQR) + .value("PRODUCT", Reduce::Mode::PRODUCT) + .value("MIN", Reduce::Mode::MIN) + .value("MAX", Reduce::Mode::MAX) + .value("MEAN", Reduce::Mode::MEAN) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "SUM") return Reduce::Mode::SUM; + if (str == "SUM_SQR") return Reduce::Mode::SUM_SQR; + if (str == "PRODUCT") return Reduce::Mode::PRODUCT; + if (str == "MIN") return Reduce::Mode::MIN; + if (str == "MAX") return Reduce::Mode::MAX; + if (str == "MEAN") return Reduce::Mode::MEAN; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(ReduceInst, "DataType") + .value("DEFAULT", Reduce::DataType::DEFAULT) + .value("FLOAT_IO16xC32", Reduce::DataType::FLOAT_IO16xC32) + .value("FLOAT_O32xC32", Reduce::DataType::FLOAT_O32xC32) + .value("FLOAT_O16xC32", Reduce::DataType::FLOAT_O16xC32) + .value("QUINT_I8xO32", Reduce::DataType::QUINT_I8xO32) + .value("QINT_I8xO32", Reduce::DataType::QINT_I8xO32) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "DEFAULT") return Reduce::DataType::DEFAULT; + if (str == "FLOAT_IO16xC32") return Reduce::DataType::FLOAT_IO16xC32; + if (str == "FLOAT_O32xC32") return Reduce::DataType::FLOAT_O32xC32; + if (str == "FLOAT_O16xC32") return Reduce::DataType::FLOAT_O16xC32; + if (str == "QUINT_I8xO32") return Reduce::DataType::QUINT_I8xO32; + if (str == "QINT_I8xO32") return Reduce::DataType::QINT_I8xO32; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +ReduceInst + .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") = {}) + .def_readwrite("mode", &Reduce::mode) + .def_readwrite("axis", &Reduce::axis) + .def_readwrite("data_type", &Reduce::data_type) + .def_readwrite("keepdim", &Reduce::keepdim); + +py::class_, OpDef> RemapInst(m, "Remap"); + +py::enum_(RemapInst, "InterpolationMode") + .value("NEAREST", Remap::InterpolationMode::NEAREST) + .value("LINEAR", Remap::InterpolationMode::LINEAR) + .value("AREA", Remap::InterpolationMode::AREA) + .value("CUBIC", Remap::InterpolationMode::CUBIC) + .value("LANCZOS4", Remap::InterpolationMode::LANCZOS4) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "NEAREST") return Remap::InterpolationMode::NEAREST; + if (str == "LINEAR") return Remap::InterpolationMode::LINEAR; + if (str == "AREA") return Remap::InterpolationMode::AREA; + if (str == "CUBIC") return Remap::InterpolationMode::CUBIC; + if (str == "LANCZOS4") return Remap::InterpolationMode::LANCZOS4; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +py::enum_(RemapInst, "BorderMode") + .value("REPLICATE", Remap::BorderMode::REPLICATE) + .value("REFLECT", Remap::BorderMode::REFLECT) + .value("REFLECT_101", Remap::BorderMode::REFLECT_101) + .value("WRAP", Remap::BorderMode::WRAP) + .value("CONSTANT", Remap::BorderMode::CONSTANT) + .value("TRANSPARENT", Remap::BorderMode::TRANSPARENT) + .value("ISOLATED", Remap::BorderMode::ISOLATED) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "REPLICATE") return Remap::BorderMode::REPLICATE; + if (str == "REFLECT") return Remap::BorderMode::REFLECT; + if (str == "REFLECT_101") return Remap::BorderMode::REFLECT_101; + if (str == "WRAP") return Remap::BorderMode::WRAP; + if (str == "CONSTANT") return Remap::BorderMode::CONSTANT; + if (str == "TRANSPARENT") return Remap::BorderMode::TRANSPARENT; + if (str == "ISOLATED") return Remap::BorderMode::ISOLATED; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +RemapInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +RemapInst + .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") = {}) + .def_readwrite("imode", &Remap::imode) + .def_readwrite("border_type", &Remap::border_type) + .def_readwrite("format", &Remap::format) + .def_readwrite("scalar", &Remap::scalar); + +py::class_, OpDef> RemoteRecvInst(m, "RemoteRecv"); + +RemoteRecvInst + .def(py::init, ::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") = {}) + .def(py::init<>()) + .def_readwrite("key", &RemoteRecv::key) + .def_readwrite("addr", &RemoteRecv::addr) + .def_readwrite("port", &RemoteRecv::port) + .def_readwrite("rank_from", &RemoteRecv::rank_from) + .def_readwrite("cn", &RemoteRecv::cn) + .def_readwrite("shape", &RemoteRecv::shape) + .def_readwrite("dtype", &RemoteRecv::dtype) + .def_readwrite("backend", &RemoteRecv::backend); + +py::class_, OpDef> RemoteSendInst(m, "RemoteSend"); + +RemoteSendInst + .def(py::init(), py::arg("key"), py::arg("addr"), py::arg("port"), py::arg("rank_to"), py::arg("backend"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("key", &RemoteSend::key) + .def_readwrite("addr", &RemoteSend::addr) + .def_readwrite("port", &RemoteSend::port) + .def_readwrite("rank_to", &RemoteSend::rank_to) + .def_readwrite("backend", &RemoteSend::backend); + +py::class_, OpDef> RemoveAxisInst(m, "RemoveAxis"); + +RemoveAxisInst + .def(py::init, std::string>(), py::arg("axis"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("axis", &RemoveAxis::axis); + +py::class_, OpDef> ReshapeInst(m, "Reshape"); + +ReshapeInst + .def(py::init, std::string>(), py::arg("axis") = ::megdnn::param::OptionalAxisV1::INVALID_AXIS, py::arg("shape"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("axis", &Reshape::axis) + .def_readwrite("shape", &Reshape::shape); + +py::class_, OpDef> ResizeInst(m, "Resize"); + +ResizeInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode"); + +ResizeInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +ResizeInst + .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") = {}) + .def_readwrite("imode", &Resize::imode) + .def_readwrite("format", &Resize::format); + +py::class_, OpDef> SVDInst(m, "SVD"); + +SVDInst + .def(py::init(), py::arg("full_matrices") = false, py::arg("compute_uv") = true, py::arg("scope") = {}) + .def_readwrite("full_matrices", &SVD::full_matrices) + .def_readwrite("compute_uv", &SVD::compute_uv); + +py::class_, OpDef> SetMeshIndexingInst(m, "SetMeshIndexing"); + +SetMeshIndexingInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &SetMeshIndexing::items); + +py::class_, OpDef> SetSubtensorInst(m, "SetSubtensor"); + +SetSubtensorInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &SetSubtensor::items); + +py::class_, OpDef> ShuffleRNGInst(m, "ShuffleRNG"); + +ShuffleRNGInst + .def(py::init(), py::arg("seed") = 0, py::arg("handle"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("seed", &ShuffleRNG::seed) + .def_readwrite("handle", &ShuffleRNG::handle); + +py::class_, OpDef> SlidingWindowTransposeInst(m, "SlidingWindowTranspose"); + +SlidingWindowTransposeInst + .def(py::init(), 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") = {}) + .def_readwrite("out_h", &SlidingWindowTranspose::out_h) + .def_readwrite("out_w", &SlidingWindowTranspose::out_w) + .def_readwrite("pad_h", &SlidingWindowTranspose::pad_h) + .def_readwrite("pad_w", &SlidingWindowTranspose::pad_w) + .def_readwrite("stride_h", &SlidingWindowTranspose::stride_h) + .def_readwrite("stride_w", &SlidingWindowTranspose::stride_w) + .def_readwrite("dilate_h", &SlidingWindowTranspose::dilate_h) + .def_readwrite("dilate_w", &SlidingWindowTranspose::dilate_w) + .def_readwrite("window_h", &SlidingWindowTranspose::window_h) + .def_readwrite("window_w", &SlidingWindowTranspose::window_w); + +py::class_, OpDef> SoftmaxInst(m, "Softmax"); + +SoftmaxInst + .def(py::init(), py::arg("axis") = -1, py::arg("scope") = {}) + .def_readwrite("axis", &Softmax::axis); + +py::class_, OpDef> SplitInst(m, "Split"); + +SplitInst + .def(py::init(), py::arg("axis"), py::arg("nsections"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("axis", &Split::axis) + .def_readwrite("nsections", &Split::nsections); + +py::class_, OpDef> SubtensorInst(m, "Subtensor"); + +SubtensorInst + .def(py::init>, std::string>(), py::arg("items"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("items", &Subtensor::items); + +py::class_, OpDef> TQTInst(m, "TQT"); + +TQTInst + .def(py::init(), py::arg("qmin") = -2147483648, py::arg("qmax") = 2147483647, py::arg("scope") = {}) + .def_readwrite("qmin", &TQT::qmin) + .def_readwrite("qmax", &TQT::qmax); + +py::class_, OpDef> TensorRTRuntimeInst(m, "TensorRTRuntime"); + +TensorRTRuntimeInst + .def(py::init(), py::arg("buf"), py::arg("buf_size"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("buf", &TensorRTRuntime::buf) + .def_readwrite("buf_size", &TensorRTRuntime::buf_size); + +py::class_, OpDef> TopKInst(m, "TopK"); + +py::enum_(TopKInst, "Mode") + .value("KTH_ONLY", TopK::Mode::KTH_ONLY) + .value("VALUE_IDX_NOSORT", TopK::Mode::VALUE_IDX_NOSORT) + .value("VALUE_IDX_SORTED", TopK::Mode::VALUE_IDX_SORTED) + .def(py::init([](const std::string& in) { + auto&& str = normalize_enum(in); + if (str == "KTH_ONLY") return TopK::Mode::KTH_ONLY; + if (str == "VALUE_IDX_NOSORT") return TopK::Mode::VALUE_IDX_NOSORT; + if (str == "VALUE_IDX_SORTED") return TopK::Mode::VALUE_IDX_SORTED; + throw py::cast_error("invalid enum value " + in); + })); +py::implicitly_convertible(); + +TopKInst + .def(py::init<::megdnn::param::TopK::Mode, std::string>(), py::arg("mode") = ::megdnn::param::TopK::Mode::KTH_ONLY, py::arg("scope") = {}) + .def_readwrite("mode", &TopK::mode); + +py::class_, OpDef> TypeCvtInst(m, "TypeCvt"); + +TypeCvtInst + .def(py::init<::megdnn::DType, std::string>(), py::arg("dtype"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("dtype", &TypeCvt::dtype); + +py::class_, OpDef> UniformRNGInst(m, "UniformRNG"); + +UniformRNGInst + .def(py::init(), py::arg("seed") = 0, py::arg("dtype") = megdnn::DType::from_enum(megdnn::DTypeEnum::Float32), py::arg("handle"), py::arg("scope") = {}) + .def(py::init<>()) + .def_readwrite("seed", &UniformRNG::seed) + .def_readwrite("dtype", &UniformRNG::dtype) + .def_readwrite("handle", &UniformRNG::handle); + +py::class_, OpDef> WarpAffineInst(m, "WarpAffine"); + +WarpAffineInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode"); + +WarpAffineInst.attr("BorderMode") = RemapInst.attr("BorderMode"); + +WarpAffineInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +WarpAffineInst + .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") = {}) + .def_readwrite("imode", &WarpAffine::imode) + .def_readwrite("border_mode", &WarpAffine::border_mode) + .def_readwrite("border_val", &WarpAffine::border_val) + .def_readwrite("format", &WarpAffine::format); + +py::class_, OpDef> WarpPerspectiveInst(m, "WarpPerspective"); + +WarpPerspectiveInst.attr("InterpolationMode") = RemapInst.attr("InterpolationMode"); + +WarpPerspectiveInst.attr("BorderMode") = RemapInst.attr("BorderMode"); + +WarpPerspectiveInst.attr("Format") = AdaptivePoolingInst.attr("Format"); + +WarpPerspectiveInst + .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") = {}) + .def_readwrite("imode", &WarpPerspective::imode) + .def_readwrite("bmode", &WarpPerspective::bmode) + .def_readwrite("format", &WarpPerspective::format) + .def_readwrite("border_val", &WarpPerspective::border_val); + +// clang-format on diff --git a/imperative/tablegen/genhash.cmake b/imperative/tablegen/genhash.cmake new file mode 100644 index 00000000..267fd9de --- /dev/null +++ b/imperative/tablegen/genhash.cmake @@ -0,0 +1,12 @@ +set(SOURCES + ../../dnn/scripts/opr_param_defs.py + ../../src/core/include/megbrain/ir/ops.td + generated/opdef.h.inl + generated/opdef.cpp.inl + generated/opdef.py.inl + generated/opdef.cpy.inl + generated/enum_macro.h) +execute_process(COMMAND ${CMAKE_COMMAND} -E md5sum ${SOURCES} + OUTPUT_VARIABLE HASH_CONTENT) +message(STATUS "Generating hash.txt for opdefs") +file(WRITE generated/hash.txt "${HASH_CONTENT}") diff --git a/imperative/test/CMakeLists.txt b/imperative/test/CMakeLists.txt index e2e8314a..d7863049 100644 --- a/imperative/test/CMakeLists.txt +++ b/imperative/test/CMakeLists.txt @@ -12,9 +12,9 @@ endif() # TODO: turn python binding into a static/object library add_executable(imperative_test ${SOURCES} ${SRCS}) add_dependencies(imperative_test mgb_opdef) -target_include_directories( - imperative_test PRIVATE ${MGB_TEST_DIR}/include ../src/include ${MGB_OPDEF_OUT_DIR} - ${CPP_REDIS_INCLUDES}) +target_include_directories(imperative_test PRIVATE ${MGB_TEST_DIR}/include + ../src/include ${CPP_REDIS_INCLUDES}) +target_link_libraries(imperative_test mgb_opdef_inc) # Python binding target_include_directories(