Skip to content

Commit e568332

Browse files
committed
[GR-74917] Uncached interpreter benchmarks.
PullRequest: graalpython/4393
2 parents 41d3c31 + 7225496 commit e568332

8 files changed

Lines changed: 36 additions & 21 deletions

File tree

ci.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
[bench]: bench_task(bench) + platform_spec(no_jobs) + bench_variants({
335335
"vm_name:graalvm_ce_default_interpreter" : {"linux:amd64:jdk-latest" : on_demand + t("02:00:00")},
336336
"vm_name:graalvm_ee_default_interpreter" : {"linux:amd64:jdk-latest" : daily + t("02:00:00") + need_pgo},
337+
"vm_name:graalvm_ee_default_interpreter_uncached" : {"linux:amd64:jdk-latest" : daily + t("02:00:00") + need_pgo},
337338
"vm_name:graalpython_core_interpreter" : {"linux:amd64:jdk-latest" : on_demand + t("02:00:00")},
338339
"vm_name:graalpython_core_native_interpreter" : {"linux:amd64:jdk-latest" : on_demand + t("02:00:00")},
339340
"vm_name:graalpython_enterprise_interpreter" : {"linux:amd64:jdk-latest" : weekly + t("02:00:00")},

ci/constants.libsonnet

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
default_multi: "default-multi",
6262
interpreter: "interpreter",
6363
interpreter_manual: "interpreter-manual",
64+
interpreter_uncached: "interpreter-uncached",
6465
native_interpreter: "native-interpreter",
6566
native_interpreter_manual: "native-interpreter-manual",
6667
interpreter_multi: "interpreter-multi",
@@ -140,6 +141,10 @@
140141
python_vm: PYVM.graalpython,
141142
python_vm_config: PYVM_CONFIG.interpreter_manual,
142143
},
144+
graalpython_interpreter_uncached: {
145+
python_vm: PYVM.graalpython,
146+
python_vm_config: PYVM_CONFIG.interpreter_uncached,
147+
},
143148
graalpython_native_interpreter: {
144149
python_vm: PYVM.graalpython,
145150
python_vm_config: PYVM_CONFIG.native_interpreter,
@@ -239,6 +244,7 @@
239244
graalvm_ee_default: PYTHON_VM.graalpython + JVM_VM.graal_native_image_ee,
240245
graalvm_ee_default_manual: PYTHON_VM.graalpython_manual + JVM_VM.graal_native_image_ee,
241246
graalvm_ee_default_interpreter: PYTHON_VM.graalpython_interpreter + JVM_VM.graal_native_image_ee,
247+
graalvm_ee_default_interpreter_uncached: PYTHON_VM.graalpython_interpreter_uncached + JVM_VM.graal_native_image_ee,
242248
graalvm_ee_default_interpreter_manual: PYTHON_VM.graalpython_interpreter_manual + JVM_VM.graal_native_image_ee,
243249
graalvm_ce_default_multi_tier: PYTHON_VM.graalpython_multi_tier + JVM_VM.graal_native_image_ce,
244250
graalvm_ee_default_multi_tier: PYTHON_VM.graalpython_multi_tier + JVM_VM.graal_native_image_ee,

graalpython/com.oracle.graal.python.benchmarks/python/harness.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ def run_benchmark(args):
510510

511511
if GRAALPYTHON:
512512
print(f"### using bytecode DSL interpreter: {__graalpython__.is_bytecode_dsl_interpreter}")
513+
print(f"### using forced uncached interpreter: {getattr(__graalpython__, "is_forced_uncached_interpreter", False)}")
513514

514515
BenchRunner(bench_file, bench_args=bench_args, iterations=iterations, warmup=warmup, warmup_runs=warmup_runs, startup=startup, live_results=live_results, self_measurement=self_measurement).run()
515516

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ public void initialize(Python3Core core) {
238238
addBuiltinConstant("is_native", TruffleOptions.AOT);
239239
addBuiltinConstant("is_bytecode_dsl_interpreter", PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER);
240240
PythonContext ctx = core.getContext();
241-
TruffleString encodingOpt = ctx.getLanguage().getEngineOption(PythonOptions.StandardStreamEncoding);
241+
PythonLanguage language = ctx.getLanguage();
242+
// Engine options: if they differ from the values baked into the pre-initialized context,
243+
// this `initialize` method is run again.
244+
addBuiltinConstant("is_forced_uncached_interpreter", language.getEngineOption(PythonOptions.ForceUncachedInterpreter));
245+
TruffleString encodingOpt = language.getEngineOption(PythonOptions.StandardStreamEncoding);
242246
TruffleString standardStreamEncoding = null;
243247
TruffleString standardStreamError = null;
244248
if (encodingOpt != null && !encodingOpt.isEmpty()) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,7 @@ public void setMetadata(BytecodeDSLCodeUnit co, ParserCallbacksImpl parserErrorC
446446
}
447447
instrumentationDataIndex = co.instrumentationDataIndex;
448448
yieldFromGeneratorIndex = co.yieldFromGeneratorIndex;
449-
if (PythonOptions.UNCACHED_BYTECODE_DSL_INTERPRETER_LIMIT != -1) {
450-
getBytecodeNode().setUncachedThreshold(PythonOptions.UNCACHED_BYTECODE_DSL_INTERPRETER_LIMIT);
451-
}
449+
PythonOptions.setUncachedInterpreterThreshold(getLanguage(), getBytecodeNode());
452450
}
453451

454452
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6363
import com.oracle.truffle.api.Option;
6464
import com.oracle.truffle.api.TruffleLanguage.Env;
65+
import com.oracle.truffle.api.bytecode.BytecodeNode;
6566
import com.oracle.truffle.api.dsl.Idempotent;
6667
import com.oracle.truffle.api.exception.AbstractTruffleException;
6768
import com.oracle.truffle.api.nodes.ExplodeLoop;
@@ -88,7 +89,6 @@ public final class PythonOptions {
8889
* bytecode interpreter.
8990
*/
9091
public static final boolean ENABLE_BYTECODE_DSL_INTERPRETER;
91-
public static final int UNCACHED_BYTECODE_DSL_INTERPRETER_LIMIT;
9292
private static final OptionType<TruffleString> TS_OPTION_TYPE = new OptionType<>("graal.python.TruffleString", PythonUtils::toTruffleStringUncached);
9393

9494
static {
@@ -107,17 +107,6 @@ public final class PythonOptions {
107107
} else {
108108
ENABLE_BYTECODE_DSL_INTERPRETER = true;
109109
}
110-
111-
if (Boolean.getBoolean("python.ForceUncachedInterpreter")) {
112-
UNCACHED_BYTECODE_DSL_INTERPRETER_LIMIT = Integer.MIN_VALUE;
113-
} else {
114-
String uncachedLimitStr = System.getProperty("python.UncachedInterpreterLimit");
115-
if (uncachedLimitStr != null) {
116-
UNCACHED_BYTECODE_DSL_INTERPRETER_LIMIT = Integer.parseInt(uncachedLimitStr);
117-
} else {
118-
UNCACHED_BYTECODE_DSL_INTERPRETER_LIMIT = -1;
119-
}
120-
}
121110
}
122111

123112
private PythonOptions() {
@@ -445,6 +434,12 @@ public static void checkBytecodeDSLEnv() {
445434
such as when settrace instrumentation is enabled. This option avoids rereading bytecode files by keeping the original bytecode form in memory""") //
446435
public static final OptionKey<Boolean> KeepBytecodeInMemory = new OptionKey<>(false);
447436

437+
@EngineOption @Option(category = OptionCategory.INTERNAL, help = "", stability = OptionStability.EXPERIMENTAL) //
438+
public static final OptionKey<Boolean> ForceUncachedInterpreter = new OptionKey<>(false);
439+
440+
@EngineOption @Option(category = OptionCategory.INTERNAL, help = "", stability = OptionStability.EXPERIMENTAL) //
441+
public static final OptionKey<Integer> UncachedInterpreterThreshold = new OptionKey<>(-1);
442+
448443
public static final OptionDescriptors DESCRIPTORS = new PythonOptionsOptionDescriptors();
449444

450445
@CompilationFinal(dimensions = 1) private static final OptionKey<?>[] ENGINE_OPTION_KEYS;
@@ -546,6 +541,16 @@ public static boolean areOptionsCompatible(OptionValues first, OptionValues seco
546541
return true;
547542
}
548543

544+
public static void setUncachedInterpreterThreshold(PythonLanguage language, BytecodeNode bytecodeNode) {
545+
if (language.getEngineOption(ForceUncachedInterpreter)) {
546+
bytecodeNode.setUncachedThreshold(Integer.MIN_VALUE);
547+
}
548+
int threshold = language.getEngineOption(UncachedInterpreterThreshold);
549+
if (threshold >= 0) {
550+
bytecodeNode.setUncachedThreshold(threshold);
551+
}
552+
}
553+
549554
@Idempotent
550555
public static int getAttributeAccessInlineCacheMaxDepth() {
551556
CompilerAsserts.neverPartOfCompilation();

mx.graalpython/mx_graalpython.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ def github_ci_build_args():
286286

287287
def libpythonvm_build_args():
288288
build_args = bytecode_dsl_build_args()
289-
290-
if limit := os.environ.get('GRAALPY_UncachedInterpreterLimit'):
291-
mx.log(f"Uncached interpreter limit explicitly set to {limit}")
292-
build_args += [f'-Dpython.UncachedInterpreterLimit={limit}']
293-
294289
if os.environ.get("GITHUB_CI"):
295290
build_args += github_ci_build_args()
296291

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
CONFIGURATION_NATIVE_INTERPRETER_MULTI = "native-interpreter-multi"
7272
CONFIGURATION_DEFAULT_MULTI_TIER = "default-multi-tier"
7373
CONFIGURATION_NATIVE = "native"
74+
CONFIGURATION_UNCACHED = "interpreter-uncached"
7475
CONFIGURATION_NATIVE_MULTI = "native-multi"
7576
CONFIGURATION_NATIVE_MULTI_TIER = "native-multi-tier"
7677
CONFIGURATION_SANDBOXED = "sandboxed"
@@ -335,6 +336,9 @@ def extract_vm_info(self, args=None):
335336
def run(self, *args, **kwargs):
336337
code, out, dims = super().run(*args, **kwargs)
337338
dims.update(self._dims)
339+
is_uncached_config = self.config_name().startswith(CONFIGURATION_UNCACHED)
340+
if ("forced uncached interpreter: True" not in out) == is_uncached_config:
341+
mx.abort(f"ERROR: benchmark config '{CONFIGURATION_UNCACHED}' not consistent with what runtime reported.")
338342
return code, out, dims
339343

340344
def get_extra_polyglot_args(self):
@@ -1084,6 +1088,7 @@ def add_graalpy_vm(name, *extra_polyglot_args):
10841088
add_graalpy_vm(CONFIGURATION_DEFAULT_MULTI_TIER, '--experimental-options', '--engine.MultiTier=true')
10851089
add_graalpy_vm(CONFIGURATION_SANDBOXED, *sandboxed_options)
10861090
add_graalpy_vm(CONFIGURATION_NATIVE)
1091+
add_graalpy_vm(CONFIGURATION_UNCACHED, '--experimental-options', '--engine.Compilation=false', '--python.ForceUncachedInterpreter=true')
10871092
add_graalpy_vm(CONFIGURATION_NATIVE_INTERPRETER, '--experimental-options', '--engine.Compilation=false')
10881093
add_graalpy_vm(CONFIGURATION_SANDBOXED_MULTI, '--experimental-options', '-multi-context', *sandboxed_options)
10891094
add_graalpy_vm(CONFIGURATION_NATIVE_MULTI, '--experimental-options', '-multi-context')

0 commit comments

Comments
 (0)