janetsc commented on code in PR #13181:
URL: https://github.com/apache/tvm/pull/13181#discussion_r1005850161


##########
src/runtime/hexagon/hexagon_hvx.cc:
##########
@@ -31,25 +31,28 @@ namespace tvm {
 namespace runtime {
 namespace hexagon {
 
-HexagonHvx::HexagonHvx() {
-  // Reserve HVX.
-  int res = qurt_hvx_reserve(QURT_HVX_RESERVE_ALL_AVAILABLE);
-  CHECK((res != QURT_HVX_RESERVE_NOT_SUPPORTED) && (res != 
QURT_HVX_RESERVE_NOT_SUCCESSFUL))
-      << "error reserving HVX: " << res;
+HexagonHvx::HexagonHvx() { Acquire(); }
 
-  // Lock HVX.
+HexagonHvx::~HexagonHvx() { Release(); }
+
+void HexagonHvx::Acquire() {
+  reserved_count_ = qurt_hvx_reserve(QURT_HVX_RESERVE_ALL);
+  CHECK(reserved_count_ == QURT_HVX_RESERVE_ALL) << "error reserving HVX: " << 
reserved_count_;
+}
+
+void HexagonHvx::Release() {
+  int rel = qurt_hvx_cancel_reserve();
+  CHECK(rel == 0) << "error releasing HVX: " << rel;
+}
+
+void HexagonHvx::Lock() {
   int lck = qurt_hvx_lock(QURT_HVX_MODE_128B);
   CHECK(lck == 0) << "error locking HVX: " << lck;
 }
 
-HexagonHvx::~HexagonHvx() {

Review Comment:
   This is by design.  Reserve/release happen in the constructor/destructors, 
and lock/unlock must happen on the thread that is dedicated to that resource.  
In the case of HVX, it will be called 4 times.
   
   You bring up a good point, which is what happens if one of the threads 
crashes before it can unlock?  I test offline.  (There's not really a good way 
to incorporate that test, because other tests that run in parallel depend on 
the resources being acquired.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to