-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (102 loc) · 4.4 KB
/
Makefile
File metadata and controls
133 lines (102 loc) · 4.4 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
CC ?= cc
CFLAGS := -std=c11 -Wall -Wextra -Werror -pedantic -O2 \
-D_POSIX_C_SOURCE=200809L -Iinclude
LDFLAGS := -lm -lpthread
# SIMD selection: make SIMD=avx2 (or avx512, neon, scalar)
SIMD ?= avx2
BITNET_MODEL ?= models/BitNet-b1.58-2B-4T/ggml-model-i2_s.gguf
ifeq ($(SIMD),avx512)
CFLAGS += -mavx2 -mfma -mavx512f -mavx512bw -mavx512vl -mavx512vnni
MATMUL_SRC = src/bitnet_matmul_avx512.c src/bitnet_matmul_avx2.c src/bitnet_matmul_scalar.c
else ifeq ($(SIMD),avx2)
CFLAGS += -mavx2 -mfma
MATMUL_SRC = src/bitnet_matmul_avx2.c src/bitnet_matmul_scalar.c
else ifeq ($(SIMD),neon)
MATMUL_SRC = src/bitnet_matmul_scalar.c
else
MATMUL_SRC = src/bitnet_matmul_scalar.c
endif
SRCS := src/bitnet_gguf.c \
src/bitnet_arena.c \
src/bitnet_quant.c \
$(MATMUL_SRC) \
src/bitnet_sampler.c \
src/bitnet_tokenizer.c \
src/bitnet_core.c
OBJS := $(SRCS:.c=.o)
OBJS_NO_CORE := $(filter-out src/bitnet_core.o,$(OBJS))
.PHONY: all clean test bench compare
all: bitnet_cli bitnet_bench bench_rope
%.o: %.c include/bitnet.h
$(CC) $(CFLAGS) -c $< -o $@
bitnet_cli: $(OBJS) tools/bitnet_cli.c
$(CC) $(CFLAGS) -o $@ tools/bitnet_cli.c $(OBJS) $(LDFLAGS)
bitnet_bench: $(OBJS) tools/bitnet_bench.c
$(CC) $(CFLAGS) -o $@ tools/bitnet_bench.c $(OBJS) $(LDFLAGS)
bench_rope: tools/bench_rope.c
$(CC) $(CFLAGS) -o $@ tools/bench_rope.c $(LDFLAGS)
test_gguf: $(OBJS) tests/test_gguf.c
$(CC) $(CFLAGS) -o $@ tests/test_gguf.c $(OBJS) $(LDFLAGS)
test_matmul: $(OBJS) tests/test_matmul.c
$(CC) $(CFLAGS) -o $@ tests/test_matmul.c $(OBJS) $(LDFLAGS)
test_thread_create_failures: $(OBJS_NO_CORE) tests/test_thread_create_failures.c
$(CC) $(CFLAGS) -o $@ tests/test_thread_create_failures.c $(OBJS_NO_CORE) $(LDFLAGS)
test_quantizer: $(OBJS) tests/test_quantizer.c
$(CC) $(CFLAGS) -o $@ tests/test_quantizer.c $(OBJS) $(LDFLAGS)
test_tokenizer: $(OBJS) tests/test_tokenizer.c
$(CC) $(CFLAGS) -o $@ tests/test_tokenizer.c $(OBJS) $(LDFLAGS)
test_tokenizer_utf8: $(OBJS) tests/test_tokenizer_utf8.c
$(CC) $(CFLAGS) -o $@ tests/test_tokenizer_utf8.c $(OBJS) $(LDFLAGS)
test_tokenizer_metadata: $(OBJS) tests/test_tokenizer_metadata.c
$(CC) $(CFLAGS) -o $@ tests/test_tokenizer_metadata.c $(OBJS) $(LDFLAGS)
test_tokenizer_threads: $(OBJS) tests/test_tokenizer_threads.c
$(CC) $(CFLAGS) -o $@ tests/test_tokenizer_threads.c $(OBJS) $(LDFLAGS)
test_arena: $(OBJS) tests/test_arena.c
$(CC) $(CFLAGS) -o $@ tests/test_arena.c $(OBJS) $(LDFLAGS)
test_forward_guards: $(OBJS) tests/test_forward_guards.c
$(CC) $(CFLAGS) -o $@ tests/test_forward_guards.c $(OBJS) $(LDFLAGS)
test_sampler_oom: $(OBJS) tests/test_sampler_oom.c
$(CC) $(CFLAGS) -o $@ tests/test_sampler_oom.c $(OBJS) $(LDFLAGS)
test_sampler_init: $(OBJS) tests/test_sampler_init.c
$(CC) $(CFLAGS) -o $@ tests/test_sampler_init.c $(OBJS) $(LDFLAGS)
test_vs_reference: $(OBJS) tests/test_vs_reference.c
$(CC) $(CFLAGS) -o $@ tests/test_vs_reference.c $(OBJS) $(LDFLAGS)
test_rmsnorm: tests/test_rmsnorm.c
$(CC) $(CFLAGS) -o $@ tests/test_rmsnorm.c $(LDFLAGS)
test_cli_args: tests/test_cli_args.c bitnet_cli bitnet_bench
$(CC) $(CFLAGS) -o $@ tests/test_cli_args.c $(LDFLAGS)
test: test_gguf test_matmul test_thread_create_failures test_quantizer test_tokenizer_utf8 test_tokenizer_metadata test_tokenizer_threads test_arena test_forward_guards test_sampler_oom test_sampler_init test_rmsnorm test_cli_args
@echo "=== Running all tests ==="
./test_matmul
@echo ""
./test_thread_create_failures
@echo ""
./test_quantizer
@echo ""
./test_gguf
@echo ""
./test_tokenizer_utf8
@echo ""
./test_tokenizer_metadata
@echo ""
./test_tokenizer_threads
@echo ""
./test_arena
@echo ""
./test_forward_guards
@echo ""
./test_sampler_oom
@echo ""
./test_sampler_init
@echo ""
./test_rmsnorm
@echo ""
./test_cli_args
bench: bitnet_bench
./bitnet_bench -m $(BITNET_MODEL) -t 4
compare_llama: $(OBJS) tools/compare_llama.c
$(CC) $(CFLAGS) -o $@ tools/compare_llama.c $(OBJS) $(LDFLAGS)
compare: compare_llama
./compare_llama
clean:
rm -f $(OBJS) src/bitnet_matmul_avx512.o src/bitnet_matmul_avx2.o src/bitnet_matmul_scalar.o bitnet_cli bitnet_bench bench_rope compare_llama test_gguf test_matmul test_thread_create_failures test_quantizer test_tokenizer test_tokenizer_utf8 test_tokenizer_metadata test_tokenizer_threads test_arena test_forward_guards test_sampler_oom test_sampler_init test_vs_reference test_rmsnorm test_cli_args