blob: 838a47afba15c3a7599ff298d33efcfed513865a (
plain) (
blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
CC ?= cc
OPT ?= -O2 -g
WARN = -Wall -Wextra
CFLAGS = $(OPT) $(WARN) -std=gnu11
CPPFLAGS = -Isrc
LDLIBS = -lm
# Parity depends on the compiler not reassociating or contracting the
# reductions differently from the reference; -ffast-math is deliberately
# absent.
#
# No architecture flags are needed or wanted. On x86 the AVX2 kernels carry
# their own instruction set on the functions and are selected against the
# running processor, so a default build is both safe on a host without AVX2
# and fast on one with it.
#
# THREADS=0 drops the pthread dependency; the window loop then runs on the
# calling thread whatever --threads asks for.
# EMBED=0 leaves the weight blob out of the binary, which then needs
# --weights pyseg_weights.bin.
# STATIC=1 links a self-contained binary, for a container that carries
# nothing but the executable.
THREADS ?= 1
EMBED ?= 1
ifeq ($(THREADS),1)
CPPFLAGS += -DPYSEG_THREADS
LDLIBS += -lpthread
endif
ifeq ($(STATIC),1)
LDFLAGS += -static
endif
BUILD := build
LIB := $(BUILD)/libpyseg.a
BIN := pyseg_cli
LIB_SRCS := src/pyseg.c src/kernels.c src/weights.c src/slide.c
ifeq ($(EMBED),1)
CPPFLAGS += -DPYSEG_EMBED_WEIGHTS
LIB_SRCS += src/weights_blob.c
endif
LIB_OBJS := $(LIB_SRCS:%.c=$(BUILD)/%.o)
CLI_SRCS := src/pyseg_cli.c src/wav.c
CLI_OBJS := $(CLI_SRCS:%.c=$(BUILD)/%.o)
TESTS := test_kernels test_parity test_robust test_slide
TEST_BINS := $(TESTS:%=$(BUILD)/%)
TEST_CPPFLAGS := $(CPPFLAGS) -Itests
BENCH := $(BUILD)/bench
WEIGHTS := pyseg_weights.bin
GOLDEN := $(BUILD)/golden.bin
SLIDE_GOLDEN := $(BUILD)/slide_golden.bin
AUDIO ?= testdata_aepyx.wav
PY := PYTHONPATH=tools .venv/bin/python
PYTHON ?= python3
.PHONY: all test bench clean weights golden verify
all: $(LIB) $(BIN)
$(LIB): $(LIB_OBJS)
@rm -f $@
ar rcs $@ $(LIB_OBJS)
$(BIN): $(CLI_OBJS) $(LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(CLI_OBJS) $(LIB) $(LDLIBS)
$(BUILD)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -c $< -o $@
# The generated weight array is data, not code; optimising it only costs
# compile time.
$(BUILD)/src/weights_blob.o: src/weights_blob.c
@mkdir -p $(dir $@)
$(CC) -O0 -g0 -std=gnu11 -c $< -o $@
$(BUILD)/test_%: tests/test_%.c $(LIB) tests/test_util.h
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(TEST_CPPFLAGS) $(LDFLAGS) $< $(LIB) -o $@ $(LDLIBS)
$(BENCH): bench/bench.c $(LIB)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< $(LIB) -o $@ $(LDLIBS)
# Regenerates the weight blob from the checkpoint in the Hugging Face cache.
# The blob is checked in, so this is only needed after a layout change; the
# embedded copy is derived from it by a plain-stdlib script that runs anywhere,
# including inside the container build.
weights:
$(PY) tools/export_weights.py .
$(MAKE) src/weights_blob.c
src/weights_blob.c: $(WEIGHTS) tools/embed.py
$(PYTHON) tools/embed.py $(WEIGHTS) $@
golden: $(GOLDEN) $(SLIDE_GOLDEN)
$(GOLDEN): golden.npz tools/make_golden.py
@mkdir -p $(BUILD)
$(PY) tools/make_golden.py chunks $< $@
$(SLIDE_GOLDEN): $(AUDIO) tools/make_golden.py
@mkdir -p $(BUILD)
$(PY) tools/make_golden.py slide $< $@
golden.npz: $(AUDIO) tools/baseline.py
$(PY) tools/baseline.py golden $< $@
test: $(TEST_BINS) $(GOLDEN) $(SLIDE_GOLDEN)
@rc=0; \
$(BUILD)/test_kernels || rc=1; \
$(BUILD)/test_parity $(GOLDEN) || rc=1; \
$(BUILD)/test_robust || rc=1; \
$(BUILD)/test_slide $(SLIDE_GOLDEN) || rc=1; \
if [ $$rc -eq 0 ]; then echo "all ok"; else echo "not ok"; exit 1; fi
bench: $(BENCH) $(GOLDEN)
$(BENCH) $(GOLDEN)
# End-to-end against pyannote's own pipelines; needs the Python environment.
verify: $(BIN)
$(PY) tools/verify_cli.py $(AUDIO)
clean:
rm -rf $(BUILD) $(BIN)
-include $(LIB_OBJS:.o=.d) $(CLI_OBJS:.o=.d)
|