Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ncclDebugLog: fix for log payload larger than buf #825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,25 @@ void ncclDebugLog(ncclDebugLogLevel level, unsigned long flags, const char *file
hostname, pid, tid, cudaDev, timestamp, filefunc, line);
}

if (len) {
// If header resulted in no error and was not truncated try to add caller payload and write:
if (len >= 0 && len < sizeof(buffer)) {
va_list vargs;
va_start(vargs, fmt);
len += vsnprintf(buffer+len, sizeof(buffer)-len, fmt, vargs);
// Try adding caller payload starting on the terminating \0 of the header
int va_len = vsnprintf(buffer+len, sizeof(buffer)-len, fmt, vargs);
va_end(vargs);
buffer[len++] = '\n';
fwrite(buffer, 1, len, ncclDebugFile);
// If no error, write message
if (va_len >= 0) {
// If payload was not truncated, replace terminating \0 with \n and write message
if (va_len < sizeof(buffer) - len) {
buffer[len + va_len] = '\n';
fwrite(buffer, 1, len + va_len + 1, ncclDebugFile);
} else {
// If payload was truncated, replace last character with \n and write truncated message
buffer[sizeof(buffer) - 1] = '\n';
fwrite(buffer, 1, sizeof(buffer), ncclDebugFile);
}
}
}
}

Expand Down