Skip to content

Commit 684c823

Browse files
committed
[GR-68957] [GR-69800] Various polybench QOL/correctness fixes.
PullRequest: graal/22181
2 parents 69785bf + 33c7778 commit 684c823

File tree

7 files changed

+237
-121
lines changed

7 files changed

+237
-121
lines changed

common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
55
],
66

7-
"mx_version": "7.61.0",
7+
"mx_version": "7.62.0",
88

99
"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
1010
"jdks": {

sdk/mx.sdk/mx_sdk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
200200

201201
def mx_post_parse_cmd_line(args):
202202
mx_sdk_vm_impl.mx_post_parse_cmd_line(args)
203+
mx_sdk_benchmark.register_graalvm_vms()
203204

204205

205206
mx.update_commands(_suite, {

sdk/mx.sdk/mx_sdk_benchmark.py

Lines changed: 88 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ def post_process_command_line_args(self, args):
157157
return [arg if not callable(arg) else arg() for arg in self.extra_args] + args
158158

159159
def get_jdk(self):
160+
if self.run_on_java_home():
161+
# forcing the use of the default JAVA_HOME VM as runtime instead of the one pointed at by the tag
162+
return mx.get_jdk()
160163
tag = mx.get_jdk_option().tag
161164
if tag and tag != JVMCI_JDK_TAG:
162165
mx.abort("The '{0}/{1}' VM requires '--jdk={2}'".format(
@@ -254,7 +257,7 @@ def post_process_launcher_command_line_args(self, args):
254257
args
255258

256259
def home(self):
257-
if self.name() == 'native-image-java-home':
260+
if self.run_on_java_home() or self.name() == 'native-image-java-home':
258261
return mx.get_jdk().home
259262
return mx_sdk_vm_impl.graalvm_home(fatalIfMissing=True)
260263

@@ -341,18 +344,24 @@ def __init__(self, vm: NativeImageVM, bm_suite: BenchmarkSuite | NativeImageBenc
341344
self.skip_agent_assertions = bm_suite.skip_agent_assertions(self.benchmark_name, args)
342345
current_stage = vm.stages_info.current_stage
343346
is_shared_library = current_stage is not None and current_stage.is_layered() and current_stage.layer_info.is_shared_library
347+
# base image name (used for auxiliary output files)
348+
base_image_name = self.bm_suite.get_base_image_name(shared_library_layer_index=current_stage.layer_info.index if is_shared_library else None)
349+
# full image name qualified with vm suffix (passed as -o argument to native-image)
350+
self.final_image_name = self.bm_suite.get_full_image_name(base_image_name, vm.config_name())
351+
# root directory for all output. can be overridden with -Dnative-image.benchmark.benchmark-output-dir
344352
self.benchmark_output_dir = self.bm_suite.benchmark_output_dir(self.benchmark_name, args)
345-
executable_name, output_dir = self.get_executable_name_and_output_dir_for_stage(current_stage, vm)
346-
self.executable_name: str = executable_name
347-
self.output_dir: Path = output_dir
348-
self.final_image_name = self.executable_name + '-' + vm.config_name()
349-
self.profile_path: Path = self.output_dir / f"{self.executable_name}.iprof"
350-
self.source_mappings_path: Path = self.output_dir / f"{self.executable_name}.sourceMappings.json"
351-
self.perf_script_path: Path = self.output_dir / f"{self.executable_name}.perf.script.out"
352-
self.perf_data_path: Path = self.output_dir / f"{self.executable_name}.perf.data"
353+
# specific directory with output for this image build.
354+
self.output_dir: Path = self.bm_suite.get_image_output_dir(self.benchmark_output_dir, self.final_image_name)
355+
# path of the final executable.
356+
self.image_path: Path = self.output_dir / self.bm_suite.get_image_file_name(self.final_image_name, shared_library=is_shared_library)
357+
self.instrumented_image_path = self.output_dir / self.bm_suite.get_image_file_name(f"{base_image_name}-instrument")
358+
self.profile_path: Path = self.output_dir / f"{base_image_name}.iprof"
359+
self.source_mappings_path: Path = self.output_dir / f"{base_image_name}.sourceMappings.json"
360+
self.perf_script_path: Path = self.output_dir / f"{base_image_name}.perf.script.out"
361+
self.perf_data_path: Path = self.output_dir / f"{base_image_name}.perf.data"
353362
self.config_dir: Path = self.output_dir / "config"
354363
self.log_dir: Path = self.output_dir
355-
self.ml_log_dump_path: Path = self.output_dir / f"{self.executable_name}.ml.log.csv"
364+
self.ml_log_dump_path: Path = self.output_dir / f"{base_image_name}.ml.log.csv"
356365
base_image_build_args = ['--no-fallback']
357366
if not vm.pgo_use_perf:
358367
# Can only have debug info when not using perf, [GR-66850]
@@ -405,13 +414,6 @@ def __init__(self, vm: NativeImageVM, bm_suite: BenchmarkSuite | NativeImageBenc
405414

406415
self.image_build_reports_directory: Path = self.output_dir / "reports"
407416

408-
# Path of the final executable
409-
self.image_path = self.output_dir / self.final_image_name
410-
self.instrumented_image_path = self.output_dir / f"{self.executable_name}-instrument"
411-
if is_shared_library:
412-
self.image_path = self.image_path.parent / f"{self.image_path.name}.so"
413-
self.instrumented_image_path = self.instrumented_image_path.parent / f"{self.instrumented_image_path.name}.so"
414-
415417
if vm.is_quickbuild:
416418
base_image_build_args += ['-Ob']
417419
if vm.graalos or vm.graalhost_graalos:
@@ -465,33 +467,6 @@ def build_report_args(self, is_gate: bool, graalvm_edition: str):
465467
# Generate Build Report only when the benchmark is a part of EE gate.
466468
return ['--emit=build-report'] if is_gate and graalvm_edition == "ee" else []
467469

468-
def get_executable_name_and_output_dir_for_stage(self, stage: Stage, vm: NativeImageVM) -> Tuple[str, Path]:
469-
executable_name = self.compute_executable_name()
470-
is_shared_library = stage is not None and stage.is_layered() and stage.layer_info.is_shared_library
471-
if is_shared_library:
472-
# Shared library layers have to start with 'lib' and are differentiated with the layer index
473-
executable_name = f"lib-layer{stage.layer_info.index}-{executable_name}"
474-
475-
# Form output directory
476-
root_dir = Path(
477-
self.benchmark_output_dir if self.benchmark_output_dir else mx.suite('sdk').get_output_root(platformDependent=False,
478-
jdkDependent=False)).absolute()
479-
output_dir = root_dir / "native-image-benchmarks" / f"{executable_name}-{vm.config_name()}"
480-
481-
return executable_name, output_dir
482-
483-
def compute_executable_name(self) -> str:
484-
result = self.bm_suite.executable_name()
485-
if result is not None:
486-
return result
487-
488-
parts = [self.bm_suite.benchSuiteName()]
489-
if self.bm_suite.version() != "unknown":
490-
parts.append(self.bm_suite.version().replace(".", "-"))
491-
if self.benchmark_name:
492-
parts.append(self.benchmark_name.replace(os.sep, "_"))
493-
return "-".join(parts).lower()
494-
495470
def get_build_output_json_file(self, stage: StageName) -> Path:
496471
"""
497472
Path to the build output statistics JSON file (see also ``-H:BuildOutputJSONFile``).
@@ -1638,7 +1613,10 @@ def get_layer_aware_build_args(self) -> List[str]:
16381613
mx.abort("Failed to find any shared library layer image stages!")
16391614
layer_output_dirs = []
16401615
for stage in shared_library_stages:
1641-
_, stage_output_dir = self.config.get_executable_name_and_output_dir_for_stage(stage, self)
1616+
assert isinstance(self.bmSuite, NativeImageBenchmarkMixin)
1617+
layer_base_image_name = self.bmSuite.get_base_image_name(shared_library_layer_index=stage.layer_info.index)
1618+
layer_full_image_name = self.bmSuite.get_full_image_name(layer_base_image_name, self.config_name())
1619+
stage_output_dir = self.bmSuite.get_image_output_dir(self.config.benchmark_output_dir, layer_full_image_name)
16421620
layer_output_dirs.append(stage_output_dir.absolute().as_posix())
16431621
linker_r_path = ",".join(layer_output_dirs)
16441622
app_layer_build_args = [f"-H:LinkerRPath={linker_r_path}"]
@@ -1845,9 +1823,29 @@ def _layerize_stages(self, bm_suite, bm_suite_args, stages: List[Stage]) -> List
18451823
return layered_stages
18461824

18471825

1848-
# Adds JAVA_HOME VMs so benchmarks can run on GraalVM binaries without building them first.
1849-
for java_home_config in ['default', 'pgo', 'g1gc', 'g1gc-pgo', 'upx', 'upx-g1gc', 'quickbuild', 'quickbuild-g1gc']:
1850-
mx_benchmark.add_java_vm(NativeImageVM('native-image-java-home', java_home_config), _suite, 5)
1826+
def register_graalvm_vms():
1827+
# a simple JVM config that runs without any custom flag
1828+
mx_benchmark.add_java_vm(JvmciJdkVm('server', 'vanilla', []), _suite, 2)
1829+
1830+
for java_home_config in ['default', 'pgo', 'g1gc', 'g1gc-pgo', 'upx', 'upx-g1gc', 'quickbuild', 'quickbuild-g1gc']:
1831+
mx_benchmark.add_java_vm(NativeImageVM('native-image-java-home', java_home_config), _suite)
1832+
1833+
optimization_levels = ['O0', 'O1', 'O2', 'O3', 'Os']
1834+
analysis_context_sensitivity = ['insens', 'allocsens', '1obj', '2obj1h', '3obj2h', '4obj3h']
1835+
1836+
for short_name, config_suffix in [(None, ''), ('niee', '-ee'), ('ni', '-ce')]:
1837+
if short_name is None or any(component.short_name == short_name for component in mx_sdk_vm_impl.registered_graalvm_components(stage1=False)):
1838+
config_names = list()
1839+
for main_config in ['default', 'gate', 'llvm', 'native-architecture', 'future-defaults-all', 'preserve-all', 'preserve-classpath'] + analysis_context_sensitivity + (['g1gc', 'pgo', 'g1gc-pgo'] if config_suffix != '-ce' else []):
1840+
config_names.append(f'{main_config}{config_suffix}')
1841+
1842+
for optimization_level in optimization_levels:
1843+
config_names.append(f'{optimization_level}{config_suffix}')
1844+
for main_config in ['llvm', 'native-architecture', 'g1gc', 'native-architecture-g1gc', 'preserve-all', 'preserve-classpath'] + analysis_context_sensitivity:
1845+
config_names.append(f'{main_config}-{optimization_level}{config_suffix}')
1846+
1847+
for config_name in config_names:
1848+
mx_benchmark.add_java_vm(NativeImageVM('native-image', config_name, ['--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED']), _suite, 10)
18511849

18521850

18531851
class ObjdumpSectionRule(mx_benchmark.StdOutRule):
@@ -4196,7 +4194,7 @@ def benchmark_output_dir(self, _, args):
41964194
if parsed_args:
41974195
return parsed_args[0]
41984196
else:
4199-
return None
4197+
return mx.suite('sdk').get_output_root(platformDependent=False, jdkDependent=False)
42004198

42014199
def filter_stages_with_cli_requested_stages(self, bm_suite_args: List[str], stages: List[Stage]) -> List[Stage]:
42024200
"""
@@ -4252,9 +4250,47 @@ def get_stage_env(self) -> Optional[dict]:
42524250
"""Return the environment to be used when executing a stage."""
42534251
return None
42544252

4255-
def executable_name(self) -> Optional[str]:
4256-
"""Override to allow suites to control the executable name used in image builds."""
4257-
return None
4253+
def _base_image_name(self: BenchmarkSuite | NativeImageBenchmarkMixin) -> str:
4254+
"""
4255+
Returns the name to use in image builds. May be overridden.
4256+
Note that this name is not necessarily the full image name (there may be prefixes/suffixes added).
4257+
Use `get_image_path` to obtain the final image path.
4258+
"""
4259+
parts = [self.benchSuiteName()]
4260+
if self.version() != "unknown":
4261+
parts.append(self.version().replace(".", "-"))
4262+
parts.append(self.benchmarkName())
4263+
return "-".join(parts).lower()
4264+
4265+
def get_base_image_name(self, shared_library_layer_index: Optional[int] = None) -> str:
4266+
"""
4267+
Returns the base image name to use for auxiliary build files (e.g., iprof files).
4268+
"""
4269+
base_image_name = self._base_image_name()
4270+
if shared_library_layer_index is not None:
4271+
# Shared library layers have to start with 'lib' and are differentiated with the layer index
4272+
base_image_name = f"lib-layer{shared_library_layer_index}-{base_image_name}"
4273+
return base_image_name
4274+
4275+
def get_full_image_name(self, base_image_name: str, vm_config: str) -> str:
4276+
"""
4277+
Returns the base image name qualified by the vm suffix. This name is passed as the -o argument to native-image.
4278+
"""
4279+
return f"{base_image_name}-{vm_config}"
4280+
4281+
def get_image_file_name(self, full_image_name: str, shared_library: bool = False) -> str:
4282+
"""
4283+
Returns the file name of the generated image.
4284+
"""
4285+
if shared_library:
4286+
return f"{full_image_name}.so"
4287+
return full_image_name
4288+
4289+
def get_image_output_dir(self, benchmark_output_dir: str, full_image_name: str) -> Path:
4290+
"""
4291+
Returns the output directory for the given image name, as a subdirectory of the root output directory.
4292+
"""
4293+
return Path(benchmark_output_dir).absolute() / "native-image-benchmarks" / full_image_name
42584294

42594295

42604296
def measureTimeToFirstResponse(bmSuite):

0 commit comments

Comments
 (0)