Skip to content

Commit f6c3cec

Browse files
authored
Fix for coverity issue of medium impact: Possible data race (#27918)
### Details: - *Fixed "Data race condition" (Medium) Coverity issue* - *Mirrored part of #27916 ### Tickets: - *EISW-149544*
1 parent 3085215 commit f6c3cec

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,15 @@ ov::Tensor Bank::eval_and_alloc(const LazyTensor& tensor,
132132

133133
bool Bank::is_remote(const LazyTensor& tensor) const {
134134
// FIXME: make generic
135+
std::lock_guard<std::mutex> guard(m_mutex);
136+
135137
auto npu_bank = m_device_banks.find("NPU");
136-
if (npu_bank != m_device_banks.end() && npu_bank->second.storage.find(tensor) != npu_bank->second.storage.end()) {
137-
// Found in NPU bank so considered remote (utterly wrong for the generic case)
138-
return true;
138+
if (npu_bank != m_device_banks.end()) {
139+
std::lock_guard<std::mutex> dev_guard(npu_bank->second.mutex);
140+
if (npu_bank->second.storage.find(tensor) != npu_bank->second.storage.end()) {
141+
// Found in NPU bank so considered remote (utterly wrong for the generic case)
142+
return true;
143+
}
139144
}
140145
return false;
141146
}

src/plugins/intel_npu/src/plugin/npuw/weights_bank.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ class Bank {
3838
// Bank for specified device and their allocated memory
3939
struct DeviceBank {
4040
std::unordered_map<LazyTensor, ov::Tensor, LazyTensor::Hash> storage;
41-
std::mutex mutex;
41+
mutable std::mutex mutex;
4242
};
4343
std::unordered_map<std::string, DeviceBank> m_device_banks;
4444

4545
ov::Tensor eval_and_alloc(const LazyTensor& tensor, DeviceBank& dbank, const std::string& device);
4646

47-
std::mutex m_mutex;
47+
mutable std::mutex m_mutex;
4848
std::shared_ptr<const ov::ICore> m_core = nullptr;
4949
std::string m_alloc_device;
5050
};

0 commit comments

Comments
 (0)