From 3490d5bf189eb2600a35572341a8073fdbd0d333 Mon Sep 17 00:00:00 2001 From: Matthew Poremba Date: Wed, 24 Apr 2024 10:42:58 -0700 Subject: [PATCH] gpu-compute: Add DebugFlag for LDS This prints what values are read/written to LDS and the previous value on write. This is useful for debugging problems with LDS instructions. Change-Id: I30063327bec1a1a808914a018467d5d78d5d58b4 --- src/gpu-compute/SConscript | 3 ++- src/gpu-compute/lds_state.hh | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/gpu-compute/SConscript b/src/gpu-compute/SConscript index e4536ba2a5..23e3377f50 100644 --- a/src/gpu-compute/SConscript +++ b/src/gpu-compute/SConscript @@ -84,6 +84,7 @@ DebugFlag('GPUExec') DebugFlag('GPUFetch') DebugFlag('GPUInst') DebugFlag('GPUKernelInfo') +DebugFlag('GPULDS') DebugFlag('GPUMem') DebugFlag('GPUPort') DebugFlag('GPUPrefetch') @@ -106,4 +107,4 @@ DebugFlag('WavefrontStack') CompoundFlag('GPUALL', ['GPUCoalescer', 'GPUDisp', 'GPUExec', 'GPUFetch', 'GPUMem', 'GPUPort', 'GPUSched', 'GPUSRF', 'GPUSync', 'GPUTLB', 'GPUVRF', 'GPURFC', 'GPUWgLatency', - 'GPUKernelInfo', 'GPUInitAbi']) + 'GPUKernelInfo', 'GPUInitAbi', 'GPULDS']) diff --git a/src/gpu-compute/lds_state.hh b/src/gpu-compute/lds_state.hh index 3228b7822c..d336d35079 100644 --- a/src/gpu-compute/lds_state.hh +++ b/src/gpu-compute/lds_state.hh @@ -39,6 +39,7 @@ #include #include +#include "debug/GPULDS.hh" #include "gpu-compute/misc.hh" #include "mem/port.hh" #include "params/LdsState.hh" @@ -75,10 +76,30 @@ class LdsChunk * chunk allocated to this WG we return 0. */ if (index >= chunk.size()) { + DPRINTF(GPULDS, "LDS[%d][%d]: Read 0 beyond size (%ld)\n", + dispatchId, wgId, chunk.size()); return (T)0; } T *p0 = (T *) (&(chunk.at(index))); + + if (sizeof(T) <= 4) { + [[maybe_unused]] uint32_t int_val = + *reinterpret_cast(p0); + DPRINTF(GPULDS, "LDS[%d][%d]: Read %08x from index %d\n", + dispatchId, wgId, int_val, index); + } else if (sizeof(T) <= 8) { + [[maybe_unused]] uint64_t int_val = + *reinterpret_cast(p0); + DPRINTF(GPULDS, "LDS[%d][%d]: Read %016lx from index %d\n", + dispatchId, wgId, int_val, index); + } else if (sizeof(T) <= 16) { + [[maybe_unused]] uint64_t *int_vals = + reinterpret_cast(p0); + DPRINTF(GPULDS, "LDS[%d][%d]: Read %016lx%016lx from index %d\n", + dispatchId, wgId, int_vals[1], int_vals[0], index); + } + return *p0; } @@ -94,10 +115,33 @@ class LdsChunk * chunk allocated to this WG are dropped. */ if (index >= chunk.size()) { + DPRINTF(GPULDS, "LDS[%d][%d]: Ignoring write beyond size (%ld)\n", + dispatchId, wgId, chunk.size()); return; } T *p0 = (T *) (&(chunk.at(index))); + + if (sizeof(T) <= 4) { + [[maybe_unused]] uint32_t prev_val = + *reinterpret_cast(p0); + DPRINTF(GPULDS, "LDS[%d][%d]: Write %08lx to index %d (was " + "%08lx)\n", dispatchId, wgId, value, index, prev_val); + } else if (sizeof(T) <= 8) { + [[maybe_unused]] uint64_t prev_val = + *reinterpret_cast(p0); + DPRINTF(GPULDS, "LDS[%d][%d]: Write %016lx to index %d (was " + "%016lx)\n", dispatchId, wgId, value, index, prev_val); + } else if (sizeof(T) <= 16) { + [[maybe_unused]] uint64_t *prev_vals = + reinterpret_cast(p0); + [[maybe_unused]] const uint64_t *next_vals = + reinterpret_cast(&value); + DPRINTF(GPULDS, "LDS[%d][%d]: Write %016lx%016lx to index %d " + "(was %016lx%016lx)\n", dispatchId, wgId, next_vals[1], + next_vals[0], index, prev_vals[1], prev_vals[0]); + } + *p0 = value; } @@ -131,6 +175,9 @@ class LdsChunk return chunk.size(); } + uint32_t dispatchId; + uint32_t wgId; + protected: // the actual data store for this slice of the LDS std::vector chunk; @@ -402,6 +449,9 @@ class LdsState: public ClockedObject // make an entry for this workgroup refCounter[dispatchId][wgId] = 0; + chunkMap[dispatchId][wgId].dispatchId = dispatchId; + chunkMap[dispatchId][wgId].wgId = wgId; + return &chunkMap[dispatchId][wgId]; } }