[2022.3] Fix TSAN issues in GNA plugin (#17216)

* Fix TSAN issue in GNA plugin (#17163)

* Fix TSAN issue No2 in GNA plugin (#17185)

* Fix TSAN issue No2 in GNA plugin

* Misprint

* Add copyright
This commit is contained in:
Vitaliy Urusovskij 2023-04-26 15:40:12 +04:00 committed by GitHub
parent 72877d4b09
commit ed4a7a3842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 10 deletions

View File

@ -18,7 +18,7 @@ namespace InferenceEngine {
/**
* @brief This class provides optimal thread safe default implementation.
* The class is recommended to be used as a base class for Executable Network impleentation during plugin development.
* The class is recommended to be used as a base class for Executable Network implementation during plugin development.
* @ingroup ie_dev_api_exec_network_api
*/
class ExecutableNetworkThreadSafeDefault : public IExecutableNetworkInternal {

View File

@ -17,10 +17,11 @@ namespace GNAPluginNS {
class GNAPluginInternal : public InferenceEngine::IInferencePlugin {
private:
std::mutex syncCallsToLoadExeNetworkImpl;
mutable std::mutex syncCalls;
Config defaultConfig;
std::weak_ptr <GNAPlugin> plgPtr;
std::shared_ptr<GNAPlugin> GetCurrentPlugin() const {
std::lock_guard<std::mutex> lock{syncCalls};
auto ptr = plgPtr.lock();
if (ptr == nullptr) {
return std::make_shared<GNAPlugin>();
@ -34,9 +35,9 @@ protected:
public:
InferenceEngine::IExecutableNetworkInternal::Ptr LoadExeNetworkImpl(
const InferenceEngine::CNNNetwork &network,
const std::map<std::string, std::string> &config) override {
std::lock_guard<std::mutex> lock{ syncCallsToLoadExeNetworkImpl };
const InferenceEngine::CNNNetwork& network,
const std::map<std::string, std::string>& config) override {
std::lock_guard<std::mutex> lock{syncCalls};
Config updated_config(defaultConfig);
updated_config.UpdateFromMap(config);
auto plg = std::make_shared<GNAPlugin>(updated_config.keyConfigMap);
@ -50,8 +51,9 @@ public:
}
InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork(
const std::string &modelFileName,
const std::map<std::string, std::string> &config) override {
const std::string& modelFileName,
const std::map<std::string, std::string>& config) override {
std::lock_guard<std::mutex> lock{syncCalls};
Config updated_config(defaultConfig);
updated_config.UpdateFromMap(config);
auto plg = std::make_shared<GNAPlugin>(updated_config.keyConfigMap);
@ -63,8 +65,10 @@ public:
return network_impl;
}
InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork(std::istream& networkModel,
const std::map<std::string, std::string>& config) override {
InferenceEngine::IExecutableNetworkInternal::Ptr ImportNetwork(
std::istream& networkModel,
const std::map<std::string, std::string>& config) override {
std::lock_guard<std::mutex> lock{syncCalls};
Config updated_config(defaultConfig);
updated_config.UpdateFromMap(config);
auto plg = std::make_shared<GNAPlugin>(updated_config.keyConfigMap);

View File

@ -0,0 +1,11 @@
// Copyright (C) 2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "log.hpp"
namespace ov {
namespace intel_gna {
std::mutex GnaLog::mutex_;
} // namespace intel_gna
} // namespace ov

View File

@ -4,8 +4,9 @@
#pragma once
#include <ostream>
#include <iostream>
#include <mutex>
#include <ostream>
#include "openvino/runtime/properties.hpp"
@ -23,6 +24,7 @@ class GnaLog {
GnaLog() = default;
static GnaLog& log(ov::log::Level log_level) {
std::lock_guard<std::mutex> guard(mutex_);
GnaLog& obj = get_instance();
obj.message_level_ = log_level;
obj << "[" << log_level << "]" << " ";
@ -34,6 +36,7 @@ class GnaLog {
/** Log level of particular log message */
ov::log::Level message_level_ = ov::log::Level::NO;
static std::mutex mutex_;
static GnaLog& get_instance() {
static GnaLog log_obj;