From 8cf7325d69184d01bd37fb50d03f8a05e647c5b6 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 18 Nov 2021 14:21:05 +0000 Subject: [PATCH] Perform `busIdToInt64` on the stack. I noticed when I enabled `NCCL_DEBUG_SUBSYS=ALLOC` that this function is called thousands of times, making the log output unintelligible. Fortunately, this function can be implemented without heap allocations. --- src/misc/utils.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/misc/utils.cc b/src/misc/utils.cc index 79e6170..f3e3ca2 100644 --- a/src/misc/utils.cc +++ b/src/misc/utils.cc @@ -25,11 +25,9 @@ ncclResult_t int64ToBusId(int64_t id, char* busId) { } ncclResult_t busIdToInt64(const char* busId, int64_t* id) { - const int size = strlen(busId); - char* hexStr; - NCCLCHECK(ncclCalloc(&hexStr, size)); + char hexStr[17]; // Longest possible int64 hex string + null terminator. int hexOffset = 0; - for (int i=0; i= '0' && c <= '9') || @@ -40,7 +38,6 @@ ncclResult_t busIdToInt64(const char* busId, int64_t* id) { } hexStr[hexOffset] = '\0'; *id = strtol(hexStr, NULL, 16); - free(hexStr); return ncclSuccess; }