Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (88 loc) · 3.7 KB
/
Copy pathMakefile
File metadata and controls
110 lines (88 loc) · 3.7 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# HyperPipe
#
# make build build/hyperpipe
# make test build and run every tests/test_*.c (TAP output)
# make bench build build/bench_hyperpipe
# make fuzz ASan + UBSan fuzz run; FUZZ_K sets thousands of iterations
# make coverage line coverage of the test suite (gcov)
# make pgo profile-guided build/hyperpipe-pgo, trained on data/
#
# CFLAGS and LDFLAGS are the user's; the flags the code needs are added below.
CC ?= cc
CFLAGS ?= -O3
BUILD ?= build
FUZZ_K ?= 50
HP_CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Werror \
-D_POSIX_C_SOURCE=200809L -D_FILE_OFFSET_BITS=64 -Iinclude -MMD -MP
ifeq ($(OS),Windows_NT)
EXE = .exe
LDLIBS = -lpsapi
else
EXE =
LDLIBS = -pthread -ldl -lm
# macOS hides sysconf names such as _SC_NPROCESSORS_ONLN under strict POSIX
ifeq ($(shell uname -s),Darwin)
HP_CFLAGS += -D_DARWIN_C_SOURCE
endif
endif
LIB_SRCS := $(filter-out src/hp_main.c,$(wildcard src/*.c))
# The vector units are x86 only; elsewhere the scalar engine is built alone.
ARCH := $(shell $(CC) -dumpmachine)
ifneq ($(findstring x86_64,$(ARCH))$(findstring i686,$(ARCH)),)
AVX2_FLAGS = -mavx2 -mbmi2
AVX512_FLAGS = -mavx512f -mavx512bw -mavx512vl -mavx2 -mbmi2
else
LIB_SRCS := $(filter-out %_avx2.c %_avx512.c,$(LIB_SRCS))
endif
LIB_OBJS = $(LIB_SRCS:src/%.c=$(BUILD)/%.o)
LIB = $(BUILD)/libhyperpipe.a
TESTS = $(patsubst tests/%.c,$(BUILD)/%$(EXE),$(wildcard tests/test_*.c))
all: $(BUILD)/hyperpipe$(EXE)
$(BUILD):
mkdir -p $@
$(BUILD)/%.o: src/%.c | $(BUILD)
$(CC) $(HP_CFLAGS) $(CFLAGS) $(SIMD_FLAGS) -c $< -o $@
$(BUILD)/hp_csv_avx2.o $(BUILD)/hp_json_avx2.o: SIMD_FLAGS = $(AVX2_FLAGS)
$(BUILD)/hp_csv_avx512.o $(BUILD)/hp_json_avx512.o: SIMD_FLAGS = $(AVX512_FLAGS)
$(LIB): $(LIB_OBJS)
$(AR) rcs $@ $^
$(BUILD)/hyperpipe$(EXE): src/hp_main.c $(LIB)
$(CC) $(HP_CFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LIB) $(LDLIBS) -o $@
$(BUILD)/bench_hyperpipe$(EXE): bench/bench_main.c $(LIB)
$(CC) $(HP_CFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LIB) $(LDLIBS) -o $@
$(BUILD)/test_%$(EXE): tests/test_%.c $(LIB)
$(CC) $(HP_CFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LIB) $(LDLIBS) -o $@
bench: $(BUILD)/bench_hyperpipe$(EXE)
test: $(TESTS)
@for t in $(TESTS); do echo "# $$t"; ./$$t || exit 1; done
# The library is built in its own directory so each unit keeps its own
# vector flags: AVX-512 flags on every unit would put AVX-512 in the
# scalar paths too.
FUZZ = $(BUILD)/fuzz
SAN = -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all
fuzz:
$(MAKE) BUILD=$(FUZZ) CFLAGS="$(SAN)" $(FUZZ)/libhyperpipe.a
$(CC) $(HP_CFLAGS) $(SAN) tests/fuzz_harness.c $(FUZZ)/libhyperpipe.a $(LDLIBS) \
-o $(BUILD)/fuzz_hyperpipe$(EXE)
./$(BUILD)/fuzz_hyperpipe$(EXE) $(FUZZ_K) $(wildcard tests/corpus/*)
COV = $(BUILD)/coverage
coverage:
rm -rf $(COV) && mkdir -p $(COV)
$(MAKE) BUILD=$(COV) CFLAGS="-O0 --coverage" LDFLAGS=--coverage test
gcov -n -o $(COV) $(LIB_SRCS) | grep -A1 "^File 'src"
# Trained on the CSV filter path only: training the NDJSON paths as well
# reordered the serializer's branches and slowed CSV to NDJSON.
PGO = $(BUILD)/pgo
pgo:
rm -rf $(PGO) && mkdir -p $(PGO)
$(MAKE) BUILD=$(PGO) CFLAGS="$(CFLAGS) -fprofile-generate -fprofile-update=atomic" \
LDFLAGS=-fprofile-generate
./$(PGO)/hyperpipe$(EXE) data/nasa_server_access_log.csv "status == 200" \
--select host,status,bytes --to csv --jobs 1 -o $(PGO)/train.out
rm -f $(PGO)/*.o $(PGO)/libhyperpipe.a $(PGO)/hyperpipe$(EXE)
$(MAKE) BUILD=$(PGO) CFLAGS="$(CFLAGS) -fprofile-use -fprofile-correction"
cp $(PGO)/hyperpipe$(EXE) $(BUILD)/hyperpipe-pgo$(EXE)
clean:
rm -rf $(BUILD)
.PHONY: all bench test fuzz coverage pgo clean
-include $(wildcard $(BUILD)/*.d)