-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathhls.mk
156 lines (140 loc) · 6.53 KB
/
hls.mk
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
#
# Copyright 2017 International Business Machines
#
# Licensed under the Apache License, Version 2.0 (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.
#
# Examples:
# xcku060-ffva1156-2-e
# xc7vx690tffg1157-2
# xcku115-flva1517-2-e
#FPGACHIP ?= xcku060-ffva1156-2-e
CONFIG_FILE = $(SNAP_ROOT)/.snap_config
ifneq ("$(wildcard $(CONFIG_FILE))","")
FPGACHIP = $(shell grep FPGACHIP $(CONFIG_FILE) | cut -d = -f 2 | tr -d '"')
# $(info FPGACHIP is set to $(FPGACHIP).)
endif
PART_NUMBER ?= $(FPGACHIP)
#Reading HLS_CLOCK_PERIOD which can be set in snap_env.sh
snap_env_sh = $(SNAP_ROOT)/snap_env.sh
HLS_ACTION_CLOCK_DEFAULT = 4
ifneq ("$(wildcard $(snap_env_sh))","")
HLS_ACTION_CLOCK_COMMENTED = $(shell grep HLS_CLOCK_PERIOD_CONSTRAINT $(snap_env_sh) | grep "\#")
ifeq "$(HLS_ACTION_CLOCK_COMMENTED)" ""
#if line not commented, then get the value
HLS_ACTION_CLOCK = $(shell grep HLS_CLOCK_PERIOD_CONSTRAINT $(snap_env_sh) | cut -d = -f 2 | tr -d 'ns"')
ifeq "$(HLS_ACTION_CLOCK)" ""
HLS_ACTION_CLOCK = $(HLS_ACTION_CLOCK_DEFAULT)
endif
# $(info HLS CLOCK PERIOD is set to: $(HLS_ACTION_CLOCK) ns)
else
HLS_ACTION_CLOCK = $(HLS_ACTION_CLOCK_DEFAULT)
endif
endif
HLS_CFLAGS ?= ""
# The wrapper name must match a function in the HLS sources which is
# taken as entry point for the HDL generation.
WRAPPER ?= hls_action
syn_dir=$(SOLUTION_DIR)_$(PART_NUMBER)/$(SOLUTION_NAME)/syn
symlinks=vhdl report
# gcc test-bench stuff
objs = $(srcs:.cpp=.o)
CXX = g++
CXXFLAGS = -Wall -W -Wextra -Werror -O2 -DNO_SYNTH -Wno-unknown-pragmas -I../include
.PHONY: $(symlinks)
all: $(syn_dir) check
$(syn_dir): $(srcs) run_hls_script.tcl
@if [ ! -d "$(SNAP_ROOT)/hardware/logs" ]; then \
mkdir -p $(SNAP_ROOT)/hardware/logs; \
fi
@echo " Compiling action with Vivado HLS `vivado_hls -version|head -n1|cut -d " " -f 11`"
@echo " Clock period used for HLS is $(HLS_ACTION_CLOCK) ns"
vivado_hls -f run_hls_script.tcl > $(SNAP_ROOT)/hardware/logs/action_make.log
$(RM) -rf $@/systemc $@/verilog
# Create symlinks for simpler access
$(symlinks): $(syn_dir)
@$(RM) hls_syn_$@ && ln -s $(syn_dir)/$@ hls_syn_$@
run_hls_script.tcl: $(SNAP_ROOT)/actions/scripts/create_run_hls_script.sh
$(SNAP_ROOT)/actions/scripts/create_run_hls_script.sh \
-n $(SOLUTION_NAME) \
-d $(SOLUTION_DIR) \
-w $(WRAPPER) \
-p $(PART_NUMBER) \
-c $(HLS_ACTION_CLOCK) \
-f "$(srcs)" \
-s $(SNAP_ROOT) \
-x "$(HLS_CFLAGS)" > $@
$(SOLUTION_NAME): $(objs)
$(CXX) -o $@ $^
# FIXME That those things are not resulting in an error is problematic.
# If we get critical warnings we stay away from continuing now,
# since that will according to our experience with vivado_hls, lead
# to strange problems later on. So let us work on fixing the design
# if they occur. Rather than challenging our luck.
#
# Check that last HLS compilation of the action was done with the same clock period. Exit if occurs.
# Check for CRITICAL warnings and exit if those occur. Add more if needed.
# Check for critical warnings and exit if those occur. Add more if needed.
# Check for reserved HLS MMIO reg at offset 0x17c.
#
check: $(syn_dir)
@if [ X$(HLS_ACTION_CLOCK) != X$(shell grep "Setting up clock" vivado_hls.log |cut -d " " -f 12|cut -d "n" -f 1) ]; then \
echo " ---------------------------------------------------------- "; \
echo " ERROR: Action was last compiled with a different HLS clock."; \
echo " Please force the recompilation with a 'make clean' command"; \
echo " ---------------------------------------------------------- "; exit -1; \
fi
@echo -n " Checking for critical warnings during HLS synthesis .... "
@grep -A8 CRITICAL vivado_hls.log; \
test $$? = 1
@echo "OK"
@if [ "$(HLS_ACTION_CLOCK)" = "$(HLS_ACTION_CLOCK_DEFAULT)" ]; then \
echo -n " Checking for critical timings during HLS synthesis .... "; \
grep -A8 critical vivado_hls.log; \
if [ $$? -eq 0 ]; then \
echo "------------------------------------------------------------------ "; \
echo "TIMING ERROR: Please correct your action code before going further"!; \
echo "------------------------------------------------------------------ "; exit -1; \
fi; \
echo "OK"; \
else \
echo " --------------------------------------------------------------------------- "; \
echo " By defining HLS_CLOCK_PERIOD_CONSTRAINT in snap_env.sh, automatic critical timing checking is disabled"; \
echo " FYI action was compiled with following HLS clock:"; \
grep "Setting up clock" vivado_hls.log ; \
echo " --------------------------------------------------------------------------- "; \
echo " please CHECK the below list (if any) for HLS synthesis critical timing .... "; \
echo " --------------------------------------------------------------------------- "; \
grep -A8 critical vivado_hls.log ; \
echo " --------------------------------------------------------------------------- "; \
if [ $$? -ne 0 ]; then \
echo "OK"; \
fi; \
fi
@echo -n " Checking for reserved MMIO area during HLS synthesis ... "
@if [ "$(shell grep "0x17c" "$(syn_dir)/vhdl/$(WRAPPER)_ctrl_reg_s_axi.vhd" | cut -d : -f 2)" != " reserved" ]; then \
echo " Error "; \
echo " --------------------------------------------------------------------------- "; \
echo " -- The error comes from the way you defined your common action structure -- "; \
echo " -- option 1: You defined a structure greater than 108 Bytes -- "; \
echo " -- option 2: 64 bits compiler need 64 bits aligned structures -- "; \
echo " -- In both cases please modify the actions/hls_xxx/include/xxx.h file -- "; \
echo " --------------------------------------------------------------------------- "; \
exit -1; \
else \
echo "OK"; \
fi
@sleep 2;
clean:
@$(RM) -r $(SOLUTION_DIR)* run_hls_script.tcl *~ *.log \
$(objs) $(SOLUTION_NAME)
@for link in $(symlinks); do $(RM) hls_syn_$$link; done