MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / init_ops

Function init_ops

imperative/python/src/ops.cpp:541–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

539} // namespace PYBIND11_NAMESPACE
540
541void init_ops(py::module m) {
542 _init_py_op_def(m);
543 _init_py_op_base(m);
544 INIT_ALL_OP(m)
545
546 m.def("new_rng_handle", &rng::new_handle);
547 m.def(
548 "delete_rng_handle",
549 [](size_t handle) {
550 if (mgb::imperative::python::interpreter_for_py->check_available()) {
551 mgb::imperative::python::interpreter_for_py->sync();
552 }
553 mgb::CompNode::sync_all();
554 mgb::CompNode::foreach ([](mgb::CompNode cn) {
555 auto err = cn.check_async_error();
556 mgb_assert(!err, "%s", err->what());
557 });
558 py_task_q.wait_all_task_finish();
559 rng::delete_handle(handle);
560 },
561 py::call_guard<py::gil_scoped_release>());
562 m.def("set_global_rng_seed", [](uint64_t seed) -> void {
563 mgb_assert(
564 python::interpreter_for_py->check_available(),
565 "set global random seed failed since imperative interpreter has been "
566 "destroyed");
567 python::interpreter_for_py->sync();
568 mgb::CompNode::sync_all();
569 rng::set_global_rng_seed(seed);
570 });
571 m.def("get_global_rng_seed", &rng::get_global_rng_seed);
572 m.def("get_rng_handle_compnode", &rng::get_rng_handle_compnode);
573
574 struct PySubgraphBuilder {
575 explicit PySubgraphBuilder(std::string name) : name{name} {}
576 std::string name;
577 Subgraph graph;
578 mgb::SmallVector<bool> output_grad_mask;
579 Subgraph::var_t next_var = 1;
580 std::shared_ptr<mgb::Hashable> key = nullptr;
581
582 std::shared_ptr<OpDef> build() {
583 if (key == nullptr) {
584 key = std::make_shared<UniqueKey>();
585 }
586 return SubgraphOp::make(
587 name, std::make_shared<Subgraph>(graph), output_grad_mask, key);
588 }
589 };
590
591 py::class_<PySubgraphBuilder>(m, "SubgraphBuilder")
592 .def(py::init<std::string>())
593 .def(py::init<PySubgraphBuilder>())
594 .def("input",
595 [](PySubgraphBuilder& self) {
596 mgb_assert(self.key == nullptr);
597 auto var = self.next_var++;
598 self.graph.inputs.push_back(var);

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 15

_init_py_op_defFunction · 0.85
_init_py_op_baseFunction · 0.85
delete_handleFunction · 0.85
set_global_rng_seedFunction · 0.85
np2tensorFunction · 0.85
submoduleFunction · 0.85
init_customFunction · 0.85
check_availableMethod · 0.80
check_async_errorMethod · 0.80
resizeMethod · 0.80
attrMethod · 0.80
makeFunction · 0.50

Tested by

no test coverage detected