diff --git a/imperative/src/impl/ops/utility.cpp b/imperative/src/impl/ops/utility.cpp index 8c68ad741fd306de22f62143a4f60966ef47c92c..21104a726890b2b25c97a777a0152281e8a7e93b 100644 --- a/imperative/src/impl/ops/utility.cpp +++ b/imperative/src/impl/ops/utility.cpp @@ -288,6 +288,7 @@ ComputingGraphHolder& get_computing_graph(std::shared_ptr compiled_op, Sm cg_holder.graph->options().async_exec_level = 0; cg_holder.graph->options().graph_opt_level = compiled_op->cast_final_safe().gopt_level; cg_holder.graph->options().enable_var_mem_defragment = false; + cg_holder.graph->options().comp_seq_sync_device = false; cg_holder.graph->set_device_memory_allocator(cg_holder.allocator); // cg_holder.graph->options().graph_opt.jit = 2; VarNodeArray input_vars; diff --git a/src/core/impl/graph/cg_impl_seq.cpp b/src/core/impl/graph/cg_impl_seq.cpp index 1d5444d654cc521bbb6d55e9d57c23ce10c1d6e6..b5fa89e363997e00682f779b0c25841c4b2456cb 100644 --- a/src/core/impl/graph/cg_impl_seq.cpp +++ b/src/core/impl/graph/cg_impl_seq.cpp @@ -385,21 +385,27 @@ void ComputingGraphImpl::ComputingSequence::do_wait(bool explicit_user_wait) { } } - for (auto cn : m_used_comp_node) { - m_event_end.at(cn)->host_wait(); + bool sync_device = m_owner_graph->options().comp_seq_sync_device; + + if (sync_device) { + for (auto cn : m_used_comp_node) { + m_event_end.at(cn)->host_wait(); + } } m_wait_finished = true; #if MGB_NEED_MEGDNN_ASYNC_ERROR // FIXME: It CAN NOT work well if more than one ComputingSequnces has been // executed on the same compnode and got AsyncError concurrently, because // only the first async error on each comp_node would be recorded. - for (auto&& cn : m_used_comp_node) { - auto error = cn.check_async_error(); - if (error) { - static_cast(error->extra_info()) - ->opr() - ->owner_graph() - ->record_async_error(std::move(error)); + if (sync_device) { + for (auto&& cn : m_used_comp_node) { + auto error = cn.check_async_error(); + if (error) { + static_cast(error->extra_info()) + ->opr() + ->owner_graph() + ->record_async_error(std::move(error)); + } } } #endif diff --git a/src/core/include/megbrain/graph/cg.h b/src/core/include/megbrain/graph/cg.h index bbca52052d440113beb8523c3d59f9ee73b8949a..d2de7c25d9f885beaef75212f52e8e060170d6ae 100644 --- a/src/core/include/megbrain/graph/cg.h +++ b/src/core/include/megbrain/graph/cg.h @@ -520,6 +520,9 @@ class ComputingGraph : public std::enable_shared_from_this, */ bool no_force_inplace = false; + //! whether to sync comp_node when waiting computing sequence + bool comp_seq_sync_device = true; + //! add extra deps for the comp seq if a specific var is dependent ThinHashMap extra_vardeps;