-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Hexagon] Add HexagonThreadManager (#11653)
* Adding initial threadmanager class * Fixed compile errors * Moving constant defines inside class * Updating qurt includes * use default scope for hexagon buffers * Updating buffer allocations * Fixed bug where array of pointers treated as array of structs * - Updated HexgonDeviceAPI to use HexagonThreadManager - Updated HexagonThreadManager interface to use TVMStreams - Added second `Dispatch` interfce in thread manager to use PackedFuncs - Updated thread manager to use vector for dynamic semaphore allocation - Added "#if defined(__hexagon__)" in several places to prevent compilation errors * Bug fixes + interface addition + basic thread tests - Fixed GetStreams not returning the streams properly - Added missing semaphore cleanup to prevent qurt kernel resource leakage - new interface functions: - Start() : now all worker threads are blocked on initialization until ThreadManager->Start() is called - WaitOnThreads() : blocking call which waits until all worker thread queues are empty - added extra debug logging - Two new basic thread tests working * Adding initial ThreadManager tests * HexagonThreadManager tests and refactor * remove stack / pipe size member vars * init pointers in the header file * move all mem allocs to SpawnThreads * start_semaphore as object instead of pointer * fix bug with WaitOnThreads deadlock + Wait/Signal off by one error * add / refactor Signal / Wait tests * add SyncFromTo test cases * add Dispatch test cases * add pipe fill and overflow cases * Updating dispatch to return bool and fix pipe overflow problem * change around min / max values for stack / pipe * integrate pipe fill / overflow tests back into HTM test suite * use HexagonBuffer * assert if stack / pipe sizes fall below min * Changed semaphore vector to store pointers, not structs (fixes vector capacity adjustment invaliding in-use addresses). * add producer consumer, thread order test cases * change to unordered_map for semaphores and remove PreallocateSyncs * tests running on device * code cleanup for compile warnings * remove #if defined(__hexagon__) guards * copyright, format, lint * add hexagon buffer map class * remove redundant thread manager tests * revert Hex Dev API changes for threading * add comments; remove untested code to dispatch / wrap a packed func * pass pipe address and not HTM pointer to thread context * rename to HexagonBufferManager * cleanup ahead of PR * use DLOG(INFO) * refactor GetStreamHandles to return a vector by value * adjust HexagonBufferManager methods; use thread_manager file names * style guidelines and debug prints * reinterpret cast for TVMStreamHandle * end member variables with underscore Co-authored-by: Joseph McMahan <jmcmahan@octoml.ai>
- Loading branch information
1 parent
85a190a
commit 76b9ce9
Showing
6 changed files
with
901 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef TVM_RUNTIME_HEXAGON_HEXAGON_BUFFER_MANAGER_H_ | ||
#define TVM_RUNTIME_HEXAGON_HEXAGON_BUFFER_MANAGER_H_ | ||
|
||
#include <tvm/runtime/logging.h> | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
#include <utility> | ||
|
||
#include "hexagon_buffer.h" | ||
|
||
namespace tvm { | ||
namespace runtime { | ||
namespace hexagon { | ||
|
||
class HexagonBufferManager { | ||
public: | ||
/*! | ||
* \brief Free a HexagonBuffer. | ||
* \param ptr Address of the HexagonBuffer as returned by `AllocateHexagonBuffer`. | ||
*/ | ||
void FreeHexagonBuffer(void* ptr) { | ||
auto it = hexagon_buffer_map_.find(ptr); | ||
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); | ||
} | ||
/*! | ||
* \brief Allocate a HexagonBuffer. | ||
* \param args Templated arguments to pass through to HexagonBuffer constructor. | ||
*/ | ||
template <typename... Args> | ||
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)}); | ||
return ptr; | ||
} | ||
|
||
//! \brief Returns whether the HexagonBuffer is in the map. | ||
size_t count(void* ptr) { return hexagon_buffer_map_.count(ptr); } | ||
|
||
//! \brief Returns an iterator to the HexagonBuffer within the map. | ||
HexagonBuffer* find(void* ptr) { | ||
auto it = hexagon_buffer_map_.find(ptr); | ||
if (it != hexagon_buffer_map_.end()) { | ||
return it->second.get(); | ||
} | ||
return nullptr; | ||
} | ||
|
||
private: | ||
//! \brief Contains the HexagonBuffer objects managed by this class. | ||
std::unordered_map<void*, std::unique_ptr<HexagonBuffer>> hexagon_buffer_map_; | ||
}; | ||
|
||
} // namespace hexagon | ||
} // namespace runtime | ||
} // namespace tvm | ||
|
||
#endif // TVM_RUNTIME_HEXAGON_HEXAGON_BUFFER_MANAGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.