cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
select_cfpzoo_kernel Namespace Reference

Functions

def edit_file (full_file, new_kernel, udp, tcp, mtu, port, ddr)
 

Variables

list kernels = ["Harris", "Median_Blur", "MCEuropeanEngine", "Uppercase", "Memtest", "Warp_Transform"]
 Main script. More...
 
int arguments = len(sys.argv) - 1
 
int kernel_id = -1
 
int udp = 0
 
int tcp = 1
 
 mtu = sys.argv[4]
 
 port = sys.argv[5]
 
int ddr = 1
 
list new_kernel = kernels[kernel_id]
 
 role = os.getenv('roleName1')
 
string file = "ROLE/"+role+"/hdl/Role.vhdl"
 
string full_file = str(pathlib.Path().absolute()) + '/' + str(file)
 

Function Documentation

◆ edit_file()

def select_cfpzoo_kernel.edit_file (   full_file,
  new_kernel,
  udp,
  tcp,
  mtu,
  port,
  ddr 
)

Definition at line 29 of file select_cfpzoo_kernel.py.

29 def edit_file(full_file, new_kernel, udp, tcp, mtu, port, ddr):
30  f1 = open(full_file, 'r')
31  f2 = open(full_file+"_new", 'w')
32 
33  replaced = 0
34  uaf_start_detected = taf_start_detected = 0
35  ddr_component_start_detected = ddr_component_end_detected = 0
36  ddr_uaf_start_detected = ddr_uaf_end_detected = 0
37  ddr_taf_start_detected = ddr_taf_end_detected = 0
38  ddr_Mp2_dummy_start_detected = ddr_Mp2_dummy_end_detected = 0
39 
40  for s in f1:
41  new_s = s2 = s
42  if search("vhdl", full_file):
43  search_str = " component "
44  if search(search_str, s):
45  s2 = " component "+new_kernel+"Application is\n"
46  replaced = replaced + 1
47 
48  search_str = " end component "
49  if search(search_str, s):
50  s2 = " end component "+new_kernel+"Application;\n"
51  replaced = replaced + 1
52 
53 
55 
56  # Check component start
57  search_str = "SHELL / Mem / Mp0 Interface / Start Component"
58  if search(search_str, s):
59  s2 = s
60  ddr_component_start_detected = 1
61 
62  # Check component stop
63  search_str = "SHELL / Mem / Mp1 Interface / End Component"
64  if search(search_str, s):
65  s2 = s
66  ddr_component_end_detected = 1
67 
68  # Replace ddr pattern in component declaration
69  if (ddr_component_start_detected):
70  excluding_pattern = "-- auto excluding component Mp0-Mp1 "
71  if (search(excluding_pattern, s2)):
72  if (ddr):
73  s2 = s2.replace(str(excluding_pattern), str(''))
74  replaced = replaced + 1
75  else:
76  if (not ddr):
77  s2 = excluding_pattern + s2
78  replaced = replaced + 1
79  if (ddr_component_end_detected):
80  ddr_component_start_detected = ddr_component_end_detected = 0;
81 
82 
83  # Check DDR in UAF start
84  search_str = "SHELL / Mem / Mp0 Interface / Start in UAF"
85  if search(search_str, s):
86  s2 = s
87  ddr_uaf_start_detected = 1
88 
89  # Check DDR in UAF stop
90  search_str = "SHELL / Mem / Mp1 Interface / End in UAF"
91  if search(search_str, s):
92  s2 = s
93  ddr_uaf_end_detected = 1
94 
95  # Replace ddr pattern in component declaration
96  if (ddr_uaf_start_detected):
97  excluding_pattern = "-- auto excluding Mp0-Mp1 in UAF "
98  if (search(excluding_pattern, s2)):
99  if (ddr):
100  s2 = s2.replace(str(excluding_pattern), str(''))
101  replaced = replaced + 1
102  else:
103  if (not ddr):
104  s2 = excluding_pattern + s2
105  replaced = replaced + 1
106  if (ddr_uaf_end_detected):
107  ddr_uaf_start_detected = ddr_uaf_end_detected = 0;
108 
109 
110  # Check DDR in TAF start
111  search_str = "SHELL / Mem / Mp0 Interface / Start in TAF"
112  if search(search_str, s):
113  s2 = s
114  ddr_taf_start_detected = 1
115 
116  # Check DDR in TAF stop
117  search_str = "SHELL / Mem / Mp1 Interface / End in TAF"
118  if search(search_str, s):
119  s2 = s
120  ddr_taf_end_detected = 1
121 
122  # Replace ddr pattern in component declaration
123  if (ddr_taf_start_detected):
124  excluding_pattern = "-- auto excluding Mp0-Mp1 in TAF "
125  if (search(excluding_pattern, s2)):
126  if (ddr):
127  s2 = s2.replace(str(excluding_pattern), str(''))
128  replaced = replaced + 1
129  else:
130  if (not ddr):
131  s2 = excluding_pattern + s2
132  replaced = replaced + 1
133  if (ddr_taf_end_detected):
134  ddr_taf_start_detected = ddr_taf_end_detected = 0;
135 
136 
137  # Check DDR in dummy start
138  search_str = "2nd Memory Port dummy connections Start"
139  if search(search_str, s):
140  s2 = s
141  ddr_Mp2_dummy_start_detected = 1
142 
143  # Check DDR in dummy stop
144  search_str = "2nd Memory Port dummy connections End"
145  if search(search_str, s):
146  s2 = s
147  ddr_Mp2_dummy_end_detected = 1
148 
149  # Replace ddr pattern in component declaration
150  if (ddr_Mp2_dummy_start_detected):
151  excluding_pattern = "-- auto excluding Mp2 open connections "
152  if (search(excluding_pattern, s2)):
153  if (not ddr):
154  s2 = s2.replace(str(excluding_pattern), str(''))
155  replaced = replaced + 1
156  else:
157  if (ddr):
158  s2 = excluding_pattern + s2
159  replaced = replaced + 1
160  if (ddr_Mp2_dummy_end_detected):
161  ddr_Mp2_dummy_start_detected = ddr_Mp2_dummy_end_detected = 0;
162 
163 
164  search_str = " UAF: "
165  if search(search_str, s):
166  s2 = " UAF: "+new_kernel+"Application\n"
167  uaf_start_detected = 1
168  replaced = replaced + 1
169 
170  search_str = " TAF: "
171  if search(search_str, s):
172  s2 = " TAF: "+new_kernel+"Application\n"
173  taf_start_detected = 1
174  replaced = replaced + 1
175 
176  # Checking if we have to comment out UAF
177  if (uaf_start_detected):
178  excluding_pattern = "-- auto excluding UAF "
179  if (search(excluding_pattern, s2)):
180  if (udp):
181  s2 = s2.replace(str(excluding_pattern), str(''))
182  replaced = replaced + 1
183  else:
184  if (not udp):
185  s2 = excluding_pattern + s2
186  replaced = replaced + 1
187  if (search(" \‍);", s)):
188  uaf_start_detected = 0;
189 
190  # Checking if we have to comment out TAF
191  if (taf_start_detected):
192  excluding_pattern = "-- auto excluding TAF "
193  if (search(excluding_pattern, s2)):
194  if (tcp):
195  s2 = s2.replace(str(excluding_pattern), str(''))
196  replaced = replaced + 1
197  else:
198  if (not tcp):
199  s2 = excluding_pattern + s2
200  replaced = replaced + 1
201  if (search(" \‍);", s)):
202  taf_start_detected = 0;
203 
204  new_s = s.replace(str(s), str(s2))
205  f2.write(new_s)
206 
207  if search("tcl", full_file):
208  search_str = "# IBM-HSL-IP : "
209  if search(search_str, s):
210  s2 = "# IBM-HSL-IP : "+new_kernel+" Application Flash\n"
211  replaced = replaced + 1
212 
213  search_str = "set ipModName"
214  if search(search_str, s):
215  s2 = "set ipModName \""+new_kernel+"Application\"\n"
216  replaced = replaced + 1
217 
218  search_str = "set ipName"
219  if search(search_str, s):
220  s2 = "set ipName \""+new_kernel.lower()+"\"\n"
221  replaced = replaced + 1
222 
223  new_s = s.replace(str(s), str(s2))
224  f2.write(new_s)
225 
226  if search("Makefile", full_file):
227  search_str = ".PHONY: all clean mem_test_flash "
228  if search(search_str, s):
229  s2 = ".PHONY: all clean mem_test_flash "+new_kernel.lower()+"\n"
230  replaced = replaced + 1
231 
232  search_str = "all: mem_test_flash "
233  if search(search_str, s):
234  s2 = "all: mem_test_flash "+new_kernel.lower()+"\n"
235  replaced = replaced + 1
236 
237  new_s = s.replace(str(s), str(s2))
238  f2.write(new_s)
239 
240  if search("config.h", full_file):
241  search_str1 = "#define NET_TYPE "
242  search_str2 = "#define PACK_SIZE "
243  if search(search_str1, s):
244  if (udp and tcp):
245  s2 = search_str1 + "udp //tcp\n"
246  elif (udp):
247  s2 = search_str1 + "udp\n"
248  elif (tcp):
249  s2 = search_str1 + "tcp\n"
250  replaced = replaced + 1
251  elif search(search_str2, s):
252  s2 = search_str2 + mtu + "\n"
253  replaced = replaced + 1
254  new_s = s.replace(str(s), str(s2))
255  f2.write(new_s)
256 
257 
258  if search(".hpp", full_file):
259  search_str1 = "#define DEFAULT_TX_PORT "
260  search_str2 = "#define DEFAULT_RX_PORT "
261  if search(search_str1, s):
262  s2 = search_str1 + port + "\n"
263  replaced = replaced + 1
264  elif search(search_str2, s):
265  s2 = search_str2 + port + "\n"
266  replaced = replaced + 1
267  new_s = s.replace(str(s), str(s2))
268 
269  search_str3 = "#define ENABLE_DDR"
270  if search(search_str3, s):
271  if (ddr):
272  s2 = search_str3 + "\n"
273  else:
274  s2 = "// " + search_str3 + "\n"
275  replaced = replaced + 1
276  new_s = new_s.replace(str(s), str(s2))
277  f2.write(new_s)
278 
279 
280  print("INFO: Edits of file " + full_file + " : "+ str(replaced))
281  print("#################")
282  f1.close()
283  f2.close()
284  if (replaced != 0):
285  shutil.copyfile(full_file, full_file+"_backup")
286  shutil.move(full_file+"_new", full_file)
287 
288 
def edit_file(full_file, new_kernel, udp, tcp, mtu, port, ddr)

