Skip to content

Commit ac2652b

Browse files
committed
Add coremark, smallpt and dhrystone benchmarks to testing
Add a script to build benchmark programs to test walrus
1 parent 5fdeee6 commit ac2652b

7 files changed

Lines changed: 1221 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
path = third_party/uvwasi/uvwasi
1515
url = https://github.com/nodejs/uvwasi
1616
ignore = untracked
17+
[submodule "test/programs/coremark"]
18+
path = test/programs/coremark
19+
url = https://github.com/eembc/coremark.git

test/programs/build_programs.py

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2023-present Samsung Electronics Co., Ltd.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import argparse
18+
import os
19+
from subprocess import Popen
20+
from os.path import abspath, dirname, join
21+
22+
PROGRAMS_SOURCE_DIR = dirname(abspath(__file__))
23+
24+
PROGRAMS_EXECUTABLE_DIR = join(dirname(abspath(__file__)), "executables")
25+
26+
COREMARK_SOURCES = join(PROGRAMS_SOURCE_DIR, "coremark")
27+
28+
clang = False
29+
emcc = False
30+
clang_path = "wasm32-wasip1-clang"
31+
emcc_path = "emcc"
32+
33+
34+
def compile_dhrystone(compilers):
35+
for compiler in compilers:
36+
if "emcc" in compiler:
37+
type = "emcc"
38+
else:
39+
type = "wasi-clang"
40+
41+
proc = Popen(
42+
[
43+
compiler,
44+
"dhrystone/dhry_1.c",
45+
"dhrystone/dhry_2.c",
46+
"-I",
47+
"dhrystone/include",
48+
"-O2",
49+
"-o",
50+
"executables/dhrystone_" + type + ".wasm",
51+
]
52+
)
53+
54+
out, _ = proc.communicate()
55+
if proc.returncode != 0:
56+
print("Error with coremark " + type + " compilation! Stopping.")
57+
exit(1)
58+
59+
return
60+
61+
62+
def compile_smallpt(compilers):
63+
if not os.path.isfile("forward.cpp"):
64+
os.system("wget http://kevinbeason.com/smallpt/forward.cpp")
65+
os.system("patch -u forward.cpp -i smallpt_wasm.patch")
66+
67+
for compiler in compilers:
68+
if "emcc" in compiler:
69+
type = "emcc"
70+
else:
71+
type = "wasi-clang"
72+
compiler = compiler + "++"
73+
74+
proc = Popen(
75+
[
76+
compiler,
77+
"forward.cpp",
78+
"-O2",
79+
"-o",
80+
"executables/smallpt_" + type + ".wasm",
81+
]
82+
)
83+
84+
out, _ = proc.communicate()
85+
if proc.returncode != 0:
86+
print("Error with smallpt " + type + " compilation! Stopping.")
87+
exit(1)
88+
89+
return
90+
91+
92+
def compile_coremark(compilers):
93+
for compiler in compilers:
94+
if "emcc" in compiler:
95+
type = "emcc"
96+
else:
97+
type = "wasi-clang"
98+
99+
proc = Popen(
100+
[
101+
compiler,
102+
"-I" + COREMARK_SOURCES + "/posix",
103+
"-I" + COREMARK_SOURCES,
104+
'-DFLAGS_STR="-O3 -DPERFORMANCE_RUN=1"',
105+
"-Wl,--export=main",
106+
"-DITERATIONS=400000",
107+
"-DSEED_METHOD=SEED_VOLATILE",
108+
"-DPERFORMANCE_RUN=1",
109+
"-Wl,--allow-undefined",
110+
COREMARK_SOURCES + "/core_list_join.c",
111+
COREMARK_SOURCES + "/core_main.c",
112+
COREMARK_SOURCES + "/core_matrix.c",
113+
COREMARK_SOURCES + "/core_state.c",
114+
COREMARK_SOURCES + "/core_util.c",
115+
COREMARK_SOURCES + "/posix/core_portme.c",
116+
"-o",
117+
"executables/coremark_" + type + ".wasm",
118+
]
119+
)
120+
121+
out, _ = proc.communicate()
122+
if proc.returncode != 0:
123+
print("Error with coremark " + type + " compilation! Stopping.")
124+
exit(1)
125+
126+
return
127+
128+
129+
def parse_args():
130+
global emcc, emcc_path, clang, clang_path
131+
132+
parser = argparse.ArgumentParser(
133+
description="script to compile wasm benchmarks, by default it will compile all programs"
134+
)
135+
parser.add_argument("--coremark", help="compile coremark", action="store_true")
136+
parser.add_argument("--smallpt", help="compile smallpt", action="store_true")
137+
parser.add_argument("--dhrystone", help="compile dhrystone", action="store_true")
138+
parser.add_argument(
139+
"--emcc",
140+
help="compile with emscripten",
141+
action="store_true",
142+
)
143+
parser.add_argument(
144+
"--emcc-path", help="path to the emcc executable", nargs="?", default=""
145+
)
146+
parser.add_argument(
147+
"--clang",
148+
help="compile with clang",
149+
action="store_true",
150+
)
151+
parser.add_argument(
152+
"--clang-path", help="path to the wasi-clang executable", nargs="?", default=""
153+
)
154+
args = parser.parse_args()
155+
156+
if args.emcc is True:
157+
emcc = True
158+
159+
if args.clang is True:
160+
clang = True
161+
162+
if args.emcc_path:
163+
emcc_path = args.emcc_path
164+
165+
if args.clang_path:
166+
clang_path = args.clang_path
167+
168+
if not emcc and not clang:
169+
print("Please specify a compiler with either --emcc or --clang!")
170+
exit(1)
171+
172+
return args
173+
174+
175+
def main():
176+
global emcc, emcc_path, clang, clang_path
177+
args = parse_args()
178+
179+
compilers = []
180+
tests = []
181+
182+
if emcc:
183+
if os.system(emcc_path + " --version >/dev/null") != 0:
184+
print("Could not find emscripten executable")
185+
exit(1)
186+
compilers.append(emcc_path)
187+
188+
if clang:
189+
if os.system(clang_path + " --version >/dev/null") != 0:
190+
print("Could not find wasi-clang executable")
191+
exit(1)
192+
compilers.append(clang_path)
193+
194+
if args.coremark:
195+
tests.append(compile_coremark)
196+
if args.smallpt:
197+
tests.append(compile_smallpt)
198+
if args.dhrystone:
199+
tests.append(compile_dhrystone)
200+
201+
if not tests:
202+
tests.append(compile_coremark)
203+
tests.append(compile_smallpt)
204+
tests.append(compile_dhrystone)
205+
206+
for test in tests:
207+
test(compilers)
208+
209+
print("All programs compiled succesfully!")
210+
return
211+
212+
213+
if __name__ == "__main__":
214+
main()

test/programs/coremark

Submodule coremark added at 1f483d5

0 commit comments

Comments
 (0)