-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
68 lines (56 loc) · 2.13 KB
/
makefile
File metadata and controls
68 lines (56 loc) · 2.13 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
CC = gcc
CFLAGS = -O3 -Wall -Wextra -std=c11 -I./include -march=native \
-D_POSIX_C_SOURCE=199309L
LDFLAGS = -lm
SIMDFLAGS = -mavx2 -mfma
SRC = src/main.c src/matrix.c src/multiply_naive.c src/multiply_opt.c \
src/multiply_simd.c src/timer.c src/verify.c
ifeq ($(OS),Windows_NT)
OUT = matrix_app.exe
RUN = .\$(OUT)
RM = del /Q
else
OUT = matrix_app
RUN = ./$(OUT)
RM = rm -f
endif
# ── Targets ───────────────────────────────────────────────────────────────────
.PHONY: all run clean cachegrind perf help
## Default: build with AVX2 SIMD
all:
$(CC) $(CFLAGS) $(SIMDFLAGS) $(SRC) -o $(OUT) $(LDFLAGS)
@echo "Build OK → $(OUT)"
## Build without AVX2 (fallback scalar path in multiply_simd.c)
nosimd:
$(CC) $(CFLAGS) $(SRC) -o $(OUT) $(LDFLAGS)
@echo "Build OK (no SIMD) → $(OUT)"
run: all
$(RUN)
## Run Cachegrind cache profiling (only Linux )
## Output: cachegrind.out.<pid> → parsed to cachegrind_report.txt
cachegrind: all
valgrind --tool=cachegrind \
--cachegrind-out-file=cachegrind.out \
--D1=32768,8,64 \
--LL=8388608,16,64 \
$(RUN)
cg_annotate cachegrind.out > cachegrind_report.txt
@echo "Cache profile written to cachegrind_report.txt"
## Run perf hardware-counter profiling (Linux only, requires perf installed)
## Output: perf_report.txt
perf: all
perf stat -e cycles,instructions,cache-misses,cache-references,\
L1-dcache-loads,L1-dcache-load-misses,LLC-loads,LLC-load-misses \
$(RUN) 2> perf_report.txt
@echo "Perf counters written to perf_report.txt"
## Remove build artifacts
clean:
-$(RM) $(OUT) benchmark_results.csv cachegrind.out cachegrind_report.txt perf_report.txt
help:
@echo "Targets:"
@echo " make — build with AVX2"
@echo " make nosimd — build without AVX2"
@echo " make run — build and run benchmark"
@echo " make cachegrind — Valgrind cache profiling (Linux)"
@echo " make perf — perf hardware counters (Linux)"
@echo " make clean — remove artifacts"