Skip to content

Commit fca0ddb

Browse files
committed
[GR-60584] [GR-64433] [GR-67907] Move polybench to truffle and unchain it.
PullRequest: graal/19818
2 parents 192df35 + 3cacaaf commit fca0ddb

File tree

126 files changed

+3635
-16987
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+3635
-16987
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

espresso/mx.espresso/mx_espresso.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import mx_subst
3737
import mx_util
3838
import mx_gate
39-
import mx_espresso_benchmarks # pylint: disable=unused-import
39+
import mx_espresso_benchmarks
4040
import mx_sdk_vm
4141
import mx_sdk_vm_impl
4242
from mx_gate import Task, add_gate_runner
@@ -99,7 +99,7 @@ def _espresso_standalone_command(args, with_sulong=False, allow_jacoco=True, jdk
9999
)
100100

101101
def javavm_deps():
102-
result = [espresso_resources_suite() + ':ESPRESSO_RUNTIME_RESOURCES']
102+
result = [espresso_runtime_resources_distribution()]
103103
if mx.suite('truffle-enterprise', fatalIfMissing=False):
104104
result.append('truffle-enterprise:TRUFFLE_ENTERPRISE')
105105
if mx.suite('regex', fatalIfMissing=False):
@@ -212,6 +212,8 @@ def _run_verify_imports(s):
212212
# Find invalid files
213213
invalid_files = []
214214
for project in s.projects:
215+
if getattr(project, "skipVerifyImports", False):
216+
continue
215217
output_root = project.get_output_root()
216218
for src_dir in project.source_dirs():
217219
if src_dir.startswith(output_root):
@@ -581,6 +583,8 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
581583
community_dist_name=f'GRAALVM_ESPRESSO_COMMUNITY_JAVA{java_home_dep.major_version}{dist_suffix}',
582584
enterprise_dist_name=f'GRAALVM_ESPRESSO_JAVA{java_home_dep.major_version}{dist_suffix}'))
583585

586+
mx_espresso_benchmarks.mx_register_dynamic_suite_constituents(register_project, register_distribution)
587+
584588

585589
def espresso_resources_suite(java_home_dep=None):
586590
# Espresso resources are in the CE/EE suite depending on espresso java home type
@@ -592,6 +596,10 @@ def espresso_resources_suite(java_home_dep=None):
592596
return 'espresso'
593597

594598

599+
def espresso_runtime_resources_distribution(java_home_dep=None):
600+
return espresso_resources_suite(java_home_dep=java_home_dep) + ':ESPRESSO_RUNTIME_RESOURCES'
601+
602+
595603
def register_espresso_runtime_resources(register_project, register_distribution, suite):
596604
if espresso_resources_suite() != suite.name:
597605
return

espresso/mx.espresso/mx_espresso_benchmarks.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,108 @@
2020
# or visit www.oracle.com if you need additional information or have any
2121
# questions.
2222
#
23+
import os
2324
import re
2425
from abc import ABCMeta, abstractmethod
2526

2627
import mx
2728
import mx_benchmark
2829
import mx_espresso
30+
import mx_jardistribution
31+
import mx_polybench
2932

3033
from mx_benchmark import GuestVm, JavaVm, OutputCapturingJavaVm
3134
from mx_sdk_benchmark import _daCapoScalaConfig
3235

3336
_suite = mx.suite('espresso')
3437

3538

