Skip to content

Commit fad079a

Browse files
committed
Updated PR#196 to use a common hash function
1 parent 01d1836 commit fad079a

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

src/include/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <stdint.h>
1212

1313
ncclResult_t getHostName(char* hostname, int maxlen, const char delim);
14-
uint64_t getnHash(const char* string, int n);
14+
uint64_t getHash(const char* string, int n);
1515
uint64_t getHostHash();
1616
uint64_t getPidHash();
1717

src/init.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,8 @@ static ncclResult_t initTransportsRank(struct ncclComm* comm, ncclUniqueId* comm
691691

692692
int rank = comm->rank;
693693
int nranks = comm->nRanks;
694-
uint64_t commHash = getnHash(commId->internal, NCCL_UNIQUE_ID_BYTES);
695-
TRACE(NCCL_INIT, "comm %p, commHash %lu, rank %d nranks %d - BEGIN", comm, commHash, rank, nranks);
694+
uint64_t commHash = getHash(commId->internal, NCCL_UNIQUE_ID_BYTES);
695+
TRACE(NCCL_INIT, "comm %p, commHash %lx, rank %d nranks %d - BEGIN", comm, commHash, rank, nranks);
696696
NCCLCHECK(bootstrapInit(commId, rank, nranks, &comm->bootstrap));
697697

698698
// AllGather1 - begin

src/misc/utils.cc

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,9 @@ void ncclDebugLog(ncclDebugLogLevel level, unsigned long flags, const char *file
8787
}
8888
}
8989

90-
uint64_t getHash(const char* string) {
90+
uint64_t getHash(const char* string, int n) {
9191
// Based on DJB2, result = result * 33 + char
9292
uint64_t result = 5381;
93-
for (int c = 0; string[c] != '\0'; c++) {
94-
result = ((result << 5) + result) + string[c];
95-
}
96-
return result;
97-
}
98-
99-
uint64_t getnHash(const char* string, int n) {
100-
// Based on DJB2, result = result * 33 + char
101-
uint64_t result = 9527;
10293
for (int c = 0; c < n; c++) {
10394
result = ((result << 5) + result) + string[c];
10495
}
@@ -129,7 +120,7 @@ uint64_t getHostHash(void) {
129120
uname[offset]='\0';
130121
TRACE(NCCL_INIT,"unique hostname '%s'", uname);
131122

132-
return getHash(uname);
123+
return getHash(uname, strlen(uname));
133124
}
134125

135126
/* Generate a hash of the unique identifying string for this process
@@ -149,7 +140,7 @@ uint64_t getPidHash(void) {
149140
pname[plen+len]='\0';
150141
TRACE(NCCL_INIT,"unique PID '%s'", pname);
151142

152-
return getHash(pname);
143+
return getHash(pname, strlen(pname));
153144
}
154145

155146
int parseStringList(const char* string, struct netIf* ifList, int maxList) {

0 commit comments

Comments
 (0)