Skip to content

Commit f1be56b

Browse files
committed
Migrate sulong and wasm to unchained polybench
1 parent 6ca0ab1 commit f1be56b

31 files changed

+1852
-261
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Copyright (c) 2025, 2025, Oracle and/or its affiliates.
3+
#
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are
7+
# permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this list of
10+
# conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
# conditions and the following disclaimer in the documentation and/or other materials provided
14+
# with the distribution.
15+
#
16+
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
17+
# endorse or promote products derived from this software without specific prior written
18+
# permission.
19+
#
20+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
21+
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22+
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25+
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26+
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
# OF THE POSSIBILITY OF SUCH DAMAGE.
29+
#
30+
31+
QUIETLY$(MX_VERBOSE) = @
32+
33+
.PHONY: default
34+
35+
SOURCE_FILES=$(wildcard ${VPATH}/*.c)
36+
SOURCES=${SOURCE_FILES:${VPATH}/%=%}
37+
BC_NATIVE_FILES=${SOURCES:%.c=interpreter/%.c.native.bc}
38+
39+
default: ${BC_NATIVE_FILES}
40+
41+
ifndef NATIVE_LLVM_CC
42+
$(error NATIVE_LLVM_CC not set)
43+
endif
44+
45+
interpreter/%.c.native.bc: %.c Makefile
46+
@mkdir -p $(shell dirname $@)
47+
$(QUIETLY) $(NATIVE_LLVM_CC) -o $@ -c $<
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
mx.sulong/suite.py,no.copyright
22
projects/com.oracle.truffle.llvm.libraries.bitcode/src/qsort.c,qsort
3+
benchmarks/interpreter/fibonacci.c,no.copyright
4+
benchmarks/interpreter/deltablue.c,no.copyright
5+
benchmarks/interpreter/richards.c,no.copyright
6+
benchmarks/interpreter/sieve.c,no.copyright

sulong/mx.sulong/mx_sulong.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,7 @@ def _open_for_reading(path):
398398

399399

400400
# Legacy bm suite
401-
mx_benchmark.add_bm_suite(mx_sulong_benchmarks.SulongBenchmarkSuite(False))
402-
# Polybench bm suite
403-
mx_benchmark.add_bm_suite(mx_sulong_benchmarks.SulongBenchmarkSuite(True))
401+
mx_benchmark.add_bm_suite(mx_sulong_benchmarks.SulongBenchmarkSuite())
404402
# LLVM unit tests suite
405403
mx_benchmark.add_bm_suite(mx_sulong_benchmarks.LLVMUnitTestsSuite())
406404

sulong/mx.sulong/mx_sulong_benchmarks.py

Lines changed: 36 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2016, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2016, 2025, Oracle and/or its affiliates.
33
#
44
# All rights reserved.
55
#
@@ -35,6 +35,7 @@
3535
import os
3636
from os.path import join, exists
3737

38+
import mx_polybench
3839
import mx_subst
3940
from mx_benchmark import VmRegistry, java_vm_registry, Vm, GuestVm, VmBenchmarkSuite
4041

@@ -63,25 +64,11 @@ def _parse_results_gen():
6364
yield r
6465
return (x for x in _parse_results_gen())
6566

66-
class PolybenchExcludeWarmupRule(mx_benchmark.StdOutRule):
67-
"""Rule that behaves as the StdOutRule, but skips input until a certain pattern."""
68-
69-
def __init__(self, *args, **kwargs):
70-
self.startPattern = re.compile(kwargs.pop('startPattern'))
71-
super(PolybenchExcludeWarmupRule, self).__init__(*args, **kwargs)
72-
73-
def parse(self, text):
74-
m = self.startPattern.search(text)
75-
if m:
76-
return super(PolybenchExcludeWarmupRule, self).parse(text[m.end()+1:])
77-
else:
78-
return []
7967

8068
class SulongBenchmarkSuite(VmBenchmarkSuite):
81-
def __init__(self, use_polybench, *args, **kwargs):
69+
def __init__(self, *args, **kwargs):
8270
super(SulongBenchmarkSuite, self).__init__(*args, **kwargs)
8371
self.bench_to_exec = {}
84-
self.use_polybench = use_polybench
8572

8673
def group(self):
8774
return 'Graal'
@@ -90,7 +77,7 @@ def subgroup(self):
9077
return 'sulong'
9178

9279
def name(self):
93-
return 'csuite-polybench' if self.use_polybench else 'csuite'
80+
return 'csuite'
9481

9582
def run(self, benchnames, bmSuiteArgs):
9683
vm = self.get_vm_registry().get_vm_from_suite_args(bmSuiteArgs)
@@ -116,9 +103,6 @@ def run(self, benchnames, bmSuiteArgs):
116103
env = vm.prepare_env(env)
117104

118105
outName = vm.out_file()
119-
if self.use_polybench:
120-
env['POLYBENCH'] = 'y'
121-
outName += '.so'
122106
out = os.path.join(bench_out_dir, outName)
123107
cmdline = ['make', '-f', '../Makefile', out]
124108
if mx._opts.verbose:
@@ -155,25 +139,15 @@ def flakySkipPatterns(self, benchmarks, bmSuiteArgs):
155139
# preparatory benchmark is run using the llimul launcher and passing --multi-context-runs=0.
156140
# We can capture this argument here and instruct the benchmark infrastructure to ignore
157141
# the output of this benchmark.
158-
if self.use_polybench:
159-
if any(a == "store-aux-engine-cache" for a in bmSuiteArgs):
160-
return [re.compile(r'.*', re.MULTILINE)]
161-
else:
162-
if any(a == "--multi-context-runs=0" for a in bmSuiteArgs):
163-
return [re.compile(r'.*', re.MULTILINE)]
142+
if any(a == "--multi-context-runs=0" for a in bmSuiteArgs):
143+
return [re.compile(r'.*', re.MULTILINE)]
164144
return []
165145

166146
def flakySuccessPatterns(self):
167147
# bzip2 is known to have a compiler error during OSR compilation, but peak numbers are still valid
168148
return [re.compile(r'Compilation of sendMTFValues<OSR@\d+> failed')] # GR-38646
169149

170150
def rules(self, out, benchmarks, bmSuiteArgs):
171-
if self.use_polybench:
172-
return self.polybenchRules(out, benchmarks, bmSuiteArgs)
173-
else:
174-
return self.legacyRules(out, benchmarks, bmSuiteArgs)
175-
176-
def legacyRules(self, out, benchmarks, bmSuiteArgs):
177151
return [
178152
SulongBenchmarkRule(
179153
r'^run (?P<run>[\d]+) first [\d]+ warmup iterations (?P<benchmark>[\S]+):(?P<line>([ ,]+(?:\d+(?:\.\d+)?))+)',
@@ -243,33 +217,6 @@ def legacyRules(self, out, benchmarks, bmSuiteArgs):
243217
}),
244218
]
245219

246-
def polybenchRules(self, output, benchmarks, bmSuiteArgs):
247-
rules = [
248-
mx_benchmark.StdOutRule(r"\[(?P<name>.*)\] iteration ([0-9]*): (?P<value>.*) (?P<unit>.*)", {
249-
"bench-suite": "csuite",
250-
"benchmark": benchmarks[0],
251-
"metric.better": "lower",
252-
"metric.name": "warmup",
253-
"metric.unit": ("<unit>", str),
254-
"metric.value": ("<value>", float),
255-
"metric.type": "numeric",
256-
"metric.score-function": "id",
257-
"metric.iteration": ("$iteration", int),
258-
}),
259-
PolybenchExcludeWarmupRule(r"\[(?P<name>.*)\] iteration (?P<iteration>[0-9]*): (?P<value>.*) (?P<unit>.*)", {
260-
"bench-suite": "csuite",
261-
"benchmark": benchmarks[0],
262-
"metric.better": "lower",
263-
"metric.name": "time",
264-
"metric.unit": ("<unit>", str),
265-
"metric.value": ("<value>", float),
266-
"metric.type": "numeric",
267-
"metric.score-function": "id",
268-
"metric.iteration": ("<iteration>", int),
269-
}, startPattern=r"::: Running :::")
270-
]
271-
return rules
272-
273220
def _get_metric_name(self, bmSuiteArgs):
274221
metric = None
275222
for arg in bmSuiteArgs:
@@ -292,11 +239,7 @@ def workingDirectory(self, benchmarks, bmSuiteArgs):
292239
vm = self.get_vm_registry().get_vm_from_suite_args(bmSuiteArgs)
293240
assert isinstance(vm, CExecutionEnvironmentMixin)
294241

295-
if self.use_polybench and (any(a == "store-aux-engine-cache" for a in bmSuiteArgs) or any(a == "load-aux-engine-cache" for a in bmSuiteArgs)):
296-
# When storing or loading an aux engine cache, the working directory must be the same (the cache for the source is selected by its URL)
297-
return join(_benchmarksDirectory(), benchmarks[0], 'aux-engine-cache')
298-
else:
299-
return join(_benchmarksDirectory(), benchmarks[0], vm.bin_dir())
242+
return join(_benchmarksDirectory(), benchmarks[0], vm.bin_dir())
300243

301244
def createCommandLineArgs(self, benchmarks, bmSuiteArgs):
302245
if len(benchmarks) != 1:
@@ -307,15 +250,14 @@ def createCommandLineArgs(self, benchmarks, bmSuiteArgs):
307250
vmArgs = self.vmArgs(bmSuiteArgs)
308251
runArgs = self.runArgs(bmSuiteArgs)
309252
try:
310-
if not self.use_polybench:
311-
runArgs += ['--time', str(int(time.clock_gettime(time.CLOCK_REALTIME) * 1000000))]
253+
runArgs += ['--time', str(int(time.clock_gettime(time.CLOCK_REALTIME) * 1000000))]
312254
except:
313255
# We can end up here in case the python version we're running on doesn't have clock_gettime or CLOCK_REALTIME.
314256
pass
315257
return vmArgs + [self.bench_to_exec[benchmarks[0]]] + runArgs
316258

317259
def get_vm_registry(self):
318-
return native_polybench_vm_registry if self.use_polybench else native_vm_registry
260+
return native_vm_registry
319261

320262

321263
class CExecutionEnvironmentMixin(object):
@@ -540,93 +482,6 @@ def hosting_registry(self):
540482
return java_vm_registry
541483

542484

543-
class PolybenchVm(CExecutionEnvironmentMixin, GuestVm):
544-
545-
def __init__(self, config_name, options, templateOptions, host_vm=None):
546-
super(PolybenchVm, self).__init__(host_vm)
547-
self._config_name = config_name
548-
self._options = options
549-
self._templateOptions = templateOptions
550-
551-
def with_host_vm(self, host_vm):
552-
return PolybenchVm(self._config_name, self._options, self._templateOptions, host_vm)
553-
554-
def config_name(self):
555-
return self._config_name
556-
557-
def toolchain_name(self):
558-
return "native"
559-
560-
def name(self):
561-
return "sulong-polybench"
562-
563-
def launcherClass(self):
564-
return "org.graalvm.polybench.PolyBenchLauncher"
565-
566-
def launcherName(self):
567-
return "polybench"
568-
569-
def run(self, cwd, args):
570-
bench_file = args[-1:]
571-
bench_args = args[:-1]
572-
launcher_args = ['--path'] + bench_file + self._options + bench_args
573-
if hasattr(self.host_vm(), 'run_launcher'):
574-
result = self.host_vm().run_launcher(self.launcherName(), launcher_args, cwd)
575-
else:
576-
def _filter_properties(args):
577-
props = []
578-
remaining_args = []
579-
vm_prefix = "--vm.D"
580-
for arg in args:
581-
if arg.startswith(vm_prefix):
582-
props.append('-D' + arg[len(vm_prefix):])
583-
else:
584-
remaining_args.append(arg)
585-
return props, remaining_args
586-
587-
props, launcher_args = _filter_properties(launcher_args)
588-
sulongCmdLine = self.launcher_vm_args() + \
589-
props + \
590-
[self.launcherClass(), '--path'] + bench_file + launcher_args
591-
result = self.host_vm().run(cwd, sulongCmdLine)
592-
593-
ret_code, out, vm_dims = result
594-
return ret_code, add_run_numbers(out), vm_dims
595-
596-
def prepare_env(self, env):
597-
# if hasattr(self.host_vm(), 'run_launcher'):
598-
# import mx_sdk_vm_impl
599-
# env['CC'] = os.path.join(mx_sdk_vm_impl.graalvm_home(fatalIfMissing=True), 'jre', 'languages', 'llvm', self.toolchain_name(), 'bin', 'graalvm-{}-clang'.format(self.toolchain_name()))
600-
# else:
601-
# we always use the bootstrap toolchain since the toolchain is not installed by default in a graalvm
602-
# change this if we can properly install components into a graalvm deployment
603-
env['CC'] = mx_subst.path_substitutions.substitute('<toolchainGetToolPath:{},CC>'.format(self.toolchain_name()))
604-
env['CXX'] = mx_subst.path_substitutions.substitute('<toolchainGetToolPath:{},CXX>'.format(self.toolchain_name()))
605-
return env
606-
607-
def out_file(self):
608-
return 'bench'
609-
610-
def opt_phases(self):
611-
return []
612-
613-
def templateOptions(self):
614-
return self._templateOptions
615-
616-
def launcher_vm_args(self):
617-
return mx_sulong.getClasspathOptions(['POLYBENCH'])
618-
619-
def launcher_args(self, args):
620-
launcher_args = [
621-
'--experimental-options',
622-
'--engine.CompilationFailureAction=ExitVM',
623-
'--engine.TreatPerformanceWarningsAsErrors=call,instanceof,store',
624-
]
625-
return launcher_args + args
626-
627-
def hosting_registry(self):
628-
return java_vm_registry
629-
630485
class LLVMUnitTestsSuite(VmBenchmarkSuite):
631486
def __init__(self, *args, **kwargs):
632487
super(LLVMUnitTestsSuite, self).__init__(*args, **kwargs)
@@ -755,25 +610,32 @@ def hosting_registry(self):
755610
native_vm_registry.add_vm(SulongVm('default-O2', [], cflags=['-O2', '-fno-vectorize', '-fno-slp-vectorize']), _suite, 10)
756611
native_vm_registry.add_vm(SulongVm('default-O3', [], cflags=['-O3', '-fno-vectorize', '-fno-slp-vectorize']), _suite, 10)
757612

758-
native_polybench_vm_registry = VmRegistry("NativePolybench", known_host_registries=[java_vm_registry])
759-
native_polybench_vm_registry.add_vm(PolybenchVm('debug-aux-engine-cache',
760-
['--experimental-options', '--eval-source-only.0=true',
761-
'--llvm.AOTCacheStore.0=true', '--llvm.AOTCacheLoad.0=false', '--engine.DebugCacheCompile.0=aot', '--engine.DebugCacheStore.0=true',
762-
'--llvm.AOTCacheStore.1=false', '--llvm.AOTCacheLoad.1=true', '--engine.DebugCacheStore.1=false', '--engine.DebugCacheLoad.1=true',
763-
'--engine.MultiTier=false', '--engine.CompileAOTOnCreate=false', '--engine.DebugCachePreinitializeContext=false',
764-
'--engine.DebugTraceCache=true', '--multi-context-runs=2', '-w', '0', '-i', '10'], []), _suite, 10)
765-
native_polybench_vm_registry.add_vm(PolybenchVm('store-aux-engine-cache',
766-
['--experimental-options', '--multi-context-runs=1', '--eval-source-only=true',
767-
'--llvm.AOTCacheStore=true', '--engine.CacheCompile=aot', '--engine.CachePreinitializeContext=false',
768-
'--engine.TraceCache=true'], ['--engine.CacheStore=' + os.path.join(os.getcwd(), 'test-${benchmark}.image')]), _suite, 10)
769-
native_polybench_vm_registry.add_vm(PolybenchVm('load-aux-engine-cache',
770-
['--experimental-options', '--multi-context-runs=1',
771-
'--llvm.AOTCacheLoad=true', '--engine.CachePreinitializeContext=false', '--engine.TraceCache=true',
772-
'-w', '0', '-i', '10'], ['--engine.CacheLoad=' + os.path.join(os.getcwd(), 'test-${benchmark}.image')]), _suite, 10)
773-
native_polybench_vm_registry.add_vm(PolybenchVm('3-runs-exclusive-engine',
774-
['--multi-context-runs=3', '--shared-engine=false', '-w', '10', '-i', '10'], []), _suite, 10)
775-
native_polybench_vm_registry.add_vm(PolybenchVm('3-runs-shared-engine',
776-
['--multi-context-runs=3', '--shared-engine=true', '-w', '10', '-i', '10'], []), _suite, 10)
777-
778613
lit_vm_registry = VmRegistry("Lit", known_host_registries=[java_vm_registry])
779614
lit_vm_registry.add_vm(LitVm('sulong-native', []), _suite, 10)
615+
616+
mx_polybench.register_polybench_language(mx_suite=_suite, language="llvm", distributions=["LLVM_NATIVE_POM"])
617+
618+
619+
def sulong_polybench_runner(polybench_run: mx_polybench.PolybenchRunFunction, tags) -> None:
620+
if "gate" in tags:
621+
polybench_run(["--jvm", "interpreter/*.bc", "--experimental-options", "--engine.Compilation=false", "-w", "1", "-i", "1"])
622+
polybench_run(["--native", "interpreter/*.bc", "--experimental-options", "--engine.Compilation=false", "-w", "1", "-i", "1"])
623+
if "benchmark" in tags:
624+
polybench_run(["--jvm", "interpreter/*.bc", "--experimental-options", "--engine.Compilation=false"])
625+
polybench_run(["--native", "interpreter/*.bc", "--experimental-options", "--engine.Compilation=false"])
626+
polybench_run(["--jvm", "interpreter/*.bc"])
627+
polybench_run(["--native", "interpreter/*.bc"])
628+
polybench_run(["--jvm", "interpreter/*.bc", "--metric=metaspace-memory"])
629+
polybench_run(["--jvm", "interpreter/*.bc", "--metric=application-memory"])
630+
polybench_run(["--jvm", "interpreter/*.bc", "--metric=allocated-bytes", "-w", "40", "-i", "10", "--experimental-options",
631+
"--engine.Compilation=false"])
632+
polybench_run(["--native", "interpreter/*.bc", "--metric=allocated-bytes", "-w", "40", "-i", "10", "--experimental-options",
633+
"--engine.Compilation=false"])
634+
polybench_run(["--jvm", "interpreter/*.bc", "--metric=allocated-bytes", "-w", "40", "-i", "10"])
635+
polybench_run(["--native", "interpreter/*.bc", "--metric=allocated-bytes", "-w", "40", "-i", "10"])
636+
637+
638+
mx_polybench.register_polybench_benchmark_suite(mx_suite=_suite, name="sulong", languages=["llvm"],
639+
benchmark_distribution="SULONG_POLYBENCH_BENCHMARKS",
640+
benchmark_file_filter=".*bc", runner=sulong_polybench_runner,
641+
tags={"gate", "benchmark"})

0 commit comments

Comments
 (0)