39+
def mx_register_dynamic_suite_constituents(register_project, register_distribution):
40+
benchmark_dist = _suite.dependency("ESPRESSO_POLYBENCH_BENCHMARKS")
41+
polybench_benchmarks = os.path.join(_suite.dir, 'benchmarks', 'interpreter')
42+
for f in os.listdir(polybench_benchmarks):
43+
if os.path.isdir(os.path.join(polybench_benchmarks, f)) and not f.startswith("."):
44+
main_class = os.path.basename(f)
45+
simple_name = main_class.split(".")[-1]
46+
47+
project_name = 'benchmarks.interpreter.espresso.' + simple_name.lower()
48+
register_project(mx.JavaProject(
49+
suite=_suite,
50+
subDir=None,
51+
srcDirs=[os.path.join(_suite.dir, 'benchmarks', 'interpreter', main_class)],
52+
deps=[],
53+
name=project_name,
54+
d=os.path.join(_suite.dir, 'benchmarks', 'interpreter', main_class),
55+
javaCompliance='11+',
56+
workingSets=None,
57+
testProject=True,
58+
eclipseformat=False,
59+
skipVerifyImports=True,
60+
# javac and JDT both produce warnings on these sources. suppress javac warnings and avoid JDT.
61+
forceJavac=True,
62+
checkstyleProj=project_name,
63+
**{
64+
"javac.lint.overrides": "none",
65+
}
66+
))
67+
68+
dist_name = 'ESPRESSO_POLYBENCH_BENCHMARK_' + simple_name.upper()
69+
jar_dist = mx_jardistribution.JARDistribution(
70+
suite=_suite,
71+
subDir=None,
72+
srcDirs=[''],
73+
sourcesPath=None,
74+
deps=[project_name],
75+
mainClass=main_class,
76+
name=dist_name,
77+
path='',
78+
platformDependent=False,
79+
distDependencies=[],
80+
javaCompliance='11+',
81+
excludedLibs=[],
82+
workingSets=None,
83+
theLicense=None,
84+
testDistribution=True,
85+
maven=False,
86+
)
87+
register_distribution(jar_dist)
88+
89+
benchmark_dist.layout[f'./interpreter/{simple_name}.jar'] = [
90+
f'dependency:{dist_name}/*.jar']
91+
benchmark_dist.buildDependencies.append(dist_name)
92+
93+
espresso_runtime_resources_distribution = mx_espresso.espresso_runtime_resources_distribution()
94+
mx_polybench.register_polybench_language(mx_suite=_suite, language="espresso",
95+
distributions=["ESPRESSO", "ESPRESSO_LIBS_RESOURCES",
96+
espresso_runtime_resources_distribution, "truffle:TRUFFLE_NFI_LIBFFI"])
97+
98+
def espresso_polybench_runner(polybench_run: mx_polybench.PolybenchRunFunction, tags) -> None:
99+
if "gate" in tags:
100+
polybench_run(["--jvm", "interpreter/*.jar", "--experimental-options", "--engine.Compilation=false", "-w", "1", "-i", "1"])
101+
polybench_run(["--native", "interpreter/*.jar", "--experimental-options", "--engine.Compilation=false", "-w", "1", "-i", "1"])
102+
if "benchmark" in tags:
103+
polybench_run(["--jvm", "interpreter/*.jar", "--experimental-options", "--engine.Compilation=false"])
104+
polybench_run(["--native", "interpreter/*.jar", "--experimental-options", "--engine.Compilation=false"])
105+
polybench_run(["--jvm", "interpreter/*.jar"])
106+
polybench_run(["--native", "interpreter/*.jar"])
107+
polybench_run(["--jvm", "interpreter/*.jar", "--metric=metaspace-memory"])
108+
polybench_run(["--jvm", "interpreter/*.jar", "--metric=application-memory"])
109+
polybench_run(["--jvm", "interpreter/*.jar", "--metric=allocated-bytes", "-w", "40", "-i", "10", "--experimental-options", "--engine.Compilation=false"])
110+
polybench_run(["--native", "interpreter/*.jar", "--metric=allocated-bytes", "-w", "40", "-i", "10", "--experimental-options", "--engine.Compilation=false"])
111+
polybench_run(["--jvm", "interpreter/*.jar", "--metric=allocated-bytes", "-w", "40", "-i", "10"])
112+
polybench_run(["--native", "interpreter/*.jar", "--metric=allocated-bytes", "-w", "40", "-i", "10"])
113+
if "instructions" in tags:
114+
assert mx_polybench.is_enterprise()
115+
fork_count_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "polybench-fork-counts.json")
116+
polybench_run(["--native", "interpreter/*.jar", "--metric=instructions", "--experimental-options", "--engine.Compilation=false",
117+
"--mx-benchmark-args", "--fork-count-file", fork_count_file])
118+
119+
mx_polybench.register_polybench_benchmark_suite(mx_suite=_suite, name="espresso", languages=["espresso"],
120+
benchmark_distribution=benchmark_dist.name,
121+
benchmark_file_filter=".*jar", runner=espresso_polybench_runner,
122+
tags={"gate", "benchmark", "instructions"})
123+
124+
36125
class EspressoStandaloneVm(OutputCapturingJavaVm, metaclass=ABCMeta):
37126
def __init__(self, config_name, options):
38127
super().__init__()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"polybench:interpreter/DeltaBlue.jar": 5,
3+
"polybench:interpreter/Fibonacci.jar": 5,
4+
"polybench:interpreter/Richards.jar": 5,
5+
"polybench:interpreter/Sieve.jar": 5
6+
}

