SWDEV-311271 - Initial mempool implementation
HIP_MEM_POOL_SUPPORT controls memory pool support in runtime. Currently it's disabled by default. The initial change doesn't include: IPC, MGPU, virtual memory alloc, suballoc, defragmentation, internal dependencies. Change-Id: Ibed8528ebec698b045ebb247e49c0ecd6e587ed7
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <hip/hip_runtime.h>
|
||||
|
||||
#include "hip_internal.hpp"
|
||||
#include "hip_mempool_impl.hpp"
|
||||
|
||||
namespace hip {
|
||||
|
||||
@@ -35,6 +36,58 @@ amd::HostQueue* Device::NullStream(bool skip_alloc) {
|
||||
return null_queue;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
bool Device::Create() {
|
||||
// Create default memory pool
|
||||
default_mem_pool_ = new MemoryPool(this);
|
||||
if (default_mem_pool_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
// Current is default pool after device creation
|
||||
current_mem_pool_ = default_mem_pool_;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Device::AddMemoryPool(MemoryPool* pool) {
|
||||
if (auto it = mem_pools_.find(pool); it == mem_pools_.end()) {
|
||||
mem_pools_.insert(pool);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Device::RemoveMemoryPool(MemoryPool* pool) {
|
||||
if (auto it = mem_pools_.find(pool); it != mem_pools_.end()) {
|
||||
mem_pools_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
bool Device::FreeMemory(amd::Memory* memory, Stream* stream) {
|
||||
// Search for memory in the entire list of pools
|
||||
for (auto& it : mem_pools_) {
|
||||
if (it->FreeMemory(memory, stream)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Device::ReleaseFreedMemory(Stream* stream) {
|
||||
// Search for memory in the entire list of pools
|
||||
for (auto& it : mem_pools_) {
|
||||
it->ReleaseFreedMemory(stream);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
Device::~Device() {
|
||||
if (default_mem_pool_ != nullptr) {
|
||||
default_mem_pool_->release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace amd {
|
||||
|
||||
Reference in New Issue
Block a user