-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (116 loc) · 6.17 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
ROOT_DIR := $(shell pwd)
PATTERN_DIR := $(ROOT_DIR)/input_patterns
WORK_LIB_DIR := work_gate
TECH_LIB := $(ROOT_DIR)/sources/techlib
ERROR_SCRIPT := $(ROOT_DIR)/scripts/_compute_errors.py
DATASETS := lenet5_sample resnet18_sample resnet50_sample random8_sample
CIRCUIT_a_HEX := $(addprefix $(PATTERN_DIR)/, $(addsuffix .8bit.hex, $(DATASETS)))
CIRCUIT_b_HEX := $(addprefix $(PATTERN_DIR)/, $(addsuffix .8bit-nvdla.hex, $(DATASETS)))
CIRCUIT_a_DEF := $(addprefix +define+, TOP_LEVEL_MODULE=boothmul OPERAND_PRECISION=8 RESULT_PRECISION=16 CIRCUIT_A)
CIRCUIT_b_DEF := $(addprefix +define+, TOP_LEVEL_MODULE=NV_NVDLA_CMAC_CORE_MAC_mul PRECISION=8)
PYTHON = python3
TOP_NAME = testbench
VLIB = vlib
VSIM = vsim
VLOG = vlog
VLOG_FLAGS = -sv -timescale "1 ns/ 1 ps" -incr -cover t
VOPT = vopt
VOPT_FLAGS = -debugdb -fsmdebug "+acc=rnbpc" -suppress 4308
FAULT_IDX = 0
MODE = "fault injection"
help:
@printf "\033[1mQuestaSIM-based Fault Injection Framework:\033[0m\n"
@printf "\033[31m\tfault_inject/circuit_a/csv_file.csv [FAULT_IDX=...] [MODE=\"fault injection\"|\"failure rate\"]\033[39m Compile & fault inject on the generic Booth 8-bit multiplier using csv_file.csv under input_pattenrs dir as stimulus source.\n"
@printf "\033[31m\tfault_inject/circuit_b/csv_file.csv [FAULT_IDX=...] [MODE=\"fault injection\"|\"failure rate\"]\033[39m Compile & fault inject on the NVDLA Booth 8-bit multiplier using csv_file.csv under input_pattenrs dir as stimulus source.\n"
@printf "\033[1mModes of Operation:\033[0m\n"
@printf "\033[31m\tfault injection\033[39m Inject all stuck-at faults (one-at-a-time) of the CUT and compute MAE, MSE, MRE for dataset (csv pattern source).\n"
@printf "\033[31m\tfailure rate\033[39m Inject all stuck-at faults (one-at-a-time) of the CUT and keep ALL circuit responses (1 file per fault) for dataset (csv pattern source).\n"
%.8bit-nvdla.hex: %.csv
@cd $(PATTERN_DIR) && \
SRC=$(lastword $(subst /, ,$<)) && \
$(PYTHON) 2hex.py \
--source=$$SRC \
--precision=8 \
--nvdla
%.8bit.hex: %.csv
@cd $(PATTERN_DIR) && \
SRC=$(lastword $(subst /, ,$<)) && \
$(PYTHON) 2hex.py \
--source=$$SRC \
--precision=8
%.32bit.hex: %.csv
@cd $(PATTERN_DIR) && \
SRC=$(lastword $(subst /, ,$<)) && \
$(PYTHON) 2hex.py \
--source=$$SRC \
--precision=32
generate_hex/circuit_%:
@$(MAKE) -s $(CIRCUIT_$*_HEX)
#############################################
# CIRCUIT A - 8x8-bit booth multiplier #
#############################################
compile/circuit_a/%: generate_hex/circuit_a
@{ \
FILENAME=$(basename $*) ;\
LINES=$$(wc -l < $(ROOT_DIR)/input_patterns/$*) ;\
OPERANDS=$$(echo "$$LINES * 2" | bc -l) ;\
mkdir -p run/circuit_a/$$FILENAME ;\
cd run/circuit_a/$$FILENAME ;\
cp $(ERROR_SCRIPT) . ;\
$(VLIB) $(WORK_LIB_DIR) ;\
$(VLOG) -work $(WORK_LIB_DIR) -sv +define+functional $(TECH_LIB) ;\
$(VLOG) -work $(WORK_LIB_DIR) $(VLOG_FLAGS) $(CIRCUIT_a_DEF) \
+define+TOTAL_OPERS=$$OPERANDS \
$(ROOT_DIR)/sources/circuit_a/gate \
$(ROOT_DIR)/tb_comb.sv ;\
$(VOPT) -work $(WORK_LIB_DIR) $(VOPT_FLAGS) $(TOP_NAME) \
-o $(addsuffix _vopt, $(TOP_NAME)) ;\
}
fault_inject/circuit_a/%: compile/circuit_a/%
@{ \
FILENAME=$(basename $*) ;\
cd run/circuit_a/$$FILENAME ;\
export _FAULT_LIST=$(ROOT_DIR)/sources/circuit_a/flist ;\
export _FAULT_INDEX=$(FAULT_IDX) ;\
export _MODE=$(MODE) ;\
$(VSIM) -c -work $(WORK_LIB_DIR) -quiet -suppress 3691 \
"+operands_filename=$(ROOT_DIR)/input_patterns/$$FILENAME.8bit.hex" \
$(addsuffix _vopt, $(TOP_NAME)) \
-do "source $(ROOT_DIR)/scripts/fault_simulation.tcl" ;\
}
#############################################
# CIRCUIT B - 8x8-bit NVDLA booth multiplier#
#############################################
compile/circuit_b/%: generate_hex/circuit_b
@{ \
FILENAME=$(basename $*) ;\
OPERANDS=$$(wc -l < $(ROOT_DIR)/input_patterns/$*) ;\
mkdir -p run/circuit_b/$$FILENAME ;\
cd run/circuit_b/$$FILENAME ;\
cp $(ERROR_SCRIPT) . ;\
$(VLIB) $(WORK_LIB_DIR) ;\
$(VLOG) -work $(WORK_LIB_DIR) -sv +define+functional $(TECH_LIB) ;\
$(VLOG) -work $(WORK_LIB_DIR) $(VLOG_FLAGS) $(CIRCUIT_b_DEF) \
+define+TOTAL_OPERS=$$OPERANDS \
$(ROOT_DIR)/sources/circuit_b/gate \
$(ROOT_DIR)/tb_nvdla.sv ;\
$(VOPT) -work $(WORK_LIB_DIR) $(VOPT_FLAGS) $(TOP_NAME) \
-o $(addsuffix _vopt, $(TOP_NAME)) ;\
}
fault_inject/circuit_b/%: compile/circuit_b/%
@{ \
FILENAME=$(basename $*) ;\
cd run/circuit_b/$$FILENAME ;\
export _FAULT_LIST=$(ROOT_DIR)/sources/circuit_b/flist ;\
export _FAULT_INDEX=$(FAULT_IDX) ;\
export _MODE=$(MODE) ;\
$(VSIM) -c -work $(WORK_LIB_DIR) -quiet -suppress 3691 \
"+operands_filename=$(ROOT_DIR)/input_patterns/$$FILENAME.8bit-nvdla.hex" \
$(addsuffix _vopt, $(TOP_NAME)) \
-do "source $(ROOT_DIR)/scripts/fault_simulation.tcl" ;\
}
clean_hex:
rm input_patterns/*.hex
clean_run:
rm run/* -rf
clean_all: clean_hex clean_run