Skip to content
Open
Show file tree
Hide file tree
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
45 changes: 33 additions & 12 deletions src/common.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1229,12 +1229,16 @@ static bool parseInt(char *s, int *num) {
while (*s && isspace(*s)) ++s;
if (!*s) return false;

if (strncasecmp(s, "0b", 2) == 0)
*num = (int)strtoul(s + 2, &p, 2);
else
*num = (int)strtoul(s, &p, 0);
errno = 0;
char *start = s;
if (strncasecmp(s, "0b", 2) == 0) {
start = s + 2;
*num = (int)strtoul(start, &p, 2);
} else {
*num = (int)strtoul(start, &p, 0);
}

if (p == s)
if (p == start || errno == ERANGE)
return false;
return true;
}
Expand All @@ -1258,9 +1262,16 @@ testResult_t run() {
}

char *splitMaskEnv = NULL;
if (splitMaskEnv = getenv("NCCL_TESTS_SPLIT_MASK")) {
color = proc & strtoul(splitMaskEnv, NULL, 16);
} else if (splitMaskEnv = getenv("NCCL_TESTS_SPLIT")) {
if ((splitMaskEnv = getenv("NCCL_TESTS_SPLIT_MASK"))) {
char *end;
errno = 0;
unsigned long mask = strtoul(splitMaskEnv, &end, 16);
if (end == splitMaskEnv || *end != '\0' || errno == ERANGE) {
fprintf(stderr, "Warning: invalid NCCL_TESTS_SPLIT_MASK='%s', ignoring\n", splitMaskEnv);
} else {
color = proc & (int)mask;
}
} else if ((splitMaskEnv = getenv("NCCL_TESTS_SPLIT"))) {
if (
(strncasecmp(splitMaskEnv, "AND", strlen("AND")) == 0 && parseInt(splitMaskEnv + strlen("AND"), &color)) ||
(strncasecmp(splitMaskEnv, "&", strlen("&")) == 0 && parseInt(splitMaskEnv + strlen("&"), &color))
Expand All @@ -1274,13 +1285,23 @@ testResult_t run() {
if (
(strncasecmp(splitMaskEnv, "MOD", strlen("MOD")) == 0 && parseInt(splitMaskEnv + strlen("MOD"), &color)) ||
(strncasecmp(splitMaskEnv, "%", strlen("%")) == 0 && parseInt(splitMaskEnv + strlen("%"), &color))
)
color = proc % color;
) {
if (color == 0) {
fprintf(stderr, "Warning: NCCL_TESTS_SPLIT modulo by zero, ignoring\n");
} else {
color = proc % color;
}
}
if (
(strncasecmp(splitMaskEnv, "DIV", strlen("DIV")) == 0 && parseInt(splitMaskEnv + strlen("DIV"), &color)) ||
(strncasecmp(splitMaskEnv, "/", strlen("/")) == 0 && parseInt(splitMaskEnv + strlen("/"), &color))
)
color = proc / color;
) {
if (color == 0) {
fprintf(stderr, "Warning: NCCL_TESTS_SPLIT division by zero, ignoring\n");
} else {
color = proc / color;
}
}
}

MPI_Comm mpi_comm;
Expand Down
6 changes: 6 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SUBDIRS := $(shell ls -d c 2>/dev/null)

test:
@for d in $(SUBDIRS); do $(MAKE) -C $$d test; done

.PHONY: test
19 changes: 19 additions & 0 deletions tests/c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CC := gcc
CFLAGS := -Wall -Wextra -Wno-format-truncation -g -std=c99 -fPIC -D_GNU_SOURCE
LDFLAGS := -lpthread

SOURCES := $(wildcard test_*.c)
TARGETS := $(SOURCES:.c=)

all: $(TARGETS)

%: %.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

test: $(TARGETS)
@for t in $(TARGETS); do echo "=== $$t ==="; ./$$t; echo; done

clean:
rm -f $(TARGETS)

.PHONY: all test clean
Loading