Variable Documentation

◆ arguments

int select_cfpzoo_kernel.arguments = len(sys.argv) - 1

Definition at line 299 of file select_cfpzoo_kernel.py.

◆ ddr

int select_cfpzoo_kernel.ddr = 1

Definition at line 329 of file select_cfpzoo_kernel.py.

◆ file

string select_cfpzoo_kernel.file = "ROLE/"+role+"/hdl/Role.vhdl"

Definition at line 344 of file select_cfpzoo_kernel.py.

◆ full_file

string select_cfpzoo_kernel.full_file = str(pathlib.Path().absolute()) + '/' + str(file)

Definition at line 345 of file select_cfpzoo_kernel.py.

◆ kernel_id

select_cfpzoo_kernel.kernel_id = -1

Definition at line 305 of file select_cfpzoo_kernel.py.

◆ kernels

list select_cfpzoo_kernel.kernels = ["Harris", "Median_Blur", "MCEuropeanEngine", "Uppercase", "Memtest", "Warp_Transform"]

Main script.

Definition at line 294 of file select_cfpzoo_kernel.py.

◆ mtu

select_cfpzoo_kernel.mtu = sys.argv[4]

Definition at line 324 of file select_cfpzoo_kernel.py.

◆ new_kernel

list select_cfpzoo_kernel.new_kernel = kernels[kernel_id]

Definition at line 340 of file select_cfpzoo_kernel.py.

◆ port

select_cfpzoo_kernel.port = sys.argv[5]

Definition at line 325 of file select_cfpzoo_kernel.py.

◆ role

select_cfpzoo_kernel.role = os.getenv('roleName1')

Definition at line 342 of file select_cfpzoo_kernel.py.

◆ tcp

int select_cfpzoo_kernel.tcp = 1

Definition at line 322 of file select_cfpzoo_kernel.py.

◆ udp

int select_cfpzoo_kernel.udp = 0

Definition at line 318 of file select_cfpzoo_kernel.py.