From 5ac60a3c2912c058a937cce16c9873fc940744ec Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 19 Feb 2015 19:40:35 -0500
Subject: [PATCH] P4 to Git Change 1123622 by wchau@wchau_WINDOWS7_OCL on
2015/02/19 17:52:17
ECR #399840 - OpenCL Runtime HW Debug support development
- use device to control debugger registration and exception notification so that debug event will not be tied to any particular queue.
- use aqlCodeInfo parameter for clHwDbgMapKernelCodeAMD() to be consistent with clHwDbgGetAqlPacketInfoAMD()
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_debugger_amd.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_debugger_amd.h#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudebugmanager.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudebugmanager.hpp#4 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#352 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#127 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLContext.cpp#70 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLContext.h#43 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hwdebug.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hwdebug.hpp#6 edit
[ROCm/clr commit: 3e53caa02e354a9ceb3a5eb099c08384c3fc84c6]
---
.../runtime/device/gpu/gpudebugmanager.cpp | 47 +++++++------------
.../runtime/device/gpu/gpudebugmanager.hpp | 6 +--
.../rocclr/runtime/device/gpu/gpuvirtual.cpp | 23 +++------
.../rocclr/runtime/device/gpu/gpuvirtual.hpp | 2 -
.../device/gpu/gslbe/src/rt/GSLContext.cpp | 12 -----
.../device/gpu/gslbe/src/rt/GSLContext.h | 2 -
.../clr/rocclr/runtime/device/hwdebug.cpp | 10 ----
.../clr/rocclr/runtime/device/hwdebug.hpp | 15 ++----
8 files changed, 28 insertions(+), 89 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.cpp b/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.cpp
index aa066f94d1..fc5a2e52ab 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.cpp
@@ -111,6 +111,15 @@ GpuDebugManager::executePostDispatchCallBack()
}
}
+//! Map the kernel code for host access
+void
+GpuDebugManager::mapKernelCode(void* aqlCodeInfo) const
+{
+ AqlCodeInfo* codeInfo = reinterpret_cast(aqlCodeInfo);
+
+ codeInfo->aqlCode_ = reinterpret_cast(aqlCodeAddr_);
+ codeInfo->aqlCodeSize_ = aqlCodeSize_;
+}
cl_int
GpuDebugManager::registerDebugger(amd::Context* context, uintptr_t messageStorage)
@@ -125,8 +134,11 @@ GpuDebugManager::registerDebugger(amd::Context* context, uintptr_t messageStorag
// first time register - set the message storage, flush queue and enable hw debug
if (!isRegistered()) {
debugMessages_ = messageStorage;
- dbgMsgBufferReady_ = true;
- isRegistered_ = false;
+ if (!device()->gslCtx()->registerHwDebugger(debugMessages_)) {
+ return CL_OUT_OF_RESOURCES;
+ }
+
+ isRegistered_ = true;
}
context_ = context;
@@ -142,35 +154,10 @@ GpuDebugManager::unregisterDebugger()
// reset the debugger registration flag
isRegistered_ = false;
- dbgMsgBufferReady_ = false;
-
context_ = NULL;
}
}
-cl_int
-GpuDebugManager::registerDebuggerOnQueue(device::VirtualDevice* vDevice)
-{
- if (!isMsgBufferReady()) {
- return CL_DEBUGGER_REGISTER_FAILURE_AMD;
- }
-
- if (isRegistered()) { // The debugger has already been registered,
- return CL_SUCCESS; // nothing to be done
- }
-
- VirtualGPU* vGpu = reinterpret_cast(vDevice);
-
- // populate the fields in the debugMessages structure used by the GPU exception notification
- if (vGpu->RegisterHwDebugger(debugMessages_)) {
- vGpu_ = vGpu;
- isRegistered_ = true;
- return CL_SUCCESS;
- }
-
- return CL_DEBUGGER_REGISTER_FAILURE_AMD;
-}
-
void
GpuDebugManager::flushCache(uint32_t mask)
{
@@ -205,7 +192,6 @@ GpuDebugManager::setupTrapInformation(DebugToolInfo* toolInfo)
toolInfo->trapBuffer_ = rtTrapInfo_[kDebugTrapBufferLocation];
}
-
void
GpuDebugManager::getPacketAmdInfo(
const void* aqlCodeInfo,
@@ -259,8 +245,7 @@ GpuDebugManager::createDebugEvent(
osEventReset(shaderEvent); // initial state is non-signaled
- if (vGpu_->ExceptionNotification(shaderEvent)) {
- isRegistered_ = true;
+ if (device()->gslCtx()->exceptionNotification(shaderEvent)) {
return shaderEvent;
}
}
@@ -287,7 +272,7 @@ GpuDebugManager::destroyDebugEvent(DebugEvent* pEvent)
osEventDestroy(*pEvent);
*pEvent = 0;
- vGpu_->ExceptionNotification(0);
+ device()->gslCtx()->exceptionNotification(0);
}
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.hpp b/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.hpp
index ddda1e27d4..48507647e1 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.hpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpudebugmanager.hpp
@@ -65,9 +65,6 @@ public:
//! Register the debugger
cl_int registerDebugger(amd::Context*context, uintptr_t messageStorage);
- //! Register the debugger with KMD after command queue has been created
- cl_int registerDebuggerOnQueue(device::VirtualDevice* vDevice);
-
//! Unregister the debugger
void unregisterDebugger();
@@ -84,6 +81,9 @@ public:
uint64_t* watchMode,
DebugEvent* pEvent);
+ //! Map the kernel code for host access
+ void mapKernelCode(void* aqlCodeInfo) const;
+
//! Get the packet information for dispatch
void getPacketAmdInfo(const void* aqlCodeInfo, void* packetInfo) const;
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp b/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp
index e33348d75b..f7efde6aab 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp
@@ -403,7 +403,6 @@ VirtualGPU::VirtualGPU(
, schedParamIdx_(0)
, deviceQueueSize_(0)
, hsaQueueMem_(NULL)
- , useHwDebug_(false)
{
memset(&cal_, 0, sizeof(CalVirtualDesc));
for (uint i = 0; i < AllEngines; ++i) {
@@ -587,15 +586,6 @@ VirtualGPU::create(
return false;
}
- // Check if HW Debug is used and register the debugger if not done yet
- amd::HwDebugManager * dbgManager = dev().hwDebugMgr();
-
- if ( dbgManager && dbgManager->isMsgBufferReady() ) {
- if ( dbgManager->registerDebuggerOnQueue(this) == CL_SUCCESS ) {
- useHwDebug_ = true;
- }
- }
-
return true;
}
@@ -1648,6 +1638,7 @@ VirtualGPU::submitKernelInternalHSA(
uint64_t vmDefQueue = 0;
amd::DeviceQueue* defQueue = kernel.program().context().defDeviceQueue(dev());
VirtualGPU* gpuDefQueue = NULL;
+ amd::HwDebugManager * dbgManager = dev().hwDebugMgr();
// Get the HSA kernel object
const HSAILKernel& hsaKernel =
@@ -1735,8 +1726,8 @@ VirtualGPU::submitKernelInternalHSA(
// setup the storage for the memory pointers of the kernel parameters
uint numParams = kernel.signature().numParameters();
- if (useHwDebug_) {
- dev().hwDebugMgr()->allocParamMemList(numParams);
+ if (dbgManager) {
+ dbgManager->allocParamMemList(numParams);
}
// Program the kernel arguments for the GPU execution
@@ -1768,7 +1759,7 @@ VirtualGPU::submitKernelInternalHSA(
HwDbgKernelInfo kernelInfo;
HwDbgKernelInfo *pKernelInfo = NULL;
- if (useHwDebug_) {
+ if (dbgManager) {
buildKernelInfo(hsaKernel, aqlPkt, kernelInfo, enqueueEvent);
pKernelInfo = &kernelInfo;
}
@@ -1778,10 +1769,8 @@ VirtualGPU::submitKernelInternalHSA(
runAqlDispatch(gpuEvent, aqlPkt, vmMems(), cal_.memCount_,
scratch, scratchOffset, hsaKernel.cpuAqlCode(), hsaQueueMem_->vmAddress(), pKernelInfo);
- if (useHwDebug_) {
- if (NULL != dev().hwDebugMgr()->postDispatchCallBackFunc()) {
- dev().hwDebugMgr()->executePostDispatchCallBack();
- }
+ if (dbgManager && (NULL != dbgManager->postDispatchCallBackFunc())) {
+ dbgManager->executePostDispatchCallBack();
}
if (hsaKernel.dynamicParallelism()) {
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.hpp b/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.hpp
index ec7b03919e..5e37c53757 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.hpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.hpp
@@ -554,8 +554,6 @@ private:
uint deviceQueueSize_; //!< Device queue size
Memory* hsaQueueMem_; //!< Memory for the amd_queue_t object
-
- bool useHwDebug_; //!< Flag of using HW debug
};
/*@}*/} // namespace gpu
diff --git a/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.cpp b/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.cpp
index 00a0878d8e..65537c48ad 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.cpp
@@ -1300,18 +1300,6 @@ CALGSLContext::virtualQueueHandshake(GpuEvent& event, const gslMemObject mem, mc
eventEnd(MainEngine, event);
}
-bool
-CALGSLContext::RegisterHwDebugger(uint64 debugMessages)
-{
- return m_cs->registerHwDebugger(debugMessages);
-}
-
-bool
-CALGSLContext::ExceptionNotification(osEventHandle debugEvent)
-{
- return m_cs->exceptionNotification(debugEvent);
-}
-
void
CALGSLContext::InvalidateSqCaches(bool instInvalidate, bool dataInvalidate, bool tcL1, bool tcL2)
{
diff --git a/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.h b/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.h
index 84d662c09d..b951d171aa 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.h
+++ b/projects/clr/rocclr/runtime/device/gpu/gslbe/src/rt/GSLContext.h
@@ -142,8 +142,6 @@ public:
void writeSurfRaw(GpuEvent& event, gslMemObject mem, size_t size, const void* data);
/// HW Debug support functions
- bool RegisterHwDebugger(uint64 debugMessages);
- bool ExceptionNotification(osEventHandle debugEvent);
void InvalidateSqCaches(bool instInvalidate = true, bool dataInvalidate = true, bool tcL1 = true, bool tcL2 = true);
protected:
diff --git a/projects/clr/rocclr/runtime/device/hwdebug.cpp b/projects/clr/rocclr/runtime/device/hwdebug.cpp
index 189478ece7..b08047574a 100644
--- a/projects/clr/rocclr/runtime/device/hwdebug.cpp
+++ b/projects/clr/rocclr/runtime/device/hwdebug.cpp
@@ -41,7 +41,6 @@ HwDebugManager::HwDebugManager(amd::Device* device)
, scratchRingAddr_(NULL)
, scratchRingSize_(0)
, isRegistered_(false)
- , dbgMsgBufferReady_(false)
{
memset(&debugInfo_, 0, sizeof(debugInfo_));
@@ -81,7 +80,6 @@ HwDebugManager::getDispatchDebugInfo(void* debugInfo) const
memcpy(debugInfo, (void*) &debugInfo_, sizeof(DispatchDebugInfo));
}
-
//! Set the kernel code address and its size
void
HwDebugManager::setKernelCodeInfo(address aqlCodeAddr, uint32_t aqlCodeSize)
@@ -98,14 +96,6 @@ HwDebugManager::setScratchRing(address scratchRingAddr, uint32_t scratchRingSize
scratchRingSize_ = scratchRingSize;
}
-//! Map the shader (AQL code) for host access
-void
-HwDebugManager::mapKernelCode(uint64_t* aqlCodeAddr, uint32_t* aqlCodeSize) const
-{
- *aqlCodeAddr = reinterpret_cast(aqlCodeAddr_);
- *aqlCodeSize = aqlCodeSize_;
-}
-
//! Map the scratch ring for host access
void
HwDebugManager::mapScratchRing(uint64_t* scratchRingAddr, uint32_t* scratchRingSize) const
diff --git a/projects/clr/rocclr/runtime/device/hwdebug.hpp b/projects/clr/rocclr/runtime/device/hwdebug.hpp
index 7fa5baedb4..ebc352ab6f 100644
--- a/projects/clr/rocclr/runtime/device/hwdebug.hpp
+++ b/projects/clr/rocclr/runtime/device/hwdebug.hpp
@@ -68,8 +68,6 @@ struct RuntimeTrapInfo {
//!< Buffer to backup the VGPR used by the runtime trap handler
};
-
-
/**
* Opaque pointer to trap event
*/
@@ -113,9 +111,6 @@ public:
//! Get the scratch ring
void setScratchRing(address scratchRingAddr, uint32_t scratchRingSize);
- //! Map the shader (AQL code) for host access
- void mapKernelCode(uint64_t* aqlCodeAddr, uint32_t* aqlCodeSize) const;
-
//! Map the scratch ring for host access
void mapScratchRing(uint64_t* scratchRingAddr, uint32_t* scratchRingSize) const;
@@ -177,9 +172,6 @@ public:
//! Register the debugger
virtual cl_int registerDebugger(amd::Context* context, uintptr_t pMessageStorage) = 0;
- //! Call KMD to register the debugger
- virtual cl_int registerDebuggerOnQueue(device::VirtualDevice* vDevice) = 0;
-
//! Unregister the debugger
virtual void unregisterDebugger() = 0;
@@ -197,6 +189,9 @@ public:
uint64_t* watchMode,
DebugEvent* event) = 0;
+ //! Map the shader (AQL code) for host access
+ virtual void mapKernelCode(void* aqlCodeInfo) const = 0;
+
//! Get the packet information for dispatch
virtual void getPacketAmdInfo(const void* aqlCodeInfo,
void* packetInfo) const = 0;
@@ -214,9 +209,6 @@ public:
virtual void executePreDispatchCallBack(void* aqlPacket,
void* toolInfo) = 0;
- //! Return the use of HW DEBUG flag
- bool isMsgBufferReady() const { return dbgMsgBufferReady_; }
-
protected:
//! Return the context
const amd::Context* context() const { return context_; }
@@ -252,7 +244,6 @@ protected:
uint32_t scratchRingSize_; //!< The size of the scratch ring
bool isRegistered_; //! flag to indicate the debugger has been registered
- bool dbgMsgBufferReady_; //! flag to indicate the HW DEBUG is using
cl_dbg_exception_policy_amd excpPolicy_; //!< exception policy
cl_dbg_kernel_exec_mode_amd execMode_; //!< kernel execution mode