Skip to content

Commit e19d92a

Browse files
authored
Added KernelInfoLogging (#128)
The data that is logged for each kernel currently includes the kernel work group size, local mem size, private mem size, and spill size (if supported).
1 parent e76c699 commit e19d92a

File tree

5 files changed

+88
-35
lines changed

5 files changed

+88
-35
lines changed

docs/controls.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ If set to a nonzero value, logs the program build log after each call to clBuild
151151

152152
If set to a nonzero value, logs the preferred work group size multiple for each kernel after each call to clCreateKernel(). On some devices this is the equivalent of the SIMD size for this kernel.
153153

154+
##### `KernelInfoLogging` (bool)
155+
156+
If set to a nonzero value, logs information about the kernel after each call to clCreateKernel().
157+
154158
##### `CallLogging` (bool)
155159

156160
If set to a nonzero value, logs function entry and exit information for every OpenCL call. This can be used to easily determine which OpenCL call is causing an application to crash or fail or if a crash occurs outside of an OpenCL call. This setting is best used with LogToFile or LogToDebugger as it can generate a lot of log data.

intercept/src/controls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CLI_CONTROL( bool, LogToDebugger, false, "If s
3636
CLI_CONTROL( int, LogIndent, 0, "Indents each log entry by this many spaces." )
3737
CLI_CONTROL( bool, BuildLogging, false, "If set to a nonzero value, logs the program build log after each call to clBuildProgram(). This will likely only function correctly for synchronous builds. Note that the build log is logged regardless of whether the program built successfully, which allows compiler warnings to be logged for successful compiles." )
3838
CLI_CONTROL( bool, PreferredWorkGroupSizeMultipleLogging, false, "If set to a nonzero value, logs the preferred work group size multiple for each kernel after each call to clCreateKernel(). On some devices this is the equivalent of the SIMD size for this kernel." )
39+
CLI_CONTROL( bool, KernelInfoLogging, false, "If set to a nonzero value, logs information about the kernel after each call to clCreateKernel()." )
3940
CLI_CONTROL( bool, CallLogging, false, "If set to a nonzero value, logs function entry and exit information for every OpenCL call. This can be used to easily determine which OpenCL call is causing an application to crash or fail or if a crash occurs outside of an OpenCL call. This setting is best used with LogToFile or LogToDebugger as it can generate a lot of log data." )
4041
CLI_CONTROL( bool, CallLoggingEnqueueCounter, false, "If set to a nonzero value, logs the enqueue counter in addition to function entry and exit information for every OpenCL call. This can be used to determine appropriate limits for DumpBuffersMinEnqueue, DumpBuffersMaxEnqueue, DumpImagesMinEnqueue, or DumpBuffersMaxEnqueue. If CallLogging is disabled then this control will have no effect." )
4142
CLI_CONTROL( bool, CallLoggingThreadId, false, "If set to a nonzero value, logs the ID of the calling thread in addition to function entry and exit information for every OpenCL call. This can be helpful when debugging multi-threading issues." )

intercept/src/dispatch.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,9 +2603,10 @@ CL_API_ENTRY cl_kernel CL_API_CALL CLIRN(clCreateKernel)(
26032603
retVal,
26042604
program,
26052605
kernel_name );
2606-
if( pIntercept->config().PreferredWorkGroupSizeMultipleLogging )
2606+
if( pIntercept->config().KernelInfoLogging ||
2607+
pIntercept->config().PreferredWorkGroupSizeMultipleLogging )
26072608
{
2608-
pIntercept->logPreferredWorkGroupSizeMultiple(
2609+
pIntercept->logKernelInfo(
26092610
&retVal,
26102611
1 );
26112612
}
@@ -2680,9 +2681,10 @@ CL_API_ENTRY cl_int CL_API_CALL CLIRN(clCreateKernelsInProgram)(
26802681
kernels,
26812682
program,
26822683
num_kernels_ret[0] );
2683-
if( pIntercept->config().PreferredWorkGroupSizeMultipleLogging )
2684+
if( pIntercept->config().KernelInfoLogging ||
2685+
pIntercept->config().PreferredWorkGroupSizeMultipleLogging )
26842686
{
2685-
pIntercept->logPreferredWorkGroupSizeMultiple(
2687+
pIntercept->logKernelInfo(
26862688
kernels,
26872689
num_kernels_ret[0] );
26882690
}

intercept/src/intercept.cpp

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ void CLIntercept::logFlushOrFinishAfterEnqueueEnd(
24282428

24292429
///////////////////////////////////////////////////////////////////////////////
24302430
//
2431-
void CLIntercept::logPreferredWorkGroupSizeMultiple(
2431+
void CLIntercept::logKernelInfo(
24322432
const cl_kernel* kernels,
24332433
cl_uint numKernels )
24342434
{
@@ -2467,45 +2467,91 @@ void CLIntercept::logPreferredWorkGroupSizeMultiple(
24672467

24682468
// Log the preferred work group size multiple for each kernel,
24692469
// for each device.
2470-
while( numKernels-- )
2470+
while( numDevices && numKernels-- )
24712471
{
24722472
cl_kernel kernel = kernels[ numKernels ];
24732473

2474-
if( errorCode == CL_SUCCESS )
2475-
{
2476-
const std::string& kernelName = getShortKernelNameWithHash(kernel);
2477-
log( "Preferred Work Group Size Multiple for: '" + kernelName + "':\n" );
2478-
}
2479-
if( errorCode == CL_SUCCESS )
2474+
const std::string& kernelName = getShortKernelNameWithHash(kernel);
2475+
log( "Kernel Info for: " + kernelName + "\n" );
2476+
2477+
for( cl_uint i = 0; i < numDevices; i++ )
24802478
{
2481-
for( cl_uint i = 0; i < numDevices; i++ )
2479+
char* deviceName = NULL;
2480+
errorCode = allocateAndGetDeviceInfoString(
2481+
deviceList[i],
2482+
CL_DEVICE_NAME,
2483+
deviceName );
2484+
2485+
size_t pwgsm = 0;
2486+
errorCode |= dispatch().clGetKernelWorkGroupInfo(
2487+
kernel,
2488+
deviceList[i],
2489+
CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE,
2490+
sizeof(pwgsm),
2491+
&pwgsm,
2492+
NULL );
2493+
size_t wgs = 0;
2494+
errorCode |= dispatch().clGetKernelWorkGroupInfo(
2495+
kernel,
2496+
deviceList[i],
2497+
CL_KERNEL_WORK_GROUP_SIZE,
2498+
sizeof(wgs),
2499+
&wgs,
2500+
NULL );
2501+
cl_ulong pms = 0;
2502+
errorCode |= dispatch().clGetKernelWorkGroupInfo(
2503+
kernel,
2504+
deviceList[i],
2505+
CL_KERNEL_PRIVATE_MEM_SIZE,
2506+
sizeof(pms),
2507+
&pms,
2508+
NULL );
2509+
cl_ulong lms = 0;
2510+
errorCode |= dispatch().clGetKernelWorkGroupInfo(
2511+
kernel,
2512+
deviceList[i],
2513+
CL_KERNEL_LOCAL_MEM_SIZE,
2514+
sizeof(lms),
2515+
&lms,
2516+
NULL );
2517+
cl_ulong sms = 0;
2518+
cl_int errorCode_sms =dispatch().clGetKernelWorkGroupInfo(
2519+
kernel,
2520+
deviceList[i],
2521+
CL_KERNEL_SPILL_MEM_SIZE_INTEL,
2522+
sizeof(sms),
2523+
&sms,
2524+
NULL );
2525+
if( errorCode == CL_SUCCESS )
24822526
{
2483-
size_t kernelPreferredWorkGroupSizeMultiple = 0;
2484-
errorCode = dispatch().clGetKernelWorkGroupInfo(
2485-
kernel,
2486-
deviceList[i],
2487-
CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE,
2488-
sizeof(kernelPreferredWorkGroupSizeMultiple),
2489-
&kernelPreferredWorkGroupSizeMultiple,
2490-
NULL );
2491-
if( errorCode == CL_SUCCESS )
2527+
logf( " For device: %s\n",
2528+
deviceName );
2529+
if( config().KernelInfoLogging ||
2530+
config().PreferredWorkGroupSizeMultipleLogging )
24922531
{
2493-
char* deviceName = NULL;
2494-
2495-
errorCode = allocateAndGetDeviceInfoString(
2496-
deviceList[i],
2497-
CL_DEVICE_NAME,
2498-
deviceName );
2499-
if( errorCode == CL_SUCCESS )
2532+
logf( " Preferred Work Group Size Multiple: %u\n", (cl_uint)pwgsm);
2533+
}
2534+
if( config().KernelInfoLogging )
2535+
{
2536+
logf( " Work Group Size: %u\n", (cl_uint)wgs);
2537+
logf( " Private Mem Size: %u\n", (cl_uint)pms);
2538+
logf( " Local Mem Size: %u\n", (cl_uint)lms);
2539+
if( errorCode_sms == CL_SUCCESS )
25002540
{
2501-
logf( " for device %s: %u\n",
2502-
deviceName,
2503-
(unsigned int)kernelPreferredWorkGroupSizeMultiple );
2541+
logf( " Spill Mem Size: %u\n", (cl_uint)sms);
25042542
}
2505-
2506-
delete [] deviceName;
25072543
}
25082544
}
2545+
else if( deviceName )
2546+
{
2547+
logf( "Error querying kernel info for device %s!\n", deviceName );
2548+
}
2549+
else
2550+
{
2551+
logf( "Error querying kernel info!\n" );
2552+
}
2553+
2554+
delete [] deviceName;
25092555
}
25102556
}
25112557

intercept/src/intercept.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CLIntercept
187187
const std::string& flushOrFinish,
188188
const std::string& functionName,
189189
cl_int errorCode );
190-
void logPreferredWorkGroupSizeMultiple(
190+
void logKernelInfo(
191191
const cl_kernel* kernels,
192192
cl_uint numKernels );
193193

0 commit comments

Comments
 (0)