Skip to content

Commit dec2678

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Make background compile the default
Summary: This makes background compilation the default mode that we run under. We disable it in IG and in tests where it throws off the expectations. We keep it enabled in the `jit-auto` variation and add a `dev` build run pass that runs in this mode (where we were previous missing any significant coverage). Reviewed By: alexmalyshev Differential Revision: D114134434 fbshipit-source-id: 1d50c8a8d8572290f19c0234216006e5bb681a57
1 parent 21bd3be commit dec2678

8 files changed

Lines changed: 35 additions & 10 deletions

File tree

cinderx/Jit/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct Config {
205205
// the GIL, instead of compiling inline on the calling thread. The calling
206206
// thread keeps running through the interpreter until the background
207207
// compilation finishes and swaps in the JIT-compiled entry point.
208-
bool background_compile{false};
208+
bool background_compile{true};
209209
// When a function is being compiled, this is the maximum number of dependent
210210
// functions called by it that can be compiled along with it.
211211
size_t preload_dependent_limit{99};

cinderx/PythonLib/test_cinderx/test_compiler/test_static/test_compile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5369,7 +5369,10 @@ def f4():
53695369
"main.py",
53705370
]
53715371
proc = subprocess.run(
5372-
cmd, capture_output=True, cwd=str(d), env=subprocess_env()
5372+
cmd,
5373+
capture_output=True,
5374+
cwd=str(d),
5375+
env={"CINDERX_JIT_BACKGROUND_COMPILE": "0", **subprocess_env()},
53735376
)
53745377
self.assertEqual(proc.returncode, 0, proc.stderr)
53755378

cinderx/PythonLib/test_cinderx/test_free_threading/test_free_threading.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313

1414
class FibonacciTest(unittest.TestCase):
15+
def setUp(self):
16+
self.bg_compile = cinderx.jit.get_background_compile()
17+
cinderx.jit.background_compile(False)
18+
19+
def tearDown(self):
20+
cinderx.jit.background_compile(self.bg_compile)
21+
1522
@unittest.skipUnless(hasattr(os, "fork"), "fork not available on Windows")
1623
@run_in_subprocess
1724
def test_concurrent_calls_trigger_jit_compilation(self) -> None:

cinderx/PythonLib/test_cinderx/test_jit_disable.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def inc(x):
265265
subprocess.run(
266266
[sys.executable, str(test_file)],
267267
check=True,
268-
env=subprocess_env(),
268+
env={"CINDERX_JIT_BACKGROUND_COMPILE": "0", **subprocess_env()},
269269
)
270270

271271
def test_auto_predefined(self) -> None:
@@ -298,7 +298,7 @@ def predefined(x):
298298
subprocess.run(
299299
[sys.executable, str(test_file)],
300300
check=True,
301-
env=subprocess_env(),
301+
env={"CINDERX_JIT_BACKGROUND_COMPILE": "0", **subprocess_env()},
302302
)
303303

304304
def test_compile_after_n_calls(self) -> None:
@@ -348,7 +348,7 @@ def dec(x):
348348
subprocess.run(
349349
[sys.executable, str(test_file)],
350350
check=True,
351-
env=subprocess_env(),
351+
env={"CINDERX_JIT_BACKGROUND_COMPILE": "0", **subprocess_env()},
352352
)
353353

354354
def test_compile_after_n_calls_predefined(self) -> None:
@@ -381,7 +381,7 @@ def predefined(x):
381381
subprocess.run(
382382
[sys.executable, str(test_file)],
383383
check=True,
384-
env=subprocess_env(),
384+
env={"CINDERX_JIT_BACKGROUND_COMPILE": "0", **subprocess_env()},
385385
)
386386

387387

cinderx/PythonLib/test_cinderx/test_jit_preload.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ def test_func_destroyed_during_preload_multiprocessing(self) -> None:
6060
cwd=os.path.dirname(__file__),
6161
capture_output=True,
6262
encoding=ENCODING,
63-
env={**subprocess_env(), "DISABLE_LAZY_IMPORTS": "1"},
63+
env={
64+
**subprocess_env(),
65+
"DISABLE_LAZY_IMPORTS": "1",
66+
"CINDERX_JIT_BACKGROUND_COMPILE": "0",
67+
},
6468
)
6569
self.assertEqual(proc.returncode, 0, proc.stderr)
6670
self.assertIn("ok ", proc.stdout, proc.stdout)
@@ -88,7 +92,11 @@ def test_func_destroyed_during_preload(self) -> None:
8892
# DISABLE_LAZY_IMPORTS prevents the safer_lazy_imports startup
8993
# function from overriding -L with selective lazy imports, which
9094
# would make the helper modules' imports eager and break this test.
91-
env={**subprocess_env(), "DISABLE_LAZY_IMPORTS": "1"},
95+
env={
96+
**subprocess_env(),
97+
"DISABLE_LAZY_IMPORTS": "1",
98+
"CINDERX_JIT_BACKGROUND_COMPILE": "0",
99+
},
92100
)
93101
self.assertEqual(proc.returncode, 0)
94102
expected_stdout = """resolving a_func

cinderx/PythonLib/test_cinderx/test_jitlist.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
"Expecting functions to compile on first call",
3434
)
3535
class JitListTest(unittest.TestCase):
36+
def setUp(self):
37+
self.bg_compile = cinderx.jit.get_background_compile()
38+
cinderx.jit.background_compile(False)
39+
40+
def tearDown(self):
41+
cinderx.jit.background_compile(self.bg_compile)
42+
3643
def test_comments(self) -> None:
3744
cinderx.jit.append_jit_list("")
3845
initial_jit_list = cinderx.jit.get_jit_list()

cinderx/TestScripts/test_hir_stats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fi
2525

2626
function run_workload() {
2727
# Run through cinder_test_runner to skip tests known to break in JIT
28-
PYTHONJITDUMPHIRSTATS=1 PYTHONJITALL=1 PYTHONJITDEBUG=1 \
28+
CINDERX_JIT_BACKGROUND_COMPILE=0 PYTHONJITDUMPHIRSTATS=1 PYTHONJITALL=1 PYTHONJITDEBUG=1 \
2929
buck run @//mode/opt "fbcode//cinderx:python$PYTHON_VERSION" -- cinder_test_runner.py test "$@" -- --randseed=1
3030
}
3131

cinderx/TestScripts/test_multithreaded_compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cd "$(dirname "$(readlink -f "$0")")"/../PythonLib
99

1010
function run() {
1111
local mode=$1
12-
buck2 run @fbcode//mode/"${mode}" fbcode//cinderx:python3.12 -- -X cinderx-jit-all -X cinderx-jit-multithreaded-compile-test -X cinderx-jit-batch-compile-workers="${WORKERS}" -m test_cinderx.multithreaded_compile_test
12+
buck2 run @fbcode//mode/"${mode}" fbcode//cinderx:python3.12 -- -X cinderx-jit-background-compile=0 -X cinderx-jit-all -X cinderx-jit-multithreaded-compile-test -X cinderx-jit-batch-compile-workers="${WORKERS}" -m test_cinderx.multithreaded_compile_test
1313
}
1414

1515
# TASK(T186691817): There should be at least one run with TSAN but we don't have

0 commit comments

Comments
 (0)