1
1
#
2
- # Copyright (c) 2016, 2023 , Oracle and/or its affiliates.
2
+ # Copyright (c) 2016, 2025 , Oracle and/or its affiliates.
3
3
#
4
4
# All rights reserved.
5
5
#
35
35
import os
36
36
from os .path import join , exists
37
37
38
+ import mx_polybench
38
39
import mx_subst
39
40
from mx_benchmark import VmRegistry , java_vm_registry , Vm , GuestVm , VmBenchmarkSuite
40
41
@@ -63,25 +64,11 @@ def _parse_results_gen():
63
64
yield r
64
65
return (x for x in _parse_results_gen ())
65
66
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 []
79
67
80
68
class SulongBenchmarkSuite (VmBenchmarkSuite ):
81
- def __init__ (self , use_polybench , * args , ** kwargs ):
69
+ def __init__ (self , * args , ** kwargs ):
82
70
super (SulongBenchmarkSuite , self ).__init__ (* args , ** kwargs )
83
71
self .bench_to_exec = {}
84
- self .use_polybench = use_polybench
85
72
86
73
def group (self ):
87
74
return 'Graal'
@@ -90,7 +77,7 @@ def subgroup(self):
90
77
return 'sulong'
91
78
92
79
def name (self ):
93
- return 'csuite-polybench' if self . use_polybench else 'csuite '
80
+ return 'csuite'
94
81
95
82
def run (self , benchnames , bmSuiteArgs ):
96
83
vm = self .get_vm_registry ().get_vm_from_suite_args (bmSuiteArgs )
@@ -116,9 +103,6 @@ def run(self, benchnames, bmSuiteArgs):
116
103
env = vm .prepare_env (env )
117
104
118
105
outName = vm .out_file ()
119
- if self .use_polybench :
120
- env ['POLYBENCH' ] = 'y'
121
- outName += '.so'
122
106
out = os .path .join (bench_out_dir , outName )
123
107
cmdline = ['make' , '-f' , '../Makefile' , out ]
124
108
if mx ._opts .verbose :
@@ -155,25 +139,15 @@ def flakySkipPatterns(self, benchmarks, bmSuiteArgs):
155
139
# preparatory benchmark is run using the llimul launcher and passing --multi-context-runs=0.
156
140
# We can capture this argument here and instruct the benchmark infrastructure to ignore
157
141
# 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 )]
164
144
return []
165
145
166
146
def flakySuccessPatterns (self ):
167
147
# bzip2 is known to have a compiler error during OSR compilation, but peak numbers are still valid
168
148
return [re .compile (r'Compilation of sendMTFValues<OSR@\d+> failed' )] # GR-38646
169
149
170
150
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 ):
177
151
return [
178
152
SulongBenchmarkRule (
179
153
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):
243
217
}),
244
218
]
245
219
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
-
273
220
def _get_metric_name (self , bmSuiteArgs ):
274
221
metric = None
275
222
for arg in bmSuiteArgs :
@@ -292,11 +239,7 @@ def workingDirectory(self, benchmarks, bmSuiteArgs):
292
239
vm = self .get_vm_registry ().get_vm_from_suite_args (bmSuiteArgs )
293
240
assert isinstance (vm , CExecutionEnvironmentMixin )
294
241
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 ())
300
243
301
244
def createCommandLineArgs (self , benchmarks , bmSuiteArgs ):
302
245
if len (benchmarks ) != 1 :
@@ -307,15 +250,14 @@ def createCommandLineArgs(self, benchmarks, bmSuiteArgs):
307
250
vmArgs = self .vmArgs (bmSuiteArgs )
308
251
runArgs = self .runArgs (bmSuiteArgs )
309
252
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 ))]
312
254
except :
313
255
# We can end up here in case the python version we're running on doesn't have clock_gettime or CLOCK_REALTIME.
314
256
pass
315
257
return vmArgs + [self .bench_to_exec [benchmarks [0 ]]] + runArgs
316
258
317
259
def get_vm_registry (self ):
318
- return native_polybench_vm_registry if self . use_polybench else native_vm_registry
260
+ return native_vm_registry
319
261
320
262
321
263
class CExecutionEnvironmentMixin (object ):
@@ -540,93 +482,6 @@ def hosting_registry(self):
540
482
return java_vm_registry
541
483
542
484
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
-
630
485
class LLVMUnitTestsSuite (VmBenchmarkSuite ):
631
486
def __init__ (self , * args , ** kwargs ):
632
487
super (LLVMUnitTestsSuite , self ).__init__ (* args , ** kwargs )
@@ -755,25 +610,32 @@ def hosting_registry(self):
755
610
native_vm_registry .add_vm (SulongVm ('default-O2' , [], cflags = ['-O2' , '-fno-vectorize' , '-fno-slp-vectorize' ]), _suite , 10 )
756
611
native_vm_registry .add_vm (SulongVm ('default-O3' , [], cflags = ['-O3' , '-fno-vectorize' , '-fno-slp-vectorize' ]), _suite , 10 )
757
612
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
-
778
613
lit_vm_registry = VmRegistry ("Lit" , known_host_registries = [java_vm_registry ])
779
614
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