espresso/mx.espresso/suite.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,5 +935,12 @@
935935
"dynamicDistDependencies": "jvm_standalone_deps",
936936
"maven": False,
937937
},
938+
939+
"ESPRESSO_POLYBENCH_BENCHMARKS": {
940+
"description": "Distribution for Espresso polybench benchmarks",
941+
"layout": {
942+
# Layout is dynamically populated in mx_register_dynamic_suite_constituents
943+
},
944+
},
938945
}
939946
}

sdk/mx.sdk/mx_sdk_benchmark.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,23 +440,32 @@ def build_report_args(self, is_gate: bool, graalvm_edition: str):
440440
return ['--emit=build-report'] if is_gate and graalvm_edition == "ee" else []
441441

442442
def get_executable_name_and_output_dir_for_stage(self, stage: Stage, vm: NativeImageVM) -> Tuple[str, Path]:
443-
# Form executable name
444-
unique_suite_name = f"{self.bm_suite.benchSuiteName()}-{self.bm_suite.version().replace('.', '-')}" if self.bm_suite.version() != 'unknown' else self.bm_suite.benchSuiteName()
445-
executable_name = (
446-
unique_suite_name + '-' + self.benchmark_name).lower() if self.benchmark_name else unique_suite_name.lower()
443+
executable_name = self.compute_executable_name()
447444
is_shared_library = stage is not None and stage.is_layered() and stage.layer_info.is_shared_library
448445
if is_shared_library:
449446
# Shared library layers have to start with 'lib' and are differentiated with the layer index
450447
executable_name = f"lib-layer{stage.layer_info.index}-{executable_name}"
451448

452449
# Form output directory
453450
root_dir = Path(
454-
self.benchmark_output_dir if self.benchmark_output_dir else mx.suite('vm').get_output_root(platformDependent=False,
451+
self.benchmark_output_dir if self.benchmark_output_dir else mx.suite('sdk').get_output_root(platformDependent=False,
455452
jdkDependent=False)).absolute()
456453
output_dir = root_dir / "native-image-benchmarks" / f"{executable_name}-{vm.config_name()}"
457454

458455
return executable_name, output_dir
459456

457+
def compute_executable_name(self) -> str:
458+
result = self.bm_suite.executable_name()
459+
if result is not None:
460+
return result
461+
462+
parts = [self.bm_suite.benchSuiteName()]
463+
if self.bm_suite.version() != "unknown":
464+
parts.append(self.bm_suite.version().replace(".", "-"))
465+
if self.benchmark_name:
466+
parts.append(self.benchmark_name.replace(os.sep, "_"))
467+
return "-".join(parts).lower()
468+
460469
def get_build_output_json_file(self, stage: StageName) -> Path:
461470
"""
462471
Path to the build output statistics JSON file (see also ``-H:BuildOutputJSONFile``).
@@ -1810,6 +1819,11 @@ def _layerize_stages(self, bm_suite, bm_suite_args, stages: List[Stage]) -> List
18101819
return layered_stages
18111820

18121821

1822+
# Adds JAVA_HOME VMs so benchmarks can run on GraalVM binaries without building them first.
1823+
for java_home_config in ['default', 'pgo', 'g1gc', 'g1gc-pgo', 'upx', 'upx-g1gc', 'quickbuild', 'quickbuild-g1gc']:
1824+
mx_benchmark.add_java_vm(NativeImageVM('native-image-java-home', java_home_config), _suite, 5)
1825+
1826+
18131827
class ObjdumpSectionRule(mx_benchmark.StdOutRule):
18141828
PATTERN = re.compile(r"^ *(?P<section_num>\d+)[ ]+.(?P<section>[a-zA-Z0-9._-]+?) +(?P<size>[0-9a-f]+?) +",
18151829
re.MULTILINE)
@@ -4197,6 +4211,10 @@ def get_stage_env(self) -> Optional[dict]:
41974211
"""Return the environment to be used when executing a stage."""
41984212
return None
41994213

4214+
def executable_name(self) -> Optional[str]:
4215+
"""Override to allow suites to control the executable name used in image builds."""
4216+
return None
4217+
42004218

42014219
def measureTimeToFirstResponse(bmSuite):
42024220
protocolHost = bmSuite.serviceHost()
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 $<

0 commit comments

Comments
 (0)