From 23a7abc8e8b3f087bd51206dc4d1fcabc30487a0 Mon Sep 17 00:00:00 2001 From: Alex Xie Date: Sun, 27 Sep 2020 19:02:57 -0400 Subject: [PATCH] SWDEV-251360 - Add tracing for memory allocation/free. This can be used to debug VM fault Change-Id: I7685485b0450ea84d10b710639ad7b6c5ec2fcf3 [ROCm/clr commit: e4e6c46356f83eadaa1da00da0bf73d875e8591a] --- projects/clr/rocclr/device/rocm/rocdevice.cpp | 4 ++++ projects/clr/rocclr/device/rocm/rocmemory.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index fee8445865..c9378d0ceb 100755 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -1778,6 +1778,7 @@ void* Device::hostAlloc(size_t size, size_t alignment, bool atomics) const { : system_segment_; assert(segment.handle != 0); hsa_status_t stat = hsa_amd_memory_pool_allocate(segment, size, 0, &ptr); + ClPrint(amd::LOG_DEBUG, amd::LOG_MEM, "Allocate hsa host memory %p, size 0x%zx", ptr, size); if (stat != HSA_STATUS_SUCCESS) { LogError("Fail allocation host memory"); return nullptr; @@ -1804,6 +1805,7 @@ void* Device::hostAgentAlloc(size_t size, const AgentInfo& agentInfo, bool atomi : agentInfo.fine_grain_pool; assert(segment.handle != 0); hsa_status_t stat = hsa_amd_memory_pool_allocate(segment, size, 0, &ptr); + ClPrint(amd::LOG_DEBUG, amd::LOG_MEM, "Allocate hsa host memory %p, size 0x%zx", ptr, size); if (stat != HSA_STATUS_SUCCESS) { LogPrintfError("Fail allocation host memory with err %d", stat); return nullptr; @@ -1910,6 +1912,7 @@ void* Device::deviceLocalAlloc(size_t size, bool atomics) const { void* ptr = nullptr; hsa_status_t stat = hsa_amd_memory_pool_allocate(pool, size, 0, &ptr); + ClPrint(amd::LOG_DEBUG, amd::LOG_MEM, "Allocate hsa device memory %p, size 0x%zx", ptr, size); if (stat != HSA_STATUS_SUCCESS) { LogError("Fail allocation local memory"); return nullptr; @@ -1925,6 +1928,7 @@ void* Device::deviceLocalAlloc(size_t size, bool atomics) const { void Device::memFree(void* ptr, size_t size) const { hsa_status_t stat = hsa_amd_memory_pool_free(ptr); + ClPrint(amd::LOG_DEBUG, amd::LOG_MEM, "Free hsa memory %p", ptr); if (stat != HSA_STATUS_SUCCESS) { LogError("Fail freeing local memory"); } diff --git a/projects/clr/rocclr/device/rocm/rocmemory.cpp b/projects/clr/rocclr/device/rocm/rocmemory.cpp index 638404e9e3..dadc01b56b 100755 --- a/projects/clr/rocclr/device/rocm/rocmemory.cpp +++ b/projects/clr/rocclr/device/rocm/rocmemory.cpp @@ -261,6 +261,9 @@ bool Memory::createInteropBuffer(GLenum targetType, int miplevel) { 1, &agent, out.dmabuf_fd, 0, &size, &deviceMemory_, &metadata_size, (const void**)&metadata); close(out.dmabuf_fd); + ClPrint(amd::LOG_DEBUG, amd::LOG_MEM, "Map GL memory %p, size 0x%zx, offset=0x%llx", + deviceMemory_, size, out.buf_offset); + deviceMemory_ = static_cast(deviceMemory_) + out.buf_offset; if (status != HSA_STATUS_SUCCESS) return false; @@ -283,6 +286,7 @@ bool Memory::createInteropBuffer(GLenum targetType, int miplevel) { void Memory::destroyInteropBuffer() { assert(kind_ == MEMORY_KIND_INTEROP && "Memory must be interop type."); hsa_amd_interop_unmap_buffer(deviceMemory_); + ClPrint(amd::LOG_DEBUG, amd::LOG_MEM, "Unmap GL memory %p", deviceMemory_); deviceMemory_ = nullptr; }