-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
179 lines (144 loc) · 4.63 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
# 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 <[email protected]>
#
# Top-level Makefile
# Paths to folders
RootDir := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
TargetDir := $(RootDir)target
SimDir := $(TargetDir)/sim
ScriptsDir := $(RootDir)scripts
VerilatorPath := target/sim/verilator
VsimPath := target/sim/vsim
SW ?= $(RootDir)sw
BUILD_DIR ?= $(SW)/build
SIM_DIR ?= $(RootDir)vsim
QUESTA ?= questa-2023.4
BENDER_DIR ?= .
BENDER ?= bender
Gcc ?= $(GccInstallDir)/bin/
ISA ?= riscv
ARCH ?= rv
XLEN ?= 32
XTEN ?= imc_zicsr
PYTHON ?= python3
target ?= verilator
TargetPath := $(SimDir)/$(target)
# Included makefrags
include $(TargetPath)/$(target).mk
include bender_common.mk
include bender_sim.mk
include bender_synth.mk
ifeq ($(REDMULE_COMPLEX),1)
TEST_SRCS := $(SW)/redmule_complex.c
else
TEST_SRCS := $(SW)/redmule.c
endif
compile_script_synth ?= $(RootDir)scripts/synth_compile.tcl
INI_PATH = $(RootDir)modelsim.ini
WORK_PATH = $(SIM_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=$(Gcc)$(ISA)$(XLEN)-unknown-elf-gcc
LD=$(CC)
OBJDUMP=$(Gcc)$(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=$(BUILD_DIR)/stim_instr.txt
STIM_DATA=$(BUILD_DIR)/stim_data.txt
# Build implicit rules
$(STIM_INSTR) $(STIM_DATA): $(BIN)
objcopy --srec-len 1 --output-target=srec $(BIN) $(BIN).s19
$(PYTHON) scripts/parse_s19.py < $(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
# Download bender
bender:
curl --proto '=https' \
--tlsv1.2 https://pulp-platform.github.io/bender/init -sSf | sh -s -- 0.24.0
$(SIM_DIR):
mkdir -p $(SIM_DIR)
synth-ips:
$(BENDER) update
$(BENDER) script synopsys \
$(common_targs) $(common_defs) \
$(synth_targs) $(synth_defs) \
> ${compile_script_synth}
sw-clean:
rm -rf $(BUILD_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: sw-clean
rm -rf $(RootDir).bender
rm -rf $(compile_script)
sw-all: sw-clean sw-build
# Install tools
CXX ?= g++
NumCores := $(shell nproc)
NumCoresHalf := $(shell echo "$$(($(NumCores) / 2))")
VendorDir ?= $(RootDir)vendor
InstallDir ?= $(VendorDir)/install
# Verilator
VerilatorVersion ?= v5.028
VerilatorInstallDir := $(InstallDir)/verilator
# GCC
GccInstallDir := $(InstallDir)/riscv
RiscvTarDir := riscv.tar.gz
GccUrl := https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2024.08.28/riscv32-elf-ubuntu-20.04-gcc-nightly-2024.08.28-nightly.tar.gz
verilator: $(InstallDir)/bin/verilator
$(InstallDir)/bin/verilator:
rm -rf $(VendorDir)/verilator
mkdir -p $(VendorDir) && cd $(VendorDir) && git clone https://github.com/verilator/verilator.git
# Checkout the right version
cd $(VendorDir)/verilator && git reset --hard && git fetch && git checkout $(VerilatorVersion)
# Compile verilator
sudo apt install libfl-dev help2man
mkdir -p $(VerilatorInstallDir) && cd $(VendorDir)/verilator && git clean -xfdf && autoconf && \
./configure --prefix=$(VerilatorInstallDir) CXX=$(CXX) && make -j$(NumCoresHalf) && make install
riscv32-gcc: $(GccInstallDir)
$(GccInstallDir):
rm -rf $(GccInstallDir) $(VendorDir)/$(RiscvTarDir)
mkdir -p $(InstallDir)
cd $(VendorDir) && \
wget $(GccUrl) -O $(RiscvTarDir) && \
tar -xzvf $(RiscvTarDir) -C $(InstallDir) riscv