bridge: let the launch-stats dump take a kernel filter
D4R_CUDA_LAUNCH_STATS=1 synchronizes after and dumps every argument of every launch, which costs about 1.2 GB and 5 s per frame - fine for a one-off inventory, too much for the edit/measure loop of a single kernel. D4R_CUDA_LAUNCH_STATS_FILTER=<substring> keeps only the kernels whose name contains it, and is checked before the synchronize so the rest of the frame is neither waited on nor written. Verified: with the filter set to swin_enc0 the dump is 54 files / 839 MB instead of 314 / 3.7 GB, the run takes 5 s instead of 17, and the 54 argument files are byte-identical to the ones the unfiltered run produced.
This commit is contained in:
1 parent
708b158332
commit
1a9762bb0e
2 files changed
+15
-2
No files matched your search
@@ -1755,12 +1755,25 @@ static void summarize_launch(unsigned int sequence, CUfunction function_handle,
|
||||
if (extra == NULL || (uintptr_t)extra[0] != 1 || extra[1] == NULL ||
|
||||
(uintptr_t)extra[2] != 2 || extra[3] == NULL)
|
||||
return;
|
||||
/* D4R_CUDA_LAUNCH_STATS_FILTER restricts the summarise/dump to kernels whose
|
||||
name contains it, before the synchronize, so iterating on one kernel does
|
||||
not pay for, or write, the rest of the frame. */
|
||||
static char stats_filter[128];
|
||||
static int stats_filter_ready;
|
||||
if (!stats_filter_ready)
|
||||
{
|
||||
const char* value = getenv("D4R_CUDA_LAUNCH_STATS_FILTER");
|
||||
snprintf(stats_filter, sizeof(stats_filter), "%s", value != NULL ? value : "");
|
||||
stats_filter_ready = 1;
|
||||
}
|
||||
const char* kernel = find_function_name(function_handle);
|
||||
if (stats_filter[0] != '\0' && strstr(kernel, stats_filter) == NULL)
|
||||
return;
|
||||
CUCTX_SYNCHRONIZE_FN synchronize = (CUCTX_SYNCHRONIZE_FN)find_zluda_symbol("cuCtxSynchronize");
|
||||
CUMEMCPYDTOH_FN copy_to_host = (CUMEMCPYDTOH_FN)find_zluda_symbol("cuMemcpyDtoH_v2");
|
||||
if (synchronize == NULL || copy_to_host == NULL)
|
||||
return;
|
||||
const CUresult sync_result = synchronize();
|
||||
const char* kernel = find_function_name(function_handle);
|
||||
tracef("launch[%u] %s synchronize result=%d", sequence, kernel, sync_result);
|
||||
const unsigned char* arguments = (const unsigned char*)extra[1];
|
||||
const size_t argument_bytes = *(const size_t*)extra[3];
|
||||
|
||||
Reference in new issue
Block a user