Skip to content

Commit 5931fcd

Browse files
committed
add support for dumping command buffers to a file
1 parent 6a9afe8 commit 5931fcd

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

docs/controls.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,16 @@ This is the list of options that is implicitly passed to CLANG to build a non-Op
525525

526526
This is the list of options that is implicitly passed to CLANG to build an OpenCL 2.0 SPIR-V module. Any application-provided build options will be appended to these build options.
527527

528+
### Controls for Dumping Command Buffers
529+
530+
##### `OmitCommandBufferNumber` (bool)
531+
532+
If set to a nonzero value, the Intercept Layer for OpenCL Applications will omit the command buffer number from dumped file names and hash tracking. This can produce deterministic results even if command buffers are creatd and finalized in a non-deterministic order (say, by multiple threads).
533+
534+
##### `DumpCommandBuffers` (bool)
535+
536+
If set to a nonzero value, the Intercept Layer for OpenCL Applications will dump the commands and dependencies in a command buffer to a file when the command buffer is successfully finalized. The file name will have the form "CLI\_\<Command BufferNumber\>\_\<Uniqueue Command BufferHash Code\>\_cmdbuf.dot". The command buffer is described using the DOT graph description language.
537+
528538
### Controls for Dumping and Injecting Buffers and Images
529539

530540
##### `DumpBufferHashes` (bool)

intercept/src/controls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ CLI_CONTROL( std::string, DefaultOptions, "-cc1 -x cl
121121
CLI_CONTROL( std::string, OpenCL2Options, "-cc1 -x cl -cl-std=CL2.0 -D__OPENCL_C_VERSION__=200 -D__OPENCL_VERSION__=200 -emit-spirv -triple=spir", "This is the list of options that is implicitly passed to CLANG to build an OpenCL 2.0 SPIR-V module. Any application-provided build options will be appended to these build options." )
122122

123123
CLI_CONTROL_SEPARATOR( Controls for Dumping Command Buffers: )
124-
CLI_CONTROL( bool, DumpCommandBuffers, false, "TODO" )
124+
CLI_CONTROL( bool, OmitCommandBufferNumber, false, "If set to a nonzero value, the Intercept Layer for OpenCL Applications will omit the command buffer number from dumped file names and hash tracking. This can produce deterministic results even if command buffers are creatd and finalized in a non-deterministic order (say, by multiple threads)." )
125+
CLI_CONTROL( bool, DumpCommandBuffers, false, "If set to a nonzero value, the Intercept Layer for OpenCL Applications will dump the commands and dependencies in a command buffer to a file when the command buffer is successfully finalized. The file name will have the form \"CLI_<Command BufferNumber>_<Uniqueue Command BufferHash Code>_cmdbuf.dot\". The command buffer is described using the DOT graph description language." )
125126

126127
CLI_CONTROL_SEPARATOR( Controls for Dumping and Injecting Buffers and Images: )
127128
CLI_CONTROL( bool, DumpBufferHashes, false, "If set to a nonzero value, the Intercept Layer for OpenCL Applications will dump hashes of a buffer, SVM, or USM allocation rather than the full contents of the buffer. This can be useful to identify which kernel enqueues generate different results without requiring a large amount of disk space." )

intercept/src/intercept.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ CLIntercept::CLIntercept( void* pGlobalData )
155155
m_AubCaptureKernelEnqueueSkipCounter = 0;
156156
m_AubCaptureKernelEnqueueCaptureCounter = 0;
157157

158+
m_CommandBufferNumber = 0;
159+
158160
#define CLI_CONTROL( _type, _name, _init, _desc ) m_Config . _name = _init;
159161
#include "controls.h"
160162
#undef CLI_CONTROL
@@ -6740,7 +6742,56 @@ void CLIntercept::traceCommandBufferFinalize(
67406742

67416743
SCommandBufferTraceInfo& traceInfo = m_CommandBufferTraceInfoMap[ cmdbuf ];
67426744
traceInfo.finalize();
6743-
std::cout << "Command Buffer Trace:\n" << traceInfo.trace.str() << std::endl;
6745+
6746+
// Now dump the command buffer trace.
6747+
6748+
const auto& str = traceInfo.trace.str();
6749+
const char* ptr = str.c_str();
6750+
size_t size = str.size();
6751+
6752+
auto hash = computeHash( ptr, size );
6753+
6754+
std::string fileName;
6755+
6756+
// Get the dump directory name.
6757+
OS().GetDumpDirectoryName( sc_DumpDirectoryName, fileName );
6758+
6759+
// Make the file name. It will have the form:
6760+
// CLI_<program number>_<hash>_cmdbuf.dot
6761+
{
6762+
char numberString[256] = "";
6763+
6764+
if( config().OmitProgramNumber ) // TODO: add a different control?
6765+
{
6766+
CLI_SPRINTF( numberString, 256, "%08X",
6767+
(unsigned int)hash );
6768+
}
6769+
else
6770+
{
6771+
CLI_SPRINTF( numberString, 256, "%04u_%08X",
6772+
m_CommandBufferNumber,
6773+
(unsigned int)hash );
6774+
}
6775+
6776+
fileName += "/CLI_";
6777+
fileName += numberString;
6778+
fileName += "_cmdbuf.dot";
6779+
}
6780+
6781+
// Now make directories as appropriate.
6782+
OS().MakeDumpDirectories( fileName );
6783+
6784+
log( "Dumping command buffer to file: " + fileName + "\n" );
6785+
dumpMemoryToFile(
6786+
fileName,
6787+
false,
6788+
ptr,
6789+
size );
6790+
6791+
m_CommandBufferNumber++;
6792+
6793+
// Now that we are done tracing, we can remove the trace info.
6794+
m_CommandBufferTraceInfoMap.erase( cmdbuf );
67446795
}
67456796

67466797
///////////////////////////////////////////////////////////////////////////////

intercept/src/intercept.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,8 @@ class CLIntercept
13641364
typedef std::map< cl_semaphore_khr, cl_platform_id > CSemaphoreInfoMap;
13651365
CSemaphoreInfoMap m_SemaphoreInfoMap;
13661366

1367+
unsigned int m_CommandBufferNumber;
1368+
13671369
typedef std::map< cl_command_buffer_khr, cl_platform_id > CCommandBufferInfoMap;
13681370
CCommandBufferInfoMap m_CommandBufferInfoMap;
13691371

0 commit comments

Comments
 (0)