From de3912dae4d8da6d1cf3ff1938bf6bd9299512be Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Wed, 25 Oct 2017 20:08:36 -0500 Subject: [PATCH] Emit fragment map and thunk ptr info with VM faults. Change-Id: If1302f674df7a636529c64bf66dfdda755a70c32 [ROCm/ROCR-Runtime commit: 9212e7a09f211d51b047c82774984ac4a2c4c3c8] --- .../hsa-runtime/core/runtime/runtime.cpp | 68 ++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index 497d9b85cd..553300265d 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -1101,15 +1101,67 @@ bool Runtime::VMFaultHandler(hsa_signal_value_t val, void* arg) { reason += "Unknown"; } - fprintf(stderr, - "Memory access fault by GPU node-%u on address %p%s. Reason: %s.\n", - fault.NodeId, reinterpret_cast(fault.VirtualAddress), - (fault.Failure.Imprecise == 1) ? "(may not be exact address)" : "", - reason.c_str()); - } else { - assert(false && "GPU memory access fault."); - } + core::Agent* faultingAgent = runtime_singleton_->agents_by_node_[fault.NodeId][0]; + fprintf( + stderr, + "Memory access fault by GPU node-%u (Agent handle: %p) on address %p%s. Reason: %s.\n", + fault.NodeId, reinterpret_cast(faultingAgent->public_handle().handle), + reinterpret_cast(fault.VirtualAddress), + (fault.Failure.Imprecise == 1) ? "(may not be exact address)" : "", reason.c_str()); + +#ifndef NDEBUG + runtime_singleton_->memory_lock_.Acquire(); + auto it = runtime_singleton_->allocation_map_.upper_bound( + reinterpret_cast(fault.VirtualAddress)); + for (int i = 0; i < 2; i++) { + if (it != runtime_singleton_->allocation_map_.begin()) it--; + } + fprintf(stderr, "Nearby memory map:\n"); + auto start = it; + for (int i = 0; i < 3; i++) { + if (it == runtime_singleton_->allocation_map_.end()) break; + std::string kind = "Non-HSA"; + if (it->second.region != nullptr) { + const amd::MemoryRegion* region = + static_cast(it->second.region); + if (region->IsSystem()) + kind = "System"; + else if (region->IsLocalMemory()) + kind = "VRAM"; + else if (region->IsScratch()) + kind = "Scratch"; + else if (region->IsLDS()) + kind = "LDS"; + } + fprintf(stderr, "%p, 0x%lx, %s\n", it->first, it->second.size, kind.c_str()); + it++; + } + fprintf(stderr, "\n"); + it = start; + runtime_singleton_->memory_lock_.Release(); + hsa_amd_pointer_info_t info; + PtrInfoBlockData block; + uint32_t count; + hsa_agent_t* canAccess; + info.size = sizeof(info); + for (int i = 0; i < 3; i++) { + if (it == runtime_singleton_->allocation_map_.end()) break; + runtime_singleton_->PtrInfo(const_cast(it->first), &info, malloc, &count, &canAccess, + &block); + fprintf(stderr, "PtrInfo:\n\tAddress: %p/%p\n\tSize: 0x%lx\n\tType: %u\n\tOwner: %p\n", + info.agentBaseAddress, info.hostBaseAddress, info.sizeInBytes, info.type, + reinterpret_cast(info.agentOwner.handle)); + fprintf(stderr, "\tCanAccess: %u\n", count); + for (int t = 0; t < count; t++) + fprintf(stderr, "\t\t%p\n", reinterpret_cast(canAccess[t].handle)); + fprintf(stderr, "\tIn block: %p, 0x%lx\n", block.base, block.length); + free(canAccess); + it++; + } +#endif //! NDEBUG + } + assert(false && "GPU memory access fault."); std::abort(); } // No need to keep the signal because we are done.