forked from pulp-platform/redmule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
185 lines (149 loc) · 4.33 KB
/
Makefile
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Copyright 2023 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Yvan Tortorella <yvan.tortorella@unibo.it>
#
# Top-level Makefile
# Paths to folders
mkfile_path := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
SW ?= $(mkfile_path)sw
BUILD_DIR ?= $(SW)/build
VSIM_DIR ?= $(mkfile_path)vsim
QUESTA ?=
BENDER_DIR ?= .
BENDER ?= bender
ISA ?= riscv
ARCH ?= rv
XLEN ?= 32
XTEN ?= imc
ifeq ($(REDMULE_COMPLEX),1)
TEST_SRCS := $(SW)/redmule_complex.c
else
TEST_SRCS := $(SW)/redmule.c
endif
compile_script ?= $(mkfile_path)scripts/compile.tcl
compile_script_synth ?= $(mkfile_path)scripts/synth_compile.tcl
compile_flag ?= +acc -permissive -suppress 2583 -suppress 13314
INI_PATH = $(mkfile_path)modelsim.ini
WORK_PATH = $(VSIM_DIR)/work
# Useful Parameters
gui ?= 0
ipstools ?= 0
P_STALL ?= 0.0
ifeq ($(verbose),1)
FLAGS += -DVERBOSE
endif
ifeq ($(debug),1)
FLAGS += -DDEBUG
endif
# Include directories
INC += -I$(SW)
INC += -I$(SW)/inc
INC += -I$(SW)/utils
BOOTSCRIPT := $(SW)/kernel/crt0.S
LINKSCRIPT := $(SW)/kernel/link.ld
CC=$(ISA)$(XLEN)-unknown-elf-gcc
LD=$(CC)
OBJDUMP=$(ISA)$(XLEN)-unknown-elf-objdump
CC_OPTS=-march=$(ARCH)$(XLEN)$(XTEN) -mabi=ilp32 -D__$(ISA)__ -O2 -g -Wextra -Wall -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wundef -fdata-sections -ffunction-sections -MMD -MP
LD_OPTS=-march=$(ARCH)$(XLEN)$(XTEN) -mabi=ilp32 -D__$(ISA)__ -MMD -MP -nostartfiles -nostdlib -Wl,--gc-sections
# Setup build object dirs
CRT=$(BUILD_DIR)/crt0.o
OBJ=$(BUILD_DIR)/verif.o
BIN=$(BUILD_DIR)/verif
DUMP=$(BUILD_DIR)/verif.dump
STIM_INSTR=$(VSIM_DIR)/stim_instr.txt
STIM_DATA=$(VSIM_DIR)/stim_data.txt
# Build implicit rules
$(STIM_INSTR) $(STIM_DATA): $(BIN)
objcopy --srec-len 1 --output-target=srec $(BIN) $(BIN).s19
scripts/parse_s19.pl $(BIN).s19 > $(BIN).txt
python scripts/s19tomem.py $(BIN).txt $(STIM_INSTR) $(STIM_DATA)
$(BIN): $(CRT) $(OBJ)
$(LD) $(LD_OPTS) -o $(BIN) $(CRT) $(OBJ) -T$(LINKSCRIPT)
$(CRT): $(BUILD_DIR)
$(CC) $(CC_OPTS) -c $(BOOTSCRIPT) -o $(CRT)
$(OBJ): $(TEST_SRCS)
$(CC) $(CC_OPTS) -c $(TEST_SRCS) $(FLAGS) $(INC) -o $(OBJ)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
SHELL := /bin/bash
# Generate instructions and data stimuli
sw-build: $(STIM_INSTR) $(STIM_DATA) dis
# Run the simulation
run: $(CRT)
ifeq ($(gui), 0)
cd $(VSIM_DIR); \
$(QUESTA) vsim -c $(tb)_opt \
-do "run -a" \
-gSTIM_INSTR=$(STIM_INSTR) \
-gSTIM_DATA=$(STIM_DATA) \
-gPROB_STALL=$(P_STALL) \
-suppress vsim-3009 \
-suppress vsim-12003
else
cd $(VSIM_DIR); \
$(QUESTA) vsim $(tb)_opt \
-do "set Testbench $(tb)" \
-do "log -r /*" \
-do "source $(WAVES)" \
-gSTIM_INSTR=$(STIM_INSTR) \
-gSTIM_DATA=$(STIM_DATA) \
-gPROB_STALL=$(P_STALL) \
-suppress vsim-3009 \
-suppress vsim-12003
endif
# Download bender
bender:
curl --proto '=https' \
--tlsv1.2 https://pulp-platform.github.io/bender/init -sSf | sh -s -- 0.24.0
include bender_common.mk
include bender_sim.mk
include bender_synth.mk
WAVES := $(mkfile_path)scripts/wave.tcl
ifeq ($(REDMULE_COMPLEX),1)
tb := redmule_complex_tb
else
tb := redmule_tb
endif
$(VSIM_DIR):
mkdir -p $(VSIM_DIR)
update-ips: $(VSIM_DIR)
$(BENDER) update
$(BENDER) script vsim \
--vlog-arg="$(compile_flag)" \
--vcom-arg="-pedanticerrors" \
$(common_targs) $(common_defs) \
$(sim_targs) \
> ${compile_script}
echo 'vopt $(compile_flag) $(tb) -o $(tb)_opt' >> ${compile_script}
synth-ips:
$(BENDER) update
$(BENDER) script synopsys \
$(common_targs) $(common_defs) \
$(synth_targs) $(synth_defs) \
> ${compile_script_synth}
sw-clean:
rm -rf $(BUILD_DIR)
hw-clean:
rm -rf $(VSIM_DIR)
dis:
$(OBJDUMP) -d $(BIN) > $(DUMP)
OP ?= gemm
fp_fmt ?= FP16
M ?= 12
N ?= 16
K ?= 16
golden: golden-clean
$(MAKE) -C golden-model $(OP) SW=$(SW)/inc M=$(M) N=$(N) K=$(K) fp_fmt=$(fp_fmt)
golden-clean:
$(MAKE) -C golden-model golden-clean
clean-all: hw-clean sw-clean
rm -rf $(mkfile_path).bender
rm -rf $(compile_script)
hw-build: $(VSIM_DIR)
cd $(VSIM_DIR); \
$(QUESTA) vsim -c -do 'quit -code [source $(compile_script)]'
sw-all: sw-clean sw-build
hw-all: hw-clean hw-build