-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (70 loc) · 2.84 KB
/
Copy pathMakefile
File metadata and controls
94 lines (70 loc) · 2.84 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
# ===========================================================================
# attention — Makefile
# Part 6 of: Transformer from Scratch in Pure C
#
# This project only depends on mini-tensor.
# ===========================================================================
CC = gcc
CFLAGS = -std=c99 -Wall -Wextra -Werror -pedantic -g -O2 \
-Iinclude \
-I../mini-tensor/include
BUILD = build
# ---------------------------------------------------------------------------
# Object files
# ---------------------------------------------------------------------------
TENSOR_OBJ = $(BUILD)/tensor.o
RANDOM_OBJ = $(BUILD)/random.o
ATTN_OBJ = $(BUILD)/attention.o
OBJS = $(TENSOR_OBJ) $(RANDOM_OBJ) $(ATTN_OBJ)
# ---------------------------------------------------------------------------
# Targets
# ---------------------------------------------------------------------------
.PHONY: all demo test valgrind clean
all: $(BUILD)/demo
# ---------------------------------------------------------------------------
# Build directory
# ---------------------------------------------------------------------------
$(BUILD):
mkdir -p $(BUILD)
@echo " Build directory created."
# ---------------------------------------------------------------------------
# Upstream objects (mini-tensor only)
# ---------------------------------------------------------------------------
$(TENSOR_OBJ): ../mini-tensor/src/tensor.c | $(BUILD)
$(CC) $(CFLAGS) -c $< -o $@
$(RANDOM_OBJ): ../mini-tensor/src/random.c | $(BUILD)
$(CC) $(CFLAGS) -c $< -o $@
$(ATTN_OBJ): src/attention.c | $(BUILD)
$(CC) $(CFLAGS) -c $< -o $@
# ---------------------------------------------------------------------------
# Demo
# ---------------------------------------------------------------------------
$(BUILD)/demo: src/demo.c $(OBJS)
$(CC) $(CFLAGS) $^ -o $@ -lm
demo: $(BUILD)/demo
@echo ""
./$(BUILD)/demo
# ---------------------------------------------------------------------------
# Test suite
# ---------------------------------------------------------------------------
$(BUILD)/test_attention: tests/test_attention.c $(OBJS)
$(CC) $(CFLAGS) $^ -o $@ -lm
test: $(BUILD)/test_attention
@echo ""
./$(BUILD)/test_attention
# ---------------------------------------------------------------------------
# Memory check
# ---------------------------------------------------------------------------
valgrind: $(BUILD)/test_attention $(BUILD)/demo
@echo ""
@echo "=== valgrind: test suite ==="
valgrind --leak-check=full --error-exitcode=1 ./$(BUILD)/test_attention
@echo ""
@echo "=== valgrind: demo ==="
valgrind --leak-check=full --error-exitcode=1 ./$(BUILD)/demo
# ---------------------------------------------------------------------------
# Clean
# ---------------------------------------------------------------------------
clean:
rm -rf $(BUILD)
@echo " Build directory removed."