-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
96 lines (83 loc) · 2.58 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
BENCH_LIBS := bench openlibm soft-fp
$(BENCH_LIBS): %:
$(MAKE) -s -C ./src/common/$* archive
COLOR_RED = \033[1;31m
COLOR_GREEN = \033[1;32m
COLOR_NONE = \033[0m
RESULT = .result
$(shell > $(RESULT))
KEEP_LOG_FAILED ?= true
KEEP_LOG_SUCCEED ?= false
TIME := $(shell date --iso=seconds)
ifeq ($(mainargs),ref)
ALL = mcf x264 tcc stream linpack gemm whetstone
else
ALL = cpuemu mcf x264 tcc stream linpack gemm whetstone
endif
all: $(BENCH_LIBS) $(ALL)
@echo "OpenPerf [$(words $(ALL)) item(s)]:" $(ALL)
@if [ -z "$(mainargs)" ]; then \
echo "Empty mainargs, use \"ref\" by default"; \
echo "====== Running OpenPerf [input *ref*] ======"; \
else \
echo "====== Running OpenPerf [input *$${mainargs}*] ======"; \
fi
$(ALL): %: $(BENCH_LIBS)
@{\
TMP=$*.tmp;\
$(MAKE) -C ./src/$* ARCH=$(ARCH) run 2>&1 | tee -a $$TMP;\
if [ $${PIPESTATUS[0]} -eq 0 ]; then \
printf "[%14s] $(COLOR_GREEN)PASS$(COLOR_NONE) " $* >> $(RESULT); \
cat $$TMP | grep -E -i -e "OpenPerf time: ([0-9]*\.)?[0-9]*" >> $(RESULT); \
if $(KEEP_LOG_SUCCEED); then \
mkdir -p "logs/$(TIME)/"; \
mv $$TMP "logs/$(TIME)/"; \
else \
rm $$TMP; \
fi \
else \
printf "[%14s] $(COLOR_RED)***FAIL***$(COLOR_NONE)\n" $* >> $(RESULT); \
if $(KEEP_LOG_FAILED); then \
mkdir -p "logs/$(TIME)/"; \
mv $$TMP "logs/$(TIME)/"; \
else \
rm $$TMP; \
fi \
fi \
}
run: $(BENCH_LIBS) all
@cat $(RESULT)
@echo "============================================="
@awk '\
BEGIN {total_us = 0 } \
{ \
h = min = s = ms = us = 0;\
if (match($$0, /([0-9]+) h/, arr)) h = arr[1]; \
if (match($$0, /([0-9]+) min/, arr)) min = arr[1]; \
if (match($$0, /([0-9]+) s/, arr)) s = arr[1]; \
if (match($$0, /([0-9]+)\.([0-9]*) ms/, arr)) {ms = arr[1]; us = arr[2];} \
total_us += h * 3600 * 1000 * 1000 + min * 60 * 1000 * 1000 + s * 1000 * 1000 + ms * 1000 + us; \
} \
END { \
printf "Total time: %d h %d min %d s %d.%d ms\n", \
int(total_us / (3600 * 1000 * 1000)), \
int((total_us % (3600 * 1000 * 1000)) / (60 * 1000 * 1000)), \
int((total_us % (60 * 1000 * 1000)) / (1000 * 1000)), \
int((total_us % (1000 * 1000) / 1000)), \
total_us % 1000; \
} \
' $(RESULT)
@if grep -q -i -e "fail" "$(RESULT)"; then \
echo "OpenPerf FAIL"; \
rm $(RESULT); \
exit 1; \
else \
echo "OpenPerf PASS"; \
rm $(RESULT); \
exit 0; \
fi
CLEAN_ALL = $(dir $(shell find . -mindepth 2 -name Makefile))
clean-all: $(CLEAN_ALL)
$(CLEAN_ALL):
-@$(MAKE) -s -C $@ clean
.PHONY: $(BENCH_LIBS) $(CLEAN_ALL) $(ALL) all run clean-all