From df01016c97d074ba59e704cedde6cfd96ec5f522 Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Thu, 19 May 2022 09:24:47 -0400 Subject: [PATCH] SWDEV-336024 - Clear device heap to 0 in ROCr path Change-Id: Id100ca6d6d5bd7fb16ca8c98ff0b12c9df1d69ab [ROCm/clr commit: 830898753dd562d0b974bae2d1028f736f479c5f] --- projects/clr/rocclr/device/pal/paldevice.cpp | 8 +++++++- projects/clr/rocclr/device/rocm/rocdevice.cpp | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/projects/clr/rocclr/device/pal/paldevice.cpp b/projects/clr/rocclr/device/pal/paldevice.cpp index 7e66b51d64..6b41e554f6 100644 --- a/projects/clr/rocclr/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/device/pal/paldevice.cpp @@ -1087,6 +1087,7 @@ void PAL_STDCALL Device::PalDeveloperCallback(void* pPrivateData, const Pal::uin #endif // PAL_GPUOPEN_OCL } +// ================================================================================================ bool Device::initializeHeapResources() { amd::ScopedLock k(lockForInitHeap_); if (!heapInitComplete_) { @@ -1154,13 +1155,18 @@ bool Device::initializeHeapResources() { xferQueue_->enableSyncedBlit(); if (amd::IS_HIP) { // Allocate initial heap for device memory allocator - static constexpr size_t HeapBufferSize = 1024 * Ki; + static constexpr size_t HeapBufferSize = 128 * Ki; heap_buffer_ = createMemory(HeapBufferSize); + if (heap_buffer_ == nullptr) { + LogError("Heap buffer allocation failed!"); + return false; + } } } return true; } +// ================================================================================================ device::VirtualDevice* Device::createVirtualDevice(amd::CommandQueue* queue) { bool profiling = false; uint rtCUs = amd::CommandQueue::RealTimeDisabled; diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index b2391b9509..d178d7164a 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -540,6 +540,7 @@ void Device::tearDown() { hsa_shut_down(); } +// ================================================================================================ bool Device::create() { char agent_name[64] = {0}; if (HSA_STATUS_SUCCESS != hsa_agent_get_info(bkendDevice_, HSA_AGENT_INFO_NAME, agent_name)) { @@ -788,13 +789,22 @@ bool Device::create() { if (amd::IS_HIP) { // Allocate initial heap for device memory allocator - static constexpr size_t HeapBufferSize = 1024 * Ki; + static constexpr size_t HeapBufferSize = 128 * Ki; heap_buffer_ = createMemory(HeapBufferSize); + // Clear memory to 0 for device library logic + if ((heap_buffer_ == nullptr) || + (HSA_STATUS_SUCCESS != hsa_amd_memory_fill( + reinterpret_cast(HeapBuffer()->virtualAddress()), 0, + HeapBufferSize / sizeof(uint32_t)))) { + LogError("Heap buffer allocation failed!"); + return false; + } } return true; } +// ================================================================================================ device::Program* NullDevice::createProgram(amd::Program& owner, amd::option::Options* options) { device::Program* program; if (settings().useLightning_) {