-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
378 lines (316 loc) · 11.1 KB
/
Makefile
File metadata and controls
378 lines (316 loc) · 11.1 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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# Copyright (C) 2023-2024 ETH Zurich and University of Bologna
#
# Licensed under the Solderpad Hardware License, Version 0.51
# (the "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier: SHL-0.51
#
# Authors: Yvan Tortorella <yvan.tortorella@unibo.it>
# Victor Isachi <victor.isachi@unibo.it>
#
# MAGIA Makefile
# Paths to folders
ROOT_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
core ?= CV32E40X
MAGIA_DIR ?= $(shell pwd)
SW ?= sw
BUILD_DIR ?= sim/work
ifneq (,$(wildcard /etc/iis.version))
QUESTA ?= questa-2025.1
BENDER ?= bender
BASE_PYTHON ?= python
else
QUESTA ?=
BENDER ?= ./bender
BASE_PYTHON ?= python3
endif
BENDER_DIR ?= .
ISA ?= riscv
ARCH ?= rv
XLEN ?= 32
ifeq ($(core), CV32E40X)
XTEN = imafc
else
XTEN = imfcxpulpv2
endif
ABI ?= ilp
XABI ?= f
#ifeq ($(REDMULE_COMPLEX),1)
# TEST_SRCS := sw/redmule_complex.c
#else
# TEST_SRCS := sw/redmule.c
#endif
TEST_DIR := sw/tests
TEST_SRCS = $(TEST_DIR)/$(test).c
compile_script ?= scripts/compile.tcl
compile_script_synth ?= scripts/synth_compile.tcl
compile_flag ?= -suppress 2583 -suppress 13314 -suppress 3009
questa_compile_flag += -t 1ns -suppress 3009
questa_opt_flag += -suppress 3009 -debugdb +acc
questa_opt_fast_flag += -suppress 3009
questa_run_flag += -t 1ns -debugDB -suppress 3009
questa_run_fast_flag += -t 1ns -suppress 3009
INI_PATH = sim/modelsim.ini
WORK_PATH = $(BUILD_DIR)
# Useful Parameters
gui ?= 0
ipstools ?= 0
inst_hex_name ?= build/stim_instr.txt
data_hex_name ?= build/stim_data.txt
inst_entry ?= 0xCC000000
data_entry ?= 0xCC010000
boot_addr ?= 0xCC000080
test ?= hello_world
mesh_dv ?= 1
fast_sim ?= 0
# Add here a path to the core traces of each tile you want to monitor
num_cores ?= 16
$(foreach i, $(shell seq 0 $(shell echo $$(($(num_cores)-1)))), \
$(eval log_path_$(i) := ./core_$(i)_traces.log) \
)
itb_file ?= build/verif.itb
ifeq ($(verbose),1)
FLAGS += -DVERBOSE
endif
ifeq ($(debug),1)
FLAGS += -DDEBUG
endif
ifeq ($(core), CV32E40X)
FLAGS += -DCV32E40X
endif
# Include directories
INC += -Isw
INC += -Isw/inc
INC += -Isw/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=$(ABI)$(XLEN)$(XABI) -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=$(ABI)$(XLEN)$(XABI) -D__$(ISA)__ -MMD -MP -nostartfiles -nostdlib -Wl,--gc-sections
# Setup build object dirs
CRT=$(TEST_DIR)/$(test)/build/crt0.o
OBJ=$(TEST_DIR)/$(test)/build/verif.o
BIN=$(TEST_DIR)/$(test)/build/verif
DUMP=$(TEST_DIR)/$(test)/build/verif.dump
ODUMP=$(TEST_DIR)/$(test)/build/verif.objdump
ITB=$(TEST_DIR)/$(test)/build/verif.itb
STIM_INSTR=$(TEST_DIR)/$(test)/build/stim_instr.txt
STIM_DATA=$(TEST_DIR)/$(test)/build/stim_data.txt
VSIM_INI=modelsim.ini
VSIM_LIBS=work
# 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 && \
$(BASE_PYTHON) scripts/s19tomem.py $(BIN).txt $(STIM_INSTR) $(STIM_DATA)
cd $(TEST_DIR)/$(test) && \
ln -sfn $(ROOT_DIR)/$(INI_PATH) $(VSIM_INI) && \
ln -sfn $(ROOT_DIR)/$(WORK_PATH) $(VSIM_LIBS)
$(BIN): $(CRT) $(OBJ)
$(LD) $(LD_OPTS) -o $(BIN) $(CRT) $(OBJ) -T$(LINKSCRIPT)
$(CRT):
cd $(TEST_DIR) && \
mkdir -p $(test) && \
cd $(test) && \
mkdir -p build
$(CC) $(CC_OPTS) -c $(BOOTSCRIPT) -o $(CRT)
$(OBJ):
cd $(TEST_DIR) && \
mkdir -p $(test) && \
cd $(test) && \
mkdir -p build
$(CC) $(CC_OPTS) -c $(TEST_SRCS) $(FLAGS) $(INC) -o $(OBJ)
SHELL := /bin/bash
# Parameters used by the iDMA hardware build
IDMA_ROOT ?= $(shell $(BENDER) path idma)
IDMA_ADD_IDS ?= rw_axi_rw_obi
# Parameters used for FlooNoC
FLOONOC_ROOT ?= $(shell $(BENDER) path floo_noc)
.PHONY: python_venv python_deps
python_venv:
$(BASE_PYTHON) -m venv magia_venv
python_deps:
$(BASE_PYTHON) -m pip install --upgrade pip setuptools && \
$(BASE_PYTHON) -m pip install -r requirements.txt
# Generate instructions and data stimuli
all: $(STIM_INSTR) $(STIM_DATA) dis objdump itb
# Run the simulation
run: $(CRT)
ifeq ($(gui), 0)
cd $(TEST_DIR)/$(test); \
$(QUESTA) vsim -c vopt_tb $(questa_run_fast_flag) -l transcript -do "run -a" \
+INST_HEX=$(inst_hex_name) \
+DATA_HEX=$(data_hex_name) \
+INST_ENTRY=$(inst_entry) \
+DATA_ENTRY=$(data_entry) \
+BOOT_ADDR=$(boot_addr) \
$(foreach i, $(shell seq 0 $(shell echo $$(($(num_cores)-1)))), \
+log_file_$(i)=$(log_path_$(i)) \
) \
+itb_file=$(itb_file)
else
cd $(TEST_DIR)/$(test); \
$(QUESTA) vsim vopt_tb $(questa_run_flag) -l transcript \
-do "add log -r sim:/$(tb)/*" \
-do "source $(WAVES)" \
+INST_HEX=$(inst_hex_name) \
+DATA_HEX=$(data_hex_name) \
+INST_ENTRY=$(inst_entry) \
+DATA_ENTRY=$(data_entry) \
+BOOT_ADDR=$(boot_addr) \
$(foreach i, $(shell seq 0 $(shell echo $$(($(num_cores)-1)))), \
+log_file_$(i)=$(log_path_$(i)) \
) \
+itb_file=$(itb_file)
endif
# Download bender
bender:
curl --proto '=https' \
--tlsv1.2 https://pulp-platform.github.io/bender/init -sSf | sh -s -- 0.28.1 \
export PATH=$(pwd):$(PATH)
include bender_common.mk
include bender_sim.mk
include bender_synth.mk
include bender_profile.mk
ifeq ($(core), CV32E40X)
bender_defs += -D COREV_ASSERT_OFF
endif
ifeq ($(core), CV32E40X)
bender_defs += -D CV32E40X
else ifeq ($(core), CV32E40P)
bender_defs += -D CV32E40P
else
$(error Detected unsupported core, must choose among CV32E40X and CV32E40P)
endif
bender_targs += -t rtl
bender_targs += -t test
bender_targs += -t cv32e40p_include_tracer
# Targets needed to avoid error even though the module is not used
bender_targs += -t snitch_cluster
bender_targs += -t idma_test
#ifeq ($(REDMULE_COMPLEX),1)
# tb := redmule_complex_tb
# WAVES := $(mkfile_path)/wave_complex_xif.do
# bender_targs += -t redmule_complex
#else
# tb := redmule_tb
# WAVES := $(mkfile_path)/wave.do
# bender_targs += -t redmule_hwpe
#endif
ifeq ($(mesh_dv),1)
tb := magia_tb
else
tb := magia_tile_tb
endif
WAVES := $(mkfile_path)/wave.do
ifeq ($(core), CV32E40X)
bender_targs += -t redmule_complex
bender_targs += -t cv32e40x_bhv
else
bender_targs += -t redmule_hwpe
endif
update-ips:
$(BENDER) update
$(BENDER) script vsim \
--vlog-arg="$(compile_flag)" \
--vcom-arg="-pedanticerrors" \
$(bender_targs) $(bender_defs) \
$(sim_targs) $(sim_deps) \
> ${compile_script}
vsim-scripts:
$(BENDER) script vsim \
--vlog-arg="$(compile_flag)" \
--vcom-arg="-pedanticerrors" \
$(bender_targs) $(bender_defs) \
$(sim_targs) $(sim_deps) \
> ${compile_script}
synth-ips:
$(BENDER) update
$(MAKE) -C $(IDMA_ROOT) idma_hw_all IDMA_ADD_IDS=$(IDMA_ADD_IDS)
$(BENDER) script synopsys \
$(common_targs) $(common_defs) \
$(synth_targs) $(synth_defs) \
> ${compile_script_synth}
profile-ips:
$(BENDER) update
$(BENDER) script vsim \
--vlog-arg="$(compile_flag)" \
--vcom-arg="-pedanticerrors" \
$(bender_targs) $(bender_defs) \
$(profile_targs) $(profile_defs) \
> ${compile_script}
floonoc-patch:
cd $(FLOONOC_ROOT) && \
git apply ../../../../floonoc.patch && \
cd ../../../../
build-hw: hw-all
sdk:
cd $(SW); \
git clone \
git@github.com:pulp-platform/pulp-sdk.git
clean-sdk:
rm -rf $(SW)/pulp-sdk
clean:
rm -rf $(TEST_DIR)/$(test)
dis:
$(OBJDUMP) -d -S $(BIN) > $(DUMP)
objdump:
$(OBJDUMP) -d -l -s $(BIN) > $(ODUMP)
itb:
$(BASE_PYTHON) scripts/objdump2itb.py $(ODUMP) > $(ITB)
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
# Hardware rules
hw-clean-all:
rm -rf $(BUILD_DIR)
rm -rf .bender
rm -rf $(compile_script)
rm -rf sim/modelsim.ini
rm -rf .cached_ipdb.json
hw-opt:
ifeq ($(fast_sim), 0)
$(QUESTA) vopt $(questa_opt_flag) -o vopt_tb $(tb) -floatparameters+$(tb) -work $(BUILD_DIR)
else
$(QUESTA) vopt $(questa_opt_fast_flag) -o vopt_tb $(tb) -floatparameters+$(tb) -work $(BUILD_DIR)
endif
hw-compile:
$(MAKE) -C $(IDMA_ROOT) idma_hw_all IDMA_ADD_IDS=$(IDMA_ADD_IDS)
$(QUESTA) vsim $(questa_compile_flag) -c -l sim/compile.log +incdir+$(UVM_HOME) -do 'quit -code [source $(compile_script)]'
hw-lib:
cd sim && \
touch modelsim.ini && \
mkdir -p work
$(QUESTA) vlib $(BUILD_DIR)
$(QUESTA) vmap work $(BUILD_DIR)
chmod +w $(INI_PATH)
hw-clean:
rm -rf $(INI_PATH) $(BUILD_DIR)
hw-all: hw-clean hw-lib hw-compile hw-opt
# Nonfree components
MAGIA_NONFREE_REMOTE ?= git@iis-git.ee.ethz.ch:pulp-restricted/magia-nonfree
MAGIA_NONFREE_DIR ?= nonfree
MAGIA_NONFREE_COMMIT ?= v0.1
.PHONY: magia-nonfree-init
MAGIA_NONFREE_DEPS ?= 1
magia-nonfree-init:
git clone $(MAGIA_NONFREE_REMOTE) $(MAGIA_NONFREE_DIR)
cd $(MAGIA_NONFREE_DIR) && git checkout $(MAGIA_NONFREE_COMMIT)
if [ "$(MAGIA_NONFREE_DEPS)" -eq "1" ]; then $(MAKE) nonfree-init-dep ; fi
-include $(MAGIA_NONFREE_DIR)/nonfree.mk