SWDEV-404889 - Enable debugger interface in PAL

Add GPU_DEBUG_ENABLE to control ttpm behavior. If enabled,
then HW will collect more debug info at some perf cost

Change-Id: Icee0686b903a7b1bd483710b9d611877cd43c6aa
This commit is contained in:
German
2023-11-22 14:25:25 -05:00
committed by German Andryeyev
orang tua dc8f66b86f
melakukan 7d661bc7df
5 mengubah file dengan 28 tambahan dan 26 penghapusan
+21 -17
Melihat File
@@ -1141,15 +1141,15 @@ bool Device::initializeHeapResources() {
if (iDev()->Finalize(finalizeInfo) != Pal::Result::Success) {
return false;
}
#ifdef PAL_DEBUGGER
Pal::RuntimeSetup setup;
setup.r_debug = reinterpret_cast<uint64_t>(_amdgpu_r_debug_ptr);
if (iDev()->RegisterRuntimeState(&setup) != Pal::Result::Success) {
Pal::HipRuntimeSetup setup {.pRdebug = _amdgpu_r_debug_ptr,
.runtimeState = 1, // Always valid debug state
.ttmpSetupHint = GPU_DEBUG_ENABLE};
setup.pRdebug = _amdgpu_r_debug_ptr;
if (iDev()->RegisterHipRuntimeState(setup) != Pal::Result::Success) {
LogError("Couldn't register debug state from the loader!");
// Note: ignore debug state error, since it's not a critical
// error for the execution
}
#endif
heapInitComplete_ = true;
@@ -1211,10 +1211,11 @@ bool Device::initializeHeapResources() {
// Find an offset in memory for the trap handler.
// Loader returns an absolute address, but PAL accepts base + offset, hense find offset
auto offset = program->GetTrapHandlerAddress() - memRef.pGpuMemory->Desc().gpuVirtAddr;
#ifdef PAL_DEBUGGER
// Bind trap handler to the kernel mode driver
iDev()->BindTrapHandler(Pal::PipelineBindPoint::Compute, memRef.pGpuMemory, offset);
#endif
// Bind the trap handler's executable to the kernel mode driver
result = iDev()->SetHipTrapHandler(memRef.pGpuMemory, offset, nullptr, 0);
if (result != Pal::Result::Success) {
LogError("KMD failed to setup the trap handler");
}
} else {
LogError("Failed to make trap handler resident in memory");
}
@@ -2607,28 +2608,31 @@ bool Device::createBlitProgram() {
result = false;
}
#ifdef PAL_DEBUGGER
if (settings().useLightning_) {
const std::string TrapHandlerAsm = TrapHandlerCode;
// Create a program for trap handler
// note: It's not critical for runtime functionality to fail trap handler initialization
trap_handler_ = new amd::Program(*context_, TrapHandlerAsm.c_str(), amd::Program::Assembly);
if (trap_handler_ != nullptr) {
auto asm_program = new amd::Program(*context_, TrapHandlerAsm.c_str(), amd::Program::Assembly);
if (asm_program != nullptr) {
std::vector<amd::Device*> devices;
devices.push_back(this);
std::string opt = "-cl-internal-kernel ";
if (auto retval =
trap_handler_->build(devices, opt.c_str(), nullptr, nullptr, false) != CL_SUCCESS) {
asm_program->build(devices, opt.c_str(), nullptr, nullptr, false) != CL_SUCCESS) {
DevLogPrintfError("Build failed for trap handler with error code: %d\n", retval);
}
if (!trap_handler_->load()) {
DevLogPrintfError("Could not load the trap handler \n");
asm_program->release();
} else {
if (asm_program->load()) {
trap_handler_ = asm_program;
} else {
DevLogPrintfError("Could not load the trap handler \n");
asm_program->release();
}
}
} else {
DevLogPrintfError("Trap handler creation failed\n");
}
}
#endif
return result;
}