From cdb692d2faf345c006f503b9a10418139a82f013 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Tue, 7 Sep 2021 15:28:53 +0800 Subject: [PATCH] refactor(imperative): add TODO tag for some functions GitOrigin-RevId: e295a1fa5537f13bc65f9e82b44a3f9cd56992a6 --- .../python/megengine/core/ops/custom.py | 9 +++++++- imperative/src/impl/ops/custom_opdef.cpp | 21 ++++++------------- src/opr/impl/custom_opnode.cpp | 6 ++++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/imperative/python/megengine/core/ops/custom.py b/imperative/python/megengine/core/ops/custom.py index 75e56aa89..b1a055fd8 100644 --- a/imperative/python/megengine/core/ops/custom.py +++ b/imperative/python/megengine/core/ops/custom.py @@ -7,13 +7,20 @@ # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -from .._imperative_rt.ops._custom import _install, _uninstall, _get_custom_op_list, _make_custom_op +from .._imperative_rt.ops._custom import ( + _get_custom_op_list, + _install, + _make_custom_op, + _uninstall, +) __all__ = ["load"] + def _gen_custom_op_maker(custom_op_name): def op_maker(**kwargs): return _make_custom_op(custom_op_name, kwargs) + return op_maker diff --git a/imperative/src/impl/ops/custom_opdef.cpp b/imperative/src/impl/ops/custom_opdef.cpp index f1353c935..b178c07c2 100644 --- a/imperative/src/impl/ops/custom_opdef.cpp +++ b/imperative/src/impl/ops/custom_opdef.cpp @@ -95,6 +95,7 @@ std::tuple, bool> CustomOpDef::infer_output_attrs for (auto i_shape: i_shapes) { if (i_shape.ndim == 0) { success = false; + break; } } @@ -187,14 +188,11 @@ void apply_on_device_tensornd(const OpDef& def, auto cn = output.comp_node(); cn.activate(); } + + // [TODO] sync should be modified CompNode::sync_all(); auto&& op = static_cast(def); op.compute(inputs, outputs); - - // for (auto &&output: (*outputs)) { - // auto cn = output.comp_node(); - // cn.sync(); // cannot sync ?????????? - // } CompNode::sync_all(); } @@ -224,19 +222,11 @@ SmallVector apply_on_physical_tensor( } VarNodeArray apply_on_var_node(const OpDef &def, const cg::VarNodeArray &inputs) { - SymbolVarArray input_syms; - for (auto &input_var: inputs) - input_syms.emplace_back(input_var); - auto&& op = static_cast(def); OperatorNodeConfig config; - SymbolVarArray output_syms = opr::CustomOpNode::make( - op.impl(), input_syms, op.param(), config + VarNodeArray outputs = opr::CustomOpNode::make( + op.impl(), inputs, op.param(), config ); - - VarNodeArray outputs; - for (auto &output_sym: output_syms) - outputs.push_back(output_sym.node()); return outputs; } @@ -273,6 +263,7 @@ bool is_same_st(const OpDef& lhs, const OpDef& rhs) { return a.param() == b.param() && a.runtime_id() == b.runtime_id(); } +// [TODO] to be implemented std::vector> props(const OpDef& def) { mgb_assert(false, "Custom OpDef Props Function is not IMPLEMENTED now"); // can be implement with param schema diff --git a/src/opr/impl/custom_opnode.cpp b/src/opr/impl/custom_opnode.cpp index 4fb49a185..2408a7b51 100644 --- a/src/opr/impl/custom_opnode.cpp +++ b/src/opr/impl/custom_opnode.cpp @@ -140,7 +140,8 @@ void CustomOpNode::do_execute(ExecEnv &env) { std::vector custom_inputs = custom::to_custom(inputs); std::vector custom_outputs = custom::to_custom(outputs); m_op->compute(custom_inputs, m_param, custom_outputs); - CompNode::sync_all(); // whether reasonable + // [TODO] sync should be modified + CompNode::sync_all(); this->owner_graph()->event().signal_inplace( this, m_comp_node @@ -157,7 +158,8 @@ void CustomOpNode::init_output_static_infer_desc() { auto &&mgr = owner_graph()->static_infer_manager(); DepVal dep; - if (true) { // need design a function to allow user to decide it + // [TODO] need design a interface to allow user to decide it + if (true) { for (auto input_var: input()) dep.push_back({input_var, DepType::SHAPE}); } -- GitLab