提交 8db64303 编写于 作者: M Megvii Engine Team

fix(src/atlas): fixed no event resource when call aclrtRecordEvent function of atlas

GitOrigin-RevId: d688ba6b249678f13f723e16eafc260aeae1c79b
上级 c515ee1c
...@@ -286,6 +286,7 @@ class AtlasCompNode::EventImpl final : public EventImplHelper { ...@@ -286,6 +286,7 @@ class AtlasCompNode::EventImpl final : public EventImplHelper {
AtlasCompNodeImpl* const m_comp_node_impl; AtlasCompNodeImpl* const m_comp_node_impl;
aclrtEvent m_atlas_event; aclrtEvent m_atlas_event;
bool m_init_finished = false; bool m_init_finished = false;
bool m_used_for_sync = false;
void do_record() override { void do_record() override {
m_comp_node_impl->activate(); m_comp_node_impl->activate();
...@@ -306,6 +307,10 @@ class AtlasCompNode::EventImpl final : public EventImplHelper { ...@@ -306,6 +307,10 @@ class AtlasCompNode::EventImpl final : public EventImplHelper {
void host_wait_cv() override { void host_wait_cv() override {
MGB_ATLAS_CHECK(aclrtSynchronizeEvent(m_atlas_event)); MGB_ATLAS_CHECK(aclrtSynchronizeEvent(m_atlas_event));
if (m_used_for_sync) {
MGB_ATLAS_CHECK(aclrtResetEvent(
m_atlas_event, m_comp_node_impl->m_env.atlas_env().stream));
}
} }
double do_elapsed_time_until(EventImplHelper& end) override { double do_elapsed_time_until(EventImplHelper& end) override {
...@@ -322,8 +327,14 @@ public: ...@@ -322,8 +327,14 @@ public:
EventImpl(AtlasCompNodeImpl* comp_node_impl, size_t create_flags) EventImpl(AtlasCompNodeImpl* comp_node_impl, size_t create_flags)
: EventImplHelper(comp_node_impl, create_flags), : EventImplHelper(comp_node_impl, create_flags),
m_comp_node_impl{comp_node_impl} { m_comp_node_impl{comp_node_impl} {
m_used_for_sync = !(m_create_flags & NEED_TIMER);
m_comp_node_impl->activate(); m_comp_node_impl->activate();
MGB_ATLAS_CHECK(aclrtCreateEvent(&m_atlas_event)); if (m_used_for_sync) {
MGB_ATLAS_CHECK(aclrtCreateEvent(&m_atlas_event));
} else {
MGB_ATLAS_CHECK(
aclrtCreateEventWithFlag(&m_atlas_event, ACL_EVENT_TIME_LINE));
}
m_init_finished = true; m_init_finished = true;
} }
~EventImpl() { ~EventImpl() {
...@@ -346,11 +357,19 @@ void AtlasCompNode::EventImpl::do_device_wait_by(Impl* cn_impl) { ...@@ -346,11 +357,19 @@ void AtlasCompNode::EventImpl::do_device_wait_by(Impl* cn_impl) {
auto stream = imp->m_env.atlas_env().stream; auto stream = imp->m_env.atlas_env().stream;
imp->activate(); imp->activate();
MGB_ATLAS_CHECK(aclrtStreamWaitEvent(stream, m_atlas_event)); MGB_ATLAS_CHECK(aclrtStreamWaitEvent(stream, m_atlas_event));
if (m_used_for_sync) {
MGB_ATLAS_CHECK(aclrtResetEvent(
m_atlas_event, m_comp_node_impl->m_env.atlas_env().stream));
}
return; return;
} }
if (cn_impl->env().property().type == DeviceType::CPU) { if (cn_impl->env().property().type == DeviceType::CPU) {
auto waiter = [this]() { auto waiter = [this]() {
MGB_ATLAS_CHECK(aclrtSynchronizeEvent(m_atlas_event)); MGB_ATLAS_CHECK(aclrtSynchronizeEvent(m_atlas_event));
if (m_used_for_sync) {
MGB_ATLAS_CHECK(aclrtResetEvent(
m_atlas_event, m_comp_node_impl->m_env.atlas_env().stream));
}
}; };
cn_impl->add_callback(std::move(waiter)); cn_impl->add_callback(std::move(waiter));
return; return;
......
...@@ -192,7 +192,7 @@ AtlasRuntimeOpr::AtlasRuntimeOpr( ...@@ -192,7 +192,7 @@ AtlasRuntimeOpr::AtlasRuntimeOpr(
MGB_ATLAS_CHECK(aclmdlSetConfigOpt( MGB_ATLAS_CHECK(aclmdlSetConfigOpt(
config_handle, ACL_MDL_MEM_SIZET, &mdl_mem_size, sizeof(size_t))); config_handle, ACL_MDL_MEM_SIZET, &mdl_mem_size, sizeof(size_t)));
size_t mem_optimize_mode = 1; size_t mem_optimize_mode = true;
MGB_ATLAS_CHECK(aclmdlSetConfigOpt( MGB_ATLAS_CHECK(aclmdlSetConfigOpt(
config_handle, ACL_MDL_WORKSPACE_MEM_OPTIMIZE, &mem_optimize_mode, config_handle, ACL_MDL_WORKSPACE_MEM_OPTIMIZE, &mem_optimize_mode,
sizeof(size_t))); sizeof(size_t)));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册