1
+ #!/usr/bin/env python3
2
+
3
+ from itertools import chain
1
4
import csv
5
+ import glob
2
6
import os
3
7
import subprocess as sp
4
8
import sys
13
17
# CSV file name
14
18
CSV_NAME = "benchmarks.csv"
15
19
20
+ # Make sure we're in the code_benches directory
21
+ if os .path .dirname (sys .argv [0 ]):
22
+ os .chdir (os .path .dirname (sys .argv [0 ]))
16
23
# Absolute path to the `code_benches` directory
17
24
BENCH_ROOT = os .getcwd ()
18
25
# Absolute path to the `silverfish` directory
19
26
ROOT_PATH = os .path .dirname (BENCH_ROOT )
20
27
21
28
RUNTIME_PATH = ROOT_PATH + "/runtime"
22
- SILVERFISH_PATH = ROOT_PATH + "/target/release/silverfish"
29
+
30
+ SILVERFISH_RELEASE_PATH = ROOT_PATH + "/target/release/silverfish"
31
+ SILVERFISH_DEBUG_PATH = ROOT_PATH + "/target/debug/silverfish"
32
+ assert all (arg in {"--release" , "--debug" } for arg in sys .argv [1 :])
33
+ if "--release" in sys .argv :
34
+ SILVERFISH_PATH = SILVERFISH_RELEASE_PATH
35
+ elif "--debug" in sys .argv :
36
+ SILVERFISH_PATH = SILVERFISH_DEBUG_PATH
37
+ else :
38
+ def getmtime_or_zero (path ):
39
+ try :
40
+ return os .path .getmtime (path )
41
+ except FileNotFoundError :
42
+ return 0
43
+ SILVERFISH_PATH = max (
44
+ [SILVERFISH_RELEASE_PATH , SILVERFISH_DEBUG_PATH ],
45
+ key = getmtime_or_zero )
23
46
24
47
WASMCEPTION_PATH = ROOT_PATH + "/wasmception"
25
48
@@ -61,6 +84,17 @@ def __init__(self, name, parameters, stack_size, custom_arguments=None, do_lto=T
61
84
def __str__ (self ):
62
85
return "{}({})" .format (self .name , " " .join (map (str , self .parameters )))
63
86
87
+ def sources (self ):
88
+ # glob here, avoids issues with glob expansion in shell
89
+ if self .is_cpp :
90
+ patterns = ["*.c" , "*.cpp" ]
91
+ else :
92
+ patterns = ["*.c" ]
93
+
94
+ paths = (os .path .join (self .name , pattern ) for pattern in patterns )
95
+ sources = chain .from_iterable (glob .glob (path ) for path in paths )
96
+ return " " .join (source [len (self .name )+ 1 :] for source in sources )
97
+
64
98
65
99
# These are the programs we're going to test with
66
100
# TODO: Fix ispell, which doesn't compile on OS X
@@ -76,13 +110,13 @@ def __str__(self):
76
110
"-Wno-shift-negative-value" ]),
77
111
Program ("custom_matrix_multiply" , [], 2 ** 14 ),
78
112
Program ("custom_memcmp" , [], 2 ** 14 ),
79
- Program ("custom_sqlite" , [], 2 ** 15 ),
113
+ Program ("custom_sqlite" , [], 2 ** 15 , custom_arguments = [ "-DSQLITE_MUTEX_NOOP" , "-ldl" ] ),
80
114
81
115
# == Apps ==
82
- Program ("app_nn" , [], 2 ** 14 , custom_arguments = ["-std=c99" , "-Wno-unknown-attributes" , "-DARM_MATH_CM3" , "-I/Users/peachg/Projects/CMSIS_5_NN/CMSIS_5/CMSIS/DSP/Include" , "-I/Users/peachg/Projects/CMSIS_5_NN/CMSIS_5/CMSIS/Core/Include" , "-I/Users/peachg/Projects/CMSIS_5_NN/CMSIS_5/CMSIS/NN/Include" ]),
116
+ # Program("app_nn", [], 2 ** 14, custom_arguments=["-std=c99", "-Wno-unknown-attributes", "-DARM_MATH_CM3", "-I/Users/peachg/Projects/CMSIS_5_NN/CMSIS_5/CMSIS/DSP/Include", "-I/Users/peachg/Projects/CMSIS_5_NN/CMSIS_5/CMSIS/Core/Include", "-I/Users/peachg/Projects/CMSIS_5_NN/CMSIS_5/CMSIS/NN/Include"]),
83
117
Program ("app_pid" , ["-std=c++11" , "-Wall" ], 2 ** 8 , custom_arguments = [], is_cpp = True ),
84
118
Program ("app_tiny_ekf" , ["-std=c++11" , "-Wall" ], 2 ** 14 , custom_arguments = [], is_cpp = True ),
85
- Program ("app_tinycrypt" , [], 2 ** 15 + 2 ** 14 , custom_arguments = [ "-Wall" , "-Wpedantic" , "-Wno-gnu-zero-variadic-macro-arguments" , "-std=c11" , "-I/Users/peachg/Projects/silverfish/code_benches/app_tinycrypt/ " , "-DENABLE_TESTS " ]),
119
+ Program ("app_tinycrypt" , [], 2 ** 15 + 2 ** 14 , custom_arguments = [ "-Wall" , "-Wpedantic" , "-Wno-gnu-zero-variadic-macro-arguments" , "-std=c11" , "-DENABLE_TESTS " , "-I. " ]),
86
120
# Program("app_v9", [], 2 ** 18, custom_arguments=[], do_lto=False),
87
121
88
122
# == MiBench ==
@@ -165,17 +199,20 @@ def compile_to_executable(program):
165
199
if ENABLE_DEBUG_SYMBOLS :
166
200
opt += " -g"
167
201
if program .is_cpp :
168
- sp . check_call ( "shopt -s nullglob; clang++ {} -lm {} *.c *.cpp -o bin/{}" . format ( program . custom_arguments , opt , program . name ), shell = True , cwd = program . name )
202
+ clang = " clang++"
169
203
else :
170
- sp .check_call ("clang {} -lm {} *.c -o bin/{}" .format (program .custom_arguments , opt , program .name ), shell = True , cwd = program .name )
171
- # sp.check_call("clang {} -lm {} *.c -o bin/{}".format(program.custom_arguments, opt, program.name), shell=True, cwd=program.name)
204
+ clang = "clang"
172
205
206
+ command = "{clang} {args} -lm {opt} {sources} -o bin/{pname}" \
207
+ .format (clang = clang , args = program .custom_arguments , opt = opt , sources = program .sources (), pname = program .name )
208
+ print (command )
209
+ sp .check_call (command , shell = True , cwd = program .name )
173
210
174
211
# Compile the C code in `program`'s directory into WASM
175
212
def compile_to_wasm (program ):
176
213
flags = WASM_FLAGS .format (stack_size = program .stack_size )
177
- command = "shopt -s nullglob; {clang} {flags} {args} -O3 -flto ../dummy.c *.c *.cpp -o bin/{pname}.wasm" \
178
- .format (clang = WASM_CLANG , flags = flags , args = program .custom_arguments , pname = program .name )
214
+ command = "{clang} {flags} {args} -O3 -flto ../dummy.c {sources} -o bin/{pname}.wasm" \
215
+ .format (clang = WASM_CLANG , flags = flags , sources = program . sources (), args = program .custom_arguments , pname = program .name )
179
216
print (command )
180
217
sp .check_call (command , shell = True , cwd = program .name )
181
218
@@ -189,10 +226,12 @@ def compile_wasm_to_bc(program):
189
226
190
227
command = "{silverfish} {target} bin/{pname}.wasm -o bin/{pname}.bc" \
191
228
.format (silverfish = SILVERFISH_PATH , target = target_flag , pname = program .name )
229
+ print (command )
192
230
sp .check_call (command , shell = True , cwd = program .name )
193
231
# Also compile an unsafe version, so we can see the performance difference
194
232
command = "{silverfish} {target} -u bin/{pname}.wasm -o bin/{pname}_us.bc" \
195
233
.format (silverfish = SILVERFISH_PATH , target = target_flag , pname = program .name )
234
+ print (command )
196
235
sp .check_call (command , shell = True , cwd = program .name )
197
236
198
237
0 commit comments