Clean up benchmarks build
[riscv-tests.git] / benchmarks / Makefile
1 #=======================================================================
2 # UCB VLSI FLOW: Makefile for riscv-bmarks
3 #-----------------------------------------------------------------------
4 # Yunsup Lee (yunsup@cs.berkeley.edu)
5 #
6
7 XLEN ?= 64
8
9 default: all
10
11 src_dir = .
12
13 instname = riscv-bmarks
14 instbasedir = $(UCB_VLSI_HOME)/install
15
16 #--------------------------------------------------------------------
17 # Sources
18 #--------------------------------------------------------------------
19
20 bmarks = \
21 median \
22 qsort \
23 rsort \
24 towers \
25 vvadd \
26 multiply \
27 mm \
28 dhrystone \
29 spmv \
30 mt-vvadd \
31 mt-matmul \
32
33 #--------------------------------------------------------------------
34 # Build rules
35 #--------------------------------------------------------------------
36
37 RISCV_PREFIX ?= riscv$(XLEN)-unknown-elf-
38 RISCV_GCC ?= $(RISCV_PREFIX)gcc
39 RISCV_GCC_OPTS ?= -DPREALLOCATE=1 -mcmodel=medany -static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf
40 RISCV_LINK ?= $(RISCV_GCC) -T $(src_dir)/common/test.ld $(incs)
41 RISCV_LINK_OPTS ?= -static -nostdlib -nostartfiles -lgcc -T $(src_dir)/common/test.ld
42 RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
43 RISCV_SIM ?= spike --isa=rv$(XLEN)gc
44
45 incs += -I$(src_dir)/../env -I$(src_dir)/common $(addprefix -I$(src_dir)/, $(bmarks))
46 objs :=
47
48 define compile_template
49 $(1).riscv: $(wildcard $(src_dir)/$(1)/*) $(wildcard $(src_dir)/common/*)
50 $$(RISCV_GCC) $$(incs) $$(RISCV_GCC_OPTS) $$(RISCV_LINK_OPTS) -o $$@ $(wildcard $(src_dir)/$(1)/*.c) $(wildcard $(src_dir)/common/*.c) $(wildcard $(src_dir)/common/*.S)
51 endef
52
53 $(foreach bmark,$(bmarks),$(eval $(call compile_template,$(bmark))))
54
55 #------------------------------------------------------------
56 # Build and run benchmarks on riscv simulator
57
58 bmarks_riscv_bin = $(addsuffix .riscv, $(bmarks))
59 bmarks_riscv_dump = $(addsuffix .riscv.dump, $(bmarks))
60 bmarks_riscv_out = $(addsuffix .riscv.out, $(bmarks))
61
62 $(bmarks_riscv_dump): %.riscv.dump: %.riscv
63 $(RISCV_OBJDUMP) $< > $@
64
65 $(bmarks_riscv_out): %.riscv.out: %.riscv
66 $(RISCV_SIM) $< > $@
67
68 riscv: $(bmarks_riscv_dump)
69 run: $(bmarks_riscv_out)
70
71 junk += $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(bmarks_riscv_hex) $(bmarks_riscv_out)
72
73 #------------------------------------------------------------
74 # Default
75
76 all: riscv
77
78 #------------------------------------------------------------
79 # Install
80
81 date_suffix = $(shell date +%Y-%m-%d_%H-%M)
82 install_dir = $(instbasedir)/$(instname)-$(date_suffix)
83 latest_install = $(shell ls -1 -d $(instbasedir)/$(instname)* | tail -n 1)
84
85 install:
86 mkdir $(install_dir)
87 cp -r $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(install_dir)
88
89 install-link:
90 rm -rf $(instbasedir)/$(instname)
91 ln -s $(latest_install) $(instbasedir)/$(instname)
92
93 #------------------------------------------------------------
94 # Clean up
95
96 clean:
97 rm -rf $(objs) $(junk)