Add LICENSE
[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 default: all
8
9 bmarkdir = .
10
11 instname = riscv-bmarks
12 instbasedir = $(UCB_VLSI_HOME)/install
13
14 #--------------------------------------------------------------------
15 # Sources
16 #--------------------------------------------------------------------
17
18 bmarks = \
19 median \
20 qsort \
21 rsort \
22 towers \
23 vvadd \
24 multiply \
25 mm \
26 dhrystone \
27 spmv \
28 mt-vvadd \
29 mt-matmul \
30 #vec-fft \
31 #vec-vvadd \
32 #vec-cmplxmult \
33 #vec-matmul \
34
35 bmarks_host = \
36 median \
37 qsort \
38 towers \
39 vvadd \
40 multiply \
41 spmv \
42 vec-vvadd \
43 vec-cmplxmult \
44 vec-matmul \
45
46 #--------------------------------------------------------------------
47 # Build rules
48 #--------------------------------------------------------------------
49
50 HOST_OPTS = -std=gnu99 -DPREALLOCATE=0 -DHOST_DEBUG=1
51 HOST_COMP = gcc $(HOST_OPTS)
52
53 RISCV_PREFIX=riscv64-unknown-elf-
54 RISCV_GCC = $(RISCV_PREFIX)gcc
55 RISCV_GCC_OPTS = -static -Wa,-march=RVIMAFDXhwacha -std=gnu99 -O2 -ffast-math
56 RISCV_LINK = $(RISCV_GCC) -T $(bmarkdir)/common/test.ld $(incs)
57 RISCV_LINK_MT = $(RISCV_GCC) -T $(bmarkdir)/common/test-mt.ld
58 RISCV_LINK_OPTS = -nostdlib -nostartfiles -ffast-math -lc
59 RISCV_OBJDUMP = $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
60 RISCV_SIM = spike
61
62 VPATH += $(addprefix $(bmarkdir)/, $(bmarks))
63 VPATH += $(bmarkdir)/common
64
65 incs += -I$(bmarkdir)/../env -I$(bmarkdir)/common $(addprefix -I$(bmarkdir)/, $(bmarks))
66 objs :=
67
68 include $(patsubst %, $(bmarkdir)/%/bmark.mk, $(bmarks))
69
70 #------------------------------------------------------------
71 # Build and run benchmarks on riscv simulator
72
73 bmarks_riscv_bin = $(addsuffix .riscv, $(bmarks))
74 bmarks_riscv_dump = $(addsuffix .riscv.dump, $(bmarks))
75 bmarks_riscv_hex = $(addsuffix .riscv.hex, $(bmarks))
76 bmarks_riscv_out = $(addsuffix .riscv.out, $(bmarks))
77
78 bmarks_defs = -DPREALLOCATE=1 -DHOST_DEBUG=0
79 bmarks_cycles = 80000
80
81 %.hex: %
82 elf2hex 16 32768 $< > $@
83
84 $(bmarks_riscv_dump): %.riscv.dump: %.riscv
85 $(RISCV_OBJDUMP) $< > $@
86
87 $(bmarks_riscv_out): %.riscv.out: %.riscv
88 $(RISCV_SIM) $< > $@
89
90 %.o: %.c
91 $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) \
92 -c $(incs) $< -o $@
93
94 %.o: %.S
95 $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) -D__ASSEMBLY__=1 \
96 -c $(incs) $< -o $@
97
98 riscv: $(bmarks_riscv_dump) $(bmarks_riscv_hex)
99 run-riscv: $(bmarks_riscv_out)
100 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
101 $(bmarks_riscv_out); echo;
102
103 junk += $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(bmarks_riscv_hex) $(bmarks_riscv_out)
104
105 #------------------------------------------------------------
106 # Build and run benchmarks on host machine
107
108 bmarks_host_bin = $(addsuffix .host, $(bmarks_host))
109 bmarks_host_out = $(addsuffix .host.out, $(bmarks_host))
110
111 $(bmarks_host_out): %.host.out: %.host
112 ./$< > $@
113
114 host: $(bmarks_host_bin)
115 run-host: $(bmarks_host_out)
116 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
117 $(bmarks_host_out); echo;
118
119 junk += $(bmarks_host_bin) $(bmarks_host_out)
120
121 #------------------------------------------------------------
122 # Default
123
124 all: riscv
125
126 #------------------------------------------------------------
127 # Install
128
129 date_suffix = $(shell date +%Y-%m-%d_%H-%M)
130 install_dir = $(instbasedir)/$(instname)-$(date_suffix)
131 latest_install = $(shell ls -1 -d $(instbasedir)/$(instname)* | tail -n 1)
132
133 install:
134 mkdir $(install_dir)
135 cp -r $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(install_dir)
136
137 install-link:
138 rm -rf $(instbasedir)/$(instname)
139 ln -s $(latest_install) $(instbasedir)/$(instname)
140
141 #------------------------------------------------------------
142 # Clean up
143
144 clean:
145 rm -rf $(objs) $(junk)