Unverified Commit 7512f0ef authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Merge branch 'master' into aprocter/dyn-reshape

parents 750b7e79 b02b0812
......@@ -103,17 +103,23 @@ shared_ptr<runtime::Executable>
#endif
shared_ptr<runtime::Executable> rc;
auto it = m_exec_map.find(func);
if (it != m_exec_map.end())
// we will protect the access to map (m_exec_map) across multiple threads by creating a lock_gaurd
// m_exec_map_mutex will be released once the object `guard` goes out of scope
{
rc = it->second;
std::lock_guard<std::mutex> guard(m_exec_map_mutex);
auto it = m_exec_map.find(func);
if (it != m_exec_map.end())
{
rc = it->second;
return rc;
}
}
else
rc = make_shared<CPU_Executable>(func, pass_config, performance_counters_enabled);
{
rc = make_shared<CPU_Executable>(func, pass_config, performance_counters_enabled);
std::lock_guard<std::mutex> guard(m_exec_map_mutex);
m_exec_map.insert({func, rc});
return rc;
}
return rc;
}
runtime::cpu::CPU_Executable::CPU_Executable(shared_ptr<Function> func,
......@@ -156,6 +162,7 @@ bool runtime::cpu::CPU_Executable::call(const vector<shared_ptr<runtime::Tensor>
void runtime::cpu::CPU_Backend::remove_compiled_function(shared_ptr<Executable> exec)
{
std::lock_guard<std::mutex> guard(m_exec_map_mutex);
for (auto it = m_exec_map.begin(); it != m_exec_map.end(); ++it)
{
if (it->second == exec)
......
......@@ -18,6 +18,7 @@
#include <map>
#include <memory>
#include <mutex>
#include "cpu_backend_visibility.h"
#include "ngraph/pass/pass_config.hpp"
......@@ -63,6 +64,9 @@ namespace ngraph
bool is_supported_property(const Property prop) const override;
private:
// this mutex will be used to protect the addition and deletion
// of function to m_exec_map across multiple threads
std::mutex m_exec_map_mutex;
std::unordered_map<std::shared_ptr<Function>, std::shared_ptr<Executable>>
m_exec_map;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment