SWDEV-311271 - Make sure memory pool can accept default stream

Add lock protection for access to the pool list.
Remove destroyed stream from the list of the safe streams

Change-Id: I1863b89bd3f5e188c161227cc790c3adaf72cc58


[ROCm/clr commit: 5957ff9f7b]
This commit is contained in:
German Andryeyev
2022-04-14 19:04:01 -04:00
parent 5516c2d12e
commit 3de1a9e36c
6 changed files with 63 additions and 8 deletions
+24
View File
@@ -36,6 +36,17 @@ amd::HostQueue* Device::NullStream(bool skip_alloc) {
return null_queue;
}
// ================================================================================================
Stream* Device::GetNullStream() {
amd::HostQueue* null_queue = null_stream_.asHostQueue();
if (null_queue == nullptr) {
return nullptr;
}
// Wait for all active streams before executing commands on the default
iHipWaitActiveStreams(null_queue);
return &null_stream_;
}
// ================================================================================================
bool Device::Create() {
// Create default memory pool
@@ -50,6 +61,7 @@ bool Device::Create() {
// ================================================================================================
void Device::AddMemoryPool(MemoryPool* pool) {
amd::ScopedLock lock(lock_);
if (auto it = mem_pools_.find(pool); it == mem_pools_.end()) {
mem_pools_.insert(pool);
}
@@ -57,6 +69,7 @@ void Device::AddMemoryPool(MemoryPool* pool) {
// ================================================================================================
void Device::RemoveMemoryPool(MemoryPool* pool) {
amd::ScopedLock lock(lock_);
if (auto it = mem_pools_.find(pool); it != mem_pools_.end()) {
mem_pools_.erase(it);
}
@@ -64,6 +77,7 @@ void Device::RemoveMemoryPool(MemoryPool* pool) {
// ================================================================================================
bool Device::FreeMemory(amd::Memory* memory, Stream* stream) {
amd::ScopedLock lock(lock_);
// Search for memory in the entire list of pools
for (auto& it : mem_pools_) {
if (it->FreeMemory(memory, stream)) {
@@ -75,12 +89,22 @@ bool Device::FreeMemory(amd::Memory* memory, Stream* stream) {
// ================================================================================================
void Device::ReleaseFreedMemory(Stream* stream) {
amd::ScopedLock lock(lock_);
// Search for memory in the entire list of pools
for (auto& it : mem_pools_) {
it->ReleaseFreedMemory(stream);
}
}
// ================================================================================================
void Device::RemoveStreamFromPools(Stream* stream) {
amd::ScopedLock lock(lock_);
// Update all pools with the destroyed stream
for (auto& it : mem_pools_) {
it->RemoveStream(stream);
}
}
// ================================================================================================
Device::~Device() {
if (default_mem_pool_ != nullptr) {