Skip to content

Commit 4ec59b2

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Schedule compilation for existing functions on JIT startup
Summary: This is already done when calling `cinderx.jit.auto()`, `cinderx.jit.compile_after_n_calls()`, `cinderx.jit.append_jit_list()`, or `cinderx.jit.read_jit_list()`. But it's not run when the JIT is configured to run automatically through environment variables. Oops. Reviewed By: DinoV Differential Revision: D91380488 fbshipit-source-id: e820418f5cd44eb67a7e24cd7d97d03ff66a0443
1 parent 185236a commit 4ec59b2

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

cinderx/Jit/pyjit.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,17 @@ void deleteJitList() {
18901890
cinderx::getModuleState()->setJitList(nullptr);
18911891
}
18921892

1893+
// Reschedule all functions on the JIT list for compilation. Run when the JIT
1894+
// list is modified.
1895+
void rescheduleJitList() {
1896+
walkFunctionObjects([](BorrowedRef<PyFunctionObject> func) {
1897+
auto jit_list = cinderx::getModuleState()->jitList();
1898+
if (jit_list->lookupFunc(func)) {
1899+
scheduleJitCompile(func);
1900+
}
1901+
});
1902+
}
1903+
18931904
PyObject* append_jit_list(PyObject* /* self */, PyObject* arg) {
18941905
if (!PyUnicode_Check(arg)) {
18951906
PyErr_Format(
@@ -1921,14 +1932,7 @@ PyObject* append_jit_list(PyObject* /* self */, PyObject* arg) {
19211932
return nullptr;
19221933
}
19231934

1924-
// Reset existing functions to have the JIT vectorcall entrypoint again if
1925-
// they're now on the JIT list.
1926-
walkFunctionObjects([](BorrowedRef<PyFunctionObject> func) {
1927-
auto jit_list = cinderx::getModuleState()->jitList();
1928-
if (jit_list->lookupFunc(func)) {
1929-
scheduleJitCompile(func);
1930-
}
1931-
});
1935+
rescheduleJitList();
19321936

19331937
Py_RETURN_NONE;
19341938
}
@@ -1964,14 +1968,7 @@ PyObject* read_jit_list(PyObject* /* self */, PyObject* arg) {
19641968
return nullptr;
19651969
}
19661970

1967-
// Reset existing functions to have the JIT vectorcall entrypoint again if
1968-
// they're now on the JIT list.
1969-
walkFunctionObjects([](BorrowedRef<PyFunctionObject> func) {
1970-
auto jit_list = cinderx::getModuleState()->jitList();
1971-
if (jit_list->lookupFunc(func)) {
1972-
scheduleJitCompile(func);
1973-
}
1974-
});
1971+
rescheduleJitList();
19751972

19761973
Py_RETURN_NONE;
19771974
}
@@ -3378,6 +3375,15 @@ int initialize() {
33783375

33793376
mod_state->setJitList(std::move(jit_list));
33803377

3378+
// JIT is now fully initialized. If it was configured to run automatically on
3379+
// startup, start scheduling functions for compilation now.
3380+
if (auto compile_n = getConfig().compile_after_n_calls;
3381+
compile_n.has_value()) {
3382+
compile_after_n_calls_impl(*compile_n);
3383+
} else if (mod_state->jitList() != nullptr) {
3384+
rescheduleJitList();
3385+
}
3386+
33813387
return 0;
33823388
}
33833389

0 commit comments

Comments
 (0)