-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
330 lines (302 loc) · 13.1 KB
/
Copy pathMakefile
File metadata and controls
330 lines (302 loc) · 13.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
# Copyright (C) 2025 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: Victor Isachi <victor.isachi@unibo.it>
# Alberto Dequino <alberto.dequino@unibo.it>
#
# Magia-sdk Makefile
SHELL := /bin/bash
include scripts/deps.env
CURR_DIR ?= $(shell pwd)
CMAKE_BUILDDIR ?= $(CURR_DIR)/build
MAGIA_RTL_DIR ?= ..
BUILD_DIR ?= $(MAGIA_RTL_DIR)/sw/tests/$(test)
MAGIA_DIR_ABS ?= $(abspath $(MAGIA_RTL_DIR))
BUILD_DIR_ABS ?= $(MAGIA_DIR_ABS)/sw/tests/$(test)
GVSOC_DIR ?= ./gvsoc
GVSOC_ABS_PATH ?= $(CURR_DIR)/gvsoc
BIN_ABS_PATH ?= $(CMAKE_BUILDDIR)/bin
BIN ?= $(BUILD_DIR)/build/verif
build_mode ?= update
fsync_mode ?= stall
mesh_dv ?= 1
fast_sim ?= 0
eval ?= 0
stalling ?= 0
fsync_mm ?= 1
idma_mm ?= 1
redmule_mm ?= 1
profile_cmp ?= 0
profile_cmi ?= 0
profile_cmo ?= 0
profile_snc ?= 0
target_platform ?= magia_v2
compiler ?= GCC_PULP
ifeq ($(target_platform), magia_v2)
ISA ?= rv32imcxgap9
else
ISA ?= rv32imac
endif
gui ?= 0
tiles ?= 2
spatz ?= 1
verbose ?= 0
LLVM_CMAKE ?= cmake
LLVM_DIR ?= llvm
LLVM_REPO ?= git@github.com:pulp-platform/llvm-project.git
LLVM_COMMIT ?= b494f2d8dde88723026db8ec16ac6c7ee1e140ca
LLVM_INSTALL_DIR ?= $(CURR_DIR)/llvm/install
LLVM_BUILD_DIR ?= $(LLVM_DIR)/llvm-project/build
LLVM_JOBS ?= 8
tiles_2 := $(shell echo $$(( $(tiles) * $(tiles) )))
tiles_log := $(shell awk 'BEGIN { printf "%.0f", log($(tiles_2))/log(2) }')
tiles_log_real := $(shell awk 'BEGIN { printf "%.0f", log($(tiles))/log(2) }')
GVRUN ?= $(GVSOC_DIR)/install/bin/gvrun
CMAKE ?= cmake
GVSOC_WORK_DIR ?= ./gvsoc_work
GVRUN_COMMON_ARGS ?= --work-dir $(GVSOC_WORK_DIR) --attr magia_v2/n_tiles_x=$(tiles) --attr magia_v2/n_tiles_y=$(tiles) --attr magia_v2/spatz_romfile=$(BIN_ABS_PATH)/bootrom/spatz_init.bin --trace-level=trace --trace=kill-module
GVRUN_ARGS ?= $(GVRUN_COMMON_ARGS) run
GVRUN_PROFILE_ARGS ?= $(GVRUN_COMMON_ARGS) --vcd --event=.* run
profile_tile ?=
PROFILE_TILE_ARG = $(if $(profile_tile),--trace=tile-$(profile_tile)-idma-ctrl-mm,)
gvsoc_trace ?= 0
GVSOC_TRACE_IDS = $(shell seq 0 $$(( $(tiles_2) - 1 )))
# NB: the trace file path is resolved relative to the GVSoC work-dir (like all.vcd), so it is a bare filename.
GVSOC_TRACE_ARG = $(if $(filter 1,$(gvsoc_trace)),$(foreach t,$(GVSOC_TRACE_IDS),--trace='tile-$(t)-cv32-core/insn:cv32_trace_tile$(t).log'),)
# GVSOC VCD to Perfetto converter scripts (Python version kept but unused currently)
GVSOC2PERFETTO_SCRIPT ?= scripts/gvsoc2perfetto.py
GVSOC2PERFETTO_DIR ?= scripts/gvsoc2perfetto-rs
GVSOC2PERFETTO_BIN ?= $(GVSOC2PERFETTO_DIR)/target/release/gvsoc2perfetto
GVSOC2PERFETTO_VCD ?= $(GVSOC_WORK_DIR)/all.vcd
GVSOC2PERFETTO_OUT ?= $(GVSOC_WORK_DIR)/trace.perfetto-trace
# Per-tile: CV32E40P core, light_redmule, both idma ports (frontend descriptor
# fields + real me_state/be_state FSM), Snitch+Spatz (scalar core + Spatz/ara
# vector unit). Chip-level: NoC mesh routers/network-interfaces, L2 traffic.
GVSOC2PERFETTO_INCLUDE ?= (?x) \
tile-\d+-cv32-core\.(busy|asm|func|active_pc)$$ \
| tile-\d+-redmule\.(busy|fsm_state)$$ \
| tile-\d+-idma[01]\.(fe\.do_transfer_grant|me\.me_state|be\.be_state)$$ \
| tile-\d+-snitch-spatz\.(busy|asm|func|active_pc)$$ \
| tile-\d+-snitch-spatz\.ara\.(active|label)$$ \
| tile-\d+-snitch-spatz\.ara\.(vfpu|vlsu|vslide)\.(active|label)$$ \
| magia-noc\.(req|rsp|wide)_router_\d+_\d+\.(stalled_queue_\w+|req_is_write)$$ \
| magia-noc\.(req|rsp|wide)_router_\d+_\d+\.req(_size)?$$ \
| magia-noc\.ni_\d+_\d+\.(narrow_req|wide_req)$$ \
| L2-mem\.(req_addr|req_size|req_is_write)$$
.PHONY: gvsoc build format run_profiling gvsoc2perfetto
# Build the Rust VCD->Perfetto converter (cargo tracks its own incremental state).
gvsoc2perfetto: $(GVSOC2PERFETTO_BIN)
$(GVSOC2PERFETTO_BIN): $(GVSOC2PERFETTO_DIR)/src/main.rs $(GVSOC2PERFETTO_DIR)/Cargo.toml $(GVSOC2PERFETTO_DIR)/Cargo.lock
cargo build --release --manifest-path $(GVSOC2PERFETTO_DIR)/Cargo.toml
format:
@bash scripts/ci/format-changed.sh apply
clean:
rm -rf build/
rtl-clean:
cd $(MAGIA_RTL_DIR) && \
make hw-clean-all
rm -rf $(MAGIA_RTL_DIR)/sw/tests/test_*
build:
ifeq ($(tiles), )
$(error tiles is empty!)
endif
@t=./targets/$(target_platform)/include/addr_map/tile_config.h; \
printf '// Auto-generated by `make build tiles=N` -- do not edit by hand.\n// Default: 2x2 mesh. Regenerate with: make build tiles=<N>\n#define MESH_X_TILES %d\n#define MESH_Y_TILES %d\n#define MAX_SYNC_LVL %d\n#define MESH_2_POWER %d\n' $(tiles) $(tiles) $(tiles_log) $(tiles_log_real) > $$t.tmp; \
if cmp -s $$t.tmp $$t; then rm -f $$t.tmp; else mv $$t.tmp $$t; echo "Regenerated $$t"; fi
ifeq ($(compiler), LLVM)
$(error COMING SOON!)
endif
$(CMAKE) -DTARGET_PLATFORM=$(target_platform) -DTILES=$(tiles) -DEVAL=$(eval) -DSTALLING=$(stalling) -DFSYNC_MM=$(fsync_mm) -DIDMA_MM=$(idma_mm) -DREDMULE_MM=$(redmule_mm) -DCOMPILER=$(compiler) -DPROFILE_CMP=$(profile_cmp) -DPROFILE_CMI=$(profile_cmi) -DPROFILE_CMO=$(profile_cmo) -DPROFILE_SNC=$(profile_snc) -DSPATZ_TESTS=$(spatz) -B $(CMAKE_BUILDDIR) $(if $(filter 1,$(verbose)),--trace-expand,)
$(CMAKE) --build $(CMAKE_BUILDDIR) $(if $(filter 1,$(verbose)),--verbose,) $(if $(test),--target $(test),) -- --no-print-directory
set_mesh:
ifeq ($(tiles), 1)
$(eval mesh_dv=0)
endif
$(GVSOC_WORK_DIR):
mkdir -p $(GVSOC_WORK_DIR)
run: set_mesh $(GVSOC_WORK_DIR)
@echo 'Magia is available at https://github.com/pulp-platform/MAGIA.git'
@echo 'please run "source setup_env.sh" in the magia folder before running this script'
@echo 'and make sure the risc-v objdump binary is visible on path using "which riscv32-unknown-elf-objdump".'
ifndef test
$(error Proper formatting is: make run test=<test_name> platform=rtl|gvsoc)
endif
ifeq (,$(wildcard $(CMAKE_BUILDDIR)/bin/$(test)))
$(error No test found with name: $(test))
endif
ifndef platform
$(error Proper formatting is: make run test=<test_name> platform=rtl|gvsoc)
endif
ifeq ($(platform), gvsoc)
$(GVRUN) --target magia_v2 --param binary=$(BIN_ABS_PATH)/$(test) $(GVRUN_ARGS)
else ifeq ($(platform), rtl)
mkdir -p $(BUILD_DIR_ABS) && cd $(BUILD_DIR_ABS) && mkdir -p build
cp ./build/bin/$(test) $(BUILD_DIR_ABS)/build/verif
objcopy --srec-len 1 --output-target=srec $(BIN) $(BIN).s19
scripts/parse_s19.pl $(BIN).s19 > $(BIN).txt
python3 scripts/s19tomem.py $(BIN).txt $(BUILD_DIR_ABS)/build/stim_instr.txt $(BUILD_DIR_ABS)/build/stim_data.txt
cd $(BUILD_DIR_ABS) && \
cp -sf "$(MAGIA_DIR_ABS)/sim/modelsim.ini" modelsim.ini && \
ln -sfn "$(MAGIA_DIR_ABS)/sim/work" work
riscv32-unknown-elf-objdump -d -S -Mmarch=$(ISA) $(BIN) > $(BIN).dump
riscv32-unknown-elf-objdump -d -l -s -Mmarch=$(ISA) $(BIN) > $(BIN).objdump
python3 scripts/objdump2itb.py $(BIN).objdump > $(BIN).itb
cd $(MAGIA_RTL_DIR) && \
make run test=$(test) gui=$(gui) mesh_dv=$(mesh_dv)
else
$(error Only rtl and gvsoc are supported as platforms.)
endif
run_profiling: set_mesh $(GVSOC_WORK_DIR) $(GVSOC2PERFETTO_BIN)
ifndef test
$(error Proper formatting is: make run_profiling test=<test_name>)
endif
ifeq (,$(wildcard $(CMAKE_BUILDDIR)/bin/$(test)))
$(error No test found with name: $(test))
endif
$(GVRUN) --target magia_v2 --param binary=$(BIN_ABS_PATH)/$(test) $(GVRUN_PROFILE_ARGS) $(PROFILE_TILE_ARG) $(GVSOC_TRACE_ARG)
$(GVSOC2PERFETTO_BIN) $(GVSOC2PERFETTO_VCD) \
-o $(GVSOC2PERFETTO_OUT) \
--state-map 'fsm_state=0:idle,1:preload,2:routine,3:storing,4:finished,5:acknowledge' \
--state-map 'me_state=0:idle,1:decomposing' \
--state-map 'be_state=0:idle,1:active' \
--rename 'ara=vfu' \
--rename 'label=instructions' \
--rename 'active_pc=pc' \
--split-asm \
--symbolize $(CMAKE_BUILDDIR)/bin/$(test).s \
--stats \
--include '$(GVSOC2PERFETTO_INCLUDE)'
rm -f -- $(GVSOC2PERFETTO_VCD)
debug_profiling: $(GVSOC_WORK_DIR) $(GVSOC2PERFETTO_BIN)
ifndef test
$(error Proper formatting is: make debug_profiling test=<test_name>)
endif
$(GVSOC2PERFETTO_BIN) $(GVSOC2PERFETTO_VCD) \
-o $(GVSOC2PERFETTO_OUT) \
--state-map 'fsm_state=0:idle,1:preload,2:routine,3:storing,4:finished,5:acknowledge' \
--state-map 'me_state=0:idle,1:decomposing' \
--state-map 'be_state=0:idle,1:active' \
--rename 'ara=vfu' \
--rename 'label=instructions' \
--rename 'active_pc=pc' \
--split-asm \
--symbolize $(CMAKE_BUILDDIR)/bin/$(test).s \
--stats \
--include '$(GVSOC2PERFETTO_INCLUDE)'
rm -f -- $(GVSOC2PERFETTO_VCD)
MAGIA: set_mesh
ifeq ($(shell expr $(tiles_2) \> 256), 1)
$(eval tiles_2=256)
endif
ifeq ($(target_platform), magia_v1)
sed -i -E 's/^(num_cores[[:space:]]*\?=[[:space:]]*)[0-9]+/\1$(tiles_2)/' $(MAGIA_RTL_DIR)/Makefile
sed -i -E 's/^(core[[:space:]]*\?=[[:space:]]*)CV32E40P/\1CV32E40X/' $(MAGIA_RTL_DIR)/Makefile
else ifeq ($(target_platform), magia_v2)
sed -i -E 's/^(num_cores[[:space:]]*\?=[[:space:]]*)[0-9]+/\1$(tiles_2)/' $(MAGIA_RTL_DIR)/Makefile
sed -i -E 's/^(core[[:space:]]*\?=[[:space:]]*)CV32E40X/\1CV32E40P/' $(MAGIA_RTL_DIR)/Makefile
else
$(error unrecognized platform (acceptable platform: magia).)
endif
ifneq ($(tiles), 1)
sed -i -E 's/^( localparam int unsigned N_TILES_[XY][[:space:]]*=[[:space:]]*)[0-9]+;/\1$(tiles);/' $(MAGIA_RTL_DIR)/hw/mesh/magia_pkg.sv
endif
ifeq ($(fsync_mode), stall)
sed -i -E 's/(FSYNC_STALL[[:space:]]=[[:space:]])[0-9]+/\11/' $(MAGIA_RTL_DIR)/hw/tile/magia_tile_pkg.sv
else ifeq ($(fsync_mode), interrupt)
sed -i -E 's/(FSYNC_STALL[[:space:]]=[[:space:]])[0-9]+/\10/' $(MAGIA_RTL_DIR)/hw/tile/magia_tile_pkg.sv
else
$(error unrecognized fractal sync mode (acceptable modes: stall|interrupt).)
endif
ifneq (,$(filter $(build_mode), update synth profile))
cd $(MAGIA_RTL_DIR) && \
make python_venv || true && \
source setup_env.sh && \
make python_deps || true && \
curl --proto '=https' --tlsv1.2 https://pulp-platform.github.io/bender/init -sSf | sh -s -- --local && \
export PATH=$$(pwd):$$PATH && \
python -m pip install --upgrade "setuptools<81" && \
make $(build_mode)-ips > $(build_mode)-ips.log mesh_dv=$(mesh_dv) && \
make floonoc-patch || true && \
make build-hw > build-hw.log mesh_dv=$(mesh_dv) fast_sim=$(fast_sim)
else
$(error unrecognized mode (acceptable build modes: update|profile|synth).)
endif
gvsoc:
ifeq ($(target_platform), magia_v2)
sed -i -E "s/^[[:space:]]*N_TILES_X[[:space:]]*=[[:space:]]*[0-9]+/ N_TILES_X = $(tiles)/" $(GVSOC_DIR)/pulp/pulp/chips/magia_v2/arch.py
sed -i -E "s/^[[:space:]]*N_TILES_Y[[:space:]]*=[[:space:]]*[0-9]+/ N_TILES_Y = $(tiles)/" $(GVSOC_DIR)/pulp/pulp/chips/magia_v2/arch.py
else
$(error unrecognized platform (acceptable platform: magia_v2).)
endif
ifeq ($(spatz), 1)
sed -i 's/^\([[:space:]]*SPATZ_ENABLE[[:space:]]*=[[:space:]]*\)False/\1True/' $(GVSOC_DIR)/pulp/pulp/chips/magia_v2/arch.py
else
sed -i 's/^\([[:space:]]*SPATZ_ENABLE[[:space:]]*=[[:space:]]*\)True/\1False/' "$(GVSOC_DIR)/pulp/pulp/chips/magia_v2/arch.py"
endif
cd $(GVSOC_DIR) && \
make build TARGETS=magia_v2
# Pinned commits for FondazioneChipsIT/gvsoc, gvsoc-core, pulp, engine, gvrun live in scripts/deps.env.
gvsoc_init:
git clone https://github.com/FondazioneChipsIT/gvsoc.git || true
cd $(GVSOC_DIR) && \
git fetch origin $(GVSOC_COMMIT) && \
git checkout $(GVSOC_COMMIT) && \
git submodule update --init --recursive && \
cd core && \
git fetch origin $(GVSOC_CORE_COMMIT) && \
git checkout $(GVSOC_CORE_COMMIT) && \
cd ../pulp && \
git fetch origin $(GVSOC_PULP_COMMIT) && \
git checkout $(GVSOC_PULP_COMMIT) && \
cd ../engine && \
git fetch origin $(GVSOC_ENGINE_COMMIT) && \
git checkout $(GVSOC_ENGINE_COMMIT) && \
cd ../gvrun && \
git fetch origin $(GVSOC_GVRUN_COMMIT) && \
git checkout $(GVSOC_GVRUN_COMMIT)
gvsoc_uv:
uv venv --python 3.12 gvsoc_venv && \
source gvsoc_venv/bin/activate && \
uv pip install .
gvsoc_venv:
eval "$(pyenv init -)" && \
pyenv local 3.12 && \
python -m venv gvsoc_venv && \
source gvsoc_venv/bin/activate && \
pip install .
llvm:
mkdir -p $(LLVM_DIR)
if [ ! -d "$(LLVM_DIR)/llvm-project/.git" ]; then \
cd $(LLVM_DIR) && git clone $(LLVM_REPO); \
fi
cd $(LLVM_DIR)/llvm-project && \
git checkout $(LLVM_COMMIT) && \
git submodule update --init --recursive --jobs=$(LLVM_JOBS) .
mkdir -p $(LLVM_INSTALL_DIR)
cd $(LLVM_DIR)/llvm-project && mkdir -p build && cd build && \
$(LLVM_CMAKE) \
-DCMAKE_INSTALL_PREFIX=$(LLVM_INSTALL_DIR) \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_C_COMPILER=${CC} \
-DLLVM_OPTIMIZED_TABLEGEN=True \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_TARGETS_TO_BUILD="RISCV" \
-DLLVM_DEFAULT_TARGET_TRIPLE=riscv32-unknown-elf \
-DLLVM_ENABLE_LLD=False \
-DLLVM_APPEND_VC_REV=ON \
-DCMAKE_BUILD_TYPE=Release \
../llvm && \
make -j$(LLVM_JOBS) all && \
make install