SWDEV-353281 - Initial support of memalloc in graph
Add memory allocation support in graph. Current implementation uses
cache from mempool to hold the allocations which belong to the graph.
Also the resource tracking is disabled at this moment because mempool
operates with hip::Stream objects, but graph has execution with
amd::HostQueue objects.
Change-Id: I54fe3250126d24f5a26ada975f37d429bb4ef17b
[ROCm/clr commit: eef47ca24a]
This commit is contained in:
1 parent
1087f13ee1
commit
9c811dc241
13 files changed
+352
-39
No files matched your search
@@ -74,7 +74,10 @@ hipError_t hipMallocAsync(void** dev_ptr, size_t size, hipStream_t stream) {
|
||||
reinterpret_cast<hip::Stream*>(stream);
|
||||
auto device = hip_stream->GetDevice();
|
||||
auto mem_pool = device->GetCurrentMemoryPool();
|
||||
*dev_ptr = reinterpret_cast<hip::MemoryPool*>(mem_pool)->AllocateMemory(size, hip_stream);
|
||||
|
||||
STREAM_CAPTURE(hipMallocAsync, stream, reinterpret_cast<hipMemPool_t>(mem_pool), size, dev_ptr);
|
||||
|
||||
*dev_ptr = mem_pool->AllocateMemory(size, hip_stream);
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
@@ -84,15 +87,18 @@ hipError_t hipFreeAsync(void* dev_ptr, hipStream_t stream) {
|
||||
if ((dev_ptr == nullptr) || (!hip::isValid(stream))) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
STREAM_CAPTURE(hipFreeAsync, stream, dev_ptr);
|
||||
size_t offset = 0;
|
||||
auto memory = getMemoryObject(dev_ptr, offset);
|
||||
auto id = memory->getUserData().deviceId;
|
||||
auto hip_stream = (stream == nullptr) ? hip::getCurrentDevice()->GetNullStream() :
|
||||
reinterpret_cast<hip::Stream*>(stream);
|
||||
if (!g_devices[id]->FreeMemory(memory, hip_stream)) {
|
||||
//! @todo It's not the most optimal logic. The current implementation has unconditional waits
|
||||
HIP_RETURN(ihipFree(dev_ptr));
|
||||
}
|
||||
if (memory != nullptr) {
|
||||
auto id = memory->getUserData().deviceId;
|
||||
auto hip_stream = (stream == nullptr) ? hip::getCurrentDevice()->GetNullStream() :
|
||||
reinterpret_cast<hip::Stream*>(stream);
|
||||
if (!g_devices[id]->FreeMemory(memory, hip_stream)) {
|
||||
//! @todo It's not the most optimal logic. The current implementation has unconditional waits
|
||||
HIP_RETURN(ihipFree(dev_ptr));
|
||||
}
|
||||
}
|
||||
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
@@ -232,9 +238,12 @@ hipError_t hipMallocFromPoolAsync(
|
||||
if ((dev_ptr == nullptr) || (size == 0) || (mem_pool == nullptr) || (!hip::isValid(stream))) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
STREAM_CAPTURE(hipMallocAsync, stream, mem_pool, size, dev_ptr);
|
||||
|
||||
auto mpool = reinterpret_cast<hip::MemoryPool*>(mem_pool);
|
||||
auto hip_stream = (stream == nullptr) ? hip::getCurrentDevice()->GetNullStream() :
|
||||
reinterpret_cast<hip::Stream*>(stream);
|
||||
*dev_ptr = reinterpret_cast<hip::MemoryPool*>(mem_pool)->AllocateMemory(size, hip_stream);
|
||||
*dev_ptr = mpool->AllocateMemory(size, hip_stream);
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user