Skip to content

Commit

Permalink
WIP: Add coremark as a program to test and a program builder script
Browse files Browse the repository at this point in the history
The section 'target_features' needs to be implemented to work with wasi-clang
compilation.
Add build_programs.py.

Signed-off-by: Ádám László Kulcsár <[email protected]>
  • Loading branch information
kulcsaradam committed Nov 19, 2024
1 parent cf9333d commit 46a9d01
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
path = third_party/uvwasi/uvwasi
url = https://github.com/nodejs/uvwasi
ignore = untracked
[submodule "test/programs/coremark"]
path = test/programs/coremark
url = https://github.com/eembc/coremark.git
140 changes: 140 additions & 0 deletions test/programs/build_programs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env python3

# Copyright 2023-present Samsung Electronics Co., Ltd.
#
# 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.

import argparse
import os
from subprocess import PIPE, Popen

from os.path import abspath, dirname, join

PROGRAMS_SOURCE_DIR = dirname(abspath(__file__))
PROGRAMS_EXECUTABLE_DIR = join(dirname(abspath(__file__)), "executables")

COREMARK_SOURCES = join(PROGRAMS_SOURCE_DIR, "coremark")

clang = False
emcc = False
clang_path = '/opt/wasi-sdk/bin/clang'
emcc_path = 'emcc'

def compile_coremark():
global emcc, emcc_path, clang, clang_path

if clang:
if os.system(clang_path + " --version >/dev/null") != 0:
print("Could not find wasi-clang for building coremark.")
exit(1)

proc = Popen([clang_path,
'-O3',
'-I'+COREMARK_SOURCES+'/posix', '-I'+COREMARK_SOURCES,
'-I' + PROGRAMS_EXECUTABLE_DIR,
'-DFLAGS_STR="-O3 -DPERFORMANCE_RUN=1"',
'-Wl,--export=main',
'-DITERATIONS=400000',
'-DSEED_METHOD=SEED_VOLATILE',
'-DPERFORMANCE_RUN=1',
'-Wl,--allow-undefined',
COREMARK_SOURCES + '/core_list_join.c',
COREMARK_SOURCES + '/core_main.c',
COREMARK_SOURCES + '/core_matrix.c',
COREMARK_SOURCES + '/core_state.c',
COREMARK_SOURCES + '/core_util.c',
COREMARK_SOURCES + '/posix/core_portme.c',
'-o'+ PROGRAMS_EXECUTABLE_DIR +'/coremark_clang.wasm'
])

out, _ = proc.communicate()

if proc.returncode != 0:
print("Error with clang compilation! Stopping.")
exit(1)


if emcc:
if os.system(emcc_path + " --version >/dev/null") != 0:
print("Could not find emcc for building coremark.")
exit(1)

proc = Popen([emcc_path,
'-O3',
'-I'+COREMARK_SOURCES, '-I',COREMARK_SOURCES+'/posix',
'-DFLAGS_STR="-O3 -DPERFORMANCE_RUN=1"',
'-Wl,--allow-undefined',
'-DITERATIONS 400000',
'-DSEED_METHOD=SEED_VOLATILE',
'-DPERFORMANCE_RUN=1',
'-s WASM=1',
'-s EXPORTED_FUNCTIONS=_main',
'-s EXPORTED_RUNTIME_METHODS=ccal,cwrap',
COREMARK_SOURCES + '/core_list_join.c',
COREMARK_SOURCES + '/core_main.c',
COREMARK_SOURCES + '/core_matrix.c',
COREMARK_SOURCES + '/core_state.c',
COREMARK_SOURCES + '/core_util.c',
COREMARK_SOURCES + '/posix/core_portme.c',
'-o'+ PROGRAMS_EXECUTABLE_DIR +'/coremark_emcc.wasm'
])

out, _ = proc.communicate()

if proc.returncode != 0:
print("Error with emscripten compilation! Stopping.")
exit(1)

return


def parse_args():
global emcc, emcc_path, clang, clang_path

parser = argparse.ArgumentParser()
parser.add_argument("--all", help="compile all programs", action="store_true", default=True)
parser.add_argument("--coremark", help="compile coremark", action="store_true")
parser.add_argument("--summary", help="Generate summary", action="store_true", default=False)
parser.add_argument("--emcc", help="Compile with emscripten. If there is no system emcc then follow the argument with a path to the emcc executeable.", nargs="?", default="")
parser.add_argument("--clang", help="Compile with clang. If there is no system emcc then follow the argument with a path to the emcc executeable.", nargs="?", default="")
args = parser.parse_args()

if args.emcc != "" and args.emcc is not None:
emcc_path = args.emcc
emcc = True
elif args.emcc != "":
emcc = True

if args.clang != "" and args.clang is not None:
clang_path = args.clang
clang = True
elif args.clang != "":
clang = True

if not clang and not emcc:
print("Please define which compilers to use with --emcc, --clang!")
exit(1)

return args

def main():
args = parse_args()

if args.all:
compile_coremark()

print("All programs compiled succesfully!")
return

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions test/programs/coremark
Submodule coremark added at d5fad6
5 changes: 1 addition & 4 deletions third_party/wabt/src/walrus/binary-reader-walrus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1258,20 +1258,17 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate {
}

/* target_features section */
// TODO: Add feature tests for building with wasi-clang.
Result BeginTargetFeaturesSection(Offset size) override {
abort();
return Result::Ok;
}
Result OnFeatureCount(Index count) override {
abort();
return Result::Ok;
}
Result OnFeature(uint8_t prefix, nonstd::string_view name) override {
abort();
return Result::Ok;
}
Result EndTargetFeaturesSection() override {
abort();
return Result::Ok;
}

Expand Down

0 comments on commit 46a9d01

Please sign in to comment.