You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by mo...@apache.org on 2022/09/16 18:53:58 UTC
[tvm] branch main updated: [Hexagon] [runtime] Protect access to global HexagonBufferManager map (#12807)
This is an automated email from the ASF dual-hosted git repository.
moreau pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 7c96e255ce [Hexagon] [runtime] Protect access to global HexagonBufferManager map (#12807)
7c96e255ce is described below
commit 7c96e255ce7d6d6a22b3665449ebfafb581a9fc8
Author: Janet Schneider <ja...@gmail.com>
AuthorDate: Fri Sep 16 11:53:53 2022 -0700
[Hexagon] [runtime] Protect access to global HexagonBufferManager map (#12807)
* Protect access to global buffer manager map
* Fix lint
---
src/runtime/hexagon/hexagon_buffer_manager.h | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/runtime/hexagon/hexagon_buffer_manager.h b/src/runtime/hexagon/hexagon_buffer_manager.h
index 658a39fac8..a698b0ecb1 100644
--- a/src/runtime/hexagon/hexagon_buffer_manager.h
+++ b/src/runtime/hexagon/hexagon_buffer_manager.h
@@ -43,7 +43,10 @@ class HexagonBufferManager {
CHECK(it != hexagon_buffer_map_.end())
<< "Attempt made to free unknown or already freed dataspace allocation";
CHECK(it->second != nullptr);
- hexagon_buffer_map_.erase(it);
+ {
+ std::lock_guard<std::mutex> lock(map_mutex_);
+ hexagon_buffer_map_.erase(it);
+ }
}
/*!
* \brief Allocate a HexagonBuffer.
@@ -53,15 +56,22 @@ class HexagonBufferManager {
void* AllocateHexagonBuffer(Args&&... args) {
auto buf = std::make_unique<HexagonBuffer>(std::forward<Args>(args)...);
void* ptr = buf->GetPointer();
- hexagon_buffer_map_.insert({ptr, std::move(buf)});
+ {
+ std::lock_guard<std::mutex> lock(map_mutex_);
+ hexagon_buffer_map_.insert({ptr, std::move(buf)});
+ }
return ptr;
}
//! \brief Returns whether the HexagonBuffer is in the map.
- size_t count(void* ptr) { return hexagon_buffer_map_.count(ptr); }
+ size_t count(void* ptr) {
+ std::lock_guard<std::mutex> lock(map_mutex_);
+ return hexagon_buffer_map_.count(ptr);
+ }
//! \brief Returns an iterator to the HexagonBuffer within the map.
HexagonBuffer* find(void* ptr) {
+ std::lock_guard<std::mutex> lock(map_mutex_);
auto it = hexagon_buffer_map_.find(ptr);
if (it != hexagon_buffer_map_.end()) {
return it->second.get();
@@ -69,9 +79,18 @@ class HexagonBufferManager {
return nullptr;
}
+ //! \brief Returns whether the HexagonBufferManager has any allocations.
+ bool empty() {
+ std::lock_guard<std::mutex> lock(map_mutex_);
+ return hexagon_buffer_map_.empty();
+ }
+
private:
//! \brief Contains the HexagonBuffer objects managed by this class.
std::unordered_map<void*, std::unique_ptr<HexagonBuffer>> hexagon_buffer_map_;
+
+ //! \brief Protects updates to the map.
+ std::mutex map_mutex_;
};
} // namespace hexagon