8000 GH-112354: Initial implementation of warm up on exits and trace-stitching by markshannon · Pull Request #114142 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

GH-112354: Initial implementation of warm up on exits and trace-stitching #114142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1975b4c
Cold exits: Work in progress.
markshannon Jan 10, 2024
9fb97f7
Merge branch 'main' into cold-exits
markshannon Jan 11, 2024
f9aa235
Optimize on side exits
markshannon Jan 11, 2024
1288258
Merge branch 'main' into cold-exits
markshannon Jan 11, 2024
7c6267a
Modify internal interfaces
markshannon Jan 11, 2024
55c48e8
Merge branch 'main' into cold-exits
markshannon Jan 11, 2024
8b3c2e0
Jump to next executor without updating current_executor.
markshannon Jan 11, 2024
92a3b61
Support cycle GC for executors.
markshannon Jan 12, 2024
e3def48
Give cold exits their own class, to fix GC handling of exits
markshannon Jan 16, 2024
87e544b
Generate table of cold exits
markshannon Jan 16, 2024
2172d68
Treat EXIT_TRACE as a side exit
markshannon Jan 16, 2024
4448793
Treat most common guard failures as side exits
markshannon Jan 16, 2024
c70f12f
Tweak generated tble to help C analyzer
markshannon Jan 16, 2024
d73fe0a
Add some documentation about the tier 2 engine
markshannon Jan 16, 2024
5c8f0bd
Fix constness and rename hotness
markshannon Jan 17, 2024
140486b
Add new static objects to ignored file.
markshannon Jan 17, 2024
3362c93
Address review comments
markshannon Jan 18, 2024
63fe653
Transfer executor on thread-state and othe minor changes to be more j…
markshannon Feb 8, 2024
b0991a7
Merge branch 'main' into cold-exits
markshannon Feb 8, 2024
625bce2
Get side exits to build with jit enabled.
markshannon Feb 9, 2024
e191fd7
Initialize cold exits dynamically on demand
markshannon Feb 9, 2024
941a14c
Tidy tier 2 code a bit
markshannon Feb 9, 2024
cfd3285
Add Brandt's fixes
markshannon Feb 9, 2024
1025495
Free the correct amount of memory
markshannon Feb 9, 2024
171dad7
Merge branch 'main' into cold-exits
markshannon Feb 9, 2024
e6ca3fe
Remove unreachable code
markshannon Feb 9, 2024
308b2a7
Merge branch 'main' into cold-exits
markshannon Feb 9, 2024
518143e
Clear executors attached to exits when clearing executors
markshannon Feb 9, 2024
9d8cab8
Merge branch 'main' into cold-exits
markshannon Feb 9, 2024
bf07dad
Merge branch 'main' into cold-exits
markshannon Feb 9, 2024
19b6b84
Keep c-analyzer happy
markshannon Feb 9, 2024
c959e8f
Merge branch 'main' into cold-exits
markshannon Feb 14, 2024
f393ba5
Use threshold for side exits
markshannon Feb 14, 2024
bd66b01
Statically allocate cold exits
markshannon Feb 14, 2024
fe75484
Handle errors in JIT compile
markshannon Feb 14, 2024
3d0110c
Merge branch 'main' into cold-exits
markshannon Feb 14, 2024
de93130
Fix possible leak
markshannon Feb 14, 2024
77a6740
Fix refleak transfering from JIT to tier 1
markshannon Feb 14, 2024
0a61d29
Check that only one of EXIT_IF and DEOPT_IF is present
markshannon Feb 14, 2024
b3e306d
Address review comments
markshannon Feb 14, 2024
8f3aa33
Make exit_index 32 bits to avoid endianness issues in JIT
markshannon Feb 14, 2024
7c84967
Run black
markshannon Feb 15, 2024
8ee6710
Address code review
markshannon Feb 15, 2024
f37d7fc
Update comment
markshannon Feb 15, 2024
1f8967d
Address review comments
markshannon Feb 15, 2024
8e4c601
Fix compiler warning
markshannon Feb 15, 2024
4eb2cfc
Address review comments
markshannon Feb 15, 2024
ebe804f
Add missing brace
markshannon Feb 15, 2024
c38d4e8
Address review comments
markshannon Feb 15, 2024
830eb4e
Keep c-analyzer quiet
markshannon Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Brandt's fixes
  • Loading branch information
markshannon committed Feb 9, 2024
commit cfd3285fd7278f93f277b2e8363fa396e96d84ae
1 change: 1 addition & 0 deletions Include/cpython/optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct _PyExecutorObject {
_PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */
uint32_t exit_count;
uint32_t code_size;
size_t jit_size;
void *jit_code;
_PyExitData exits[1];
} _PyExecutorObject;
Expand Down
14 changes: 14 additions & 0 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,26 @@ stack_pointer = _PyFrame_GetStackPointer(frame);

/* Tier-switching macros. */

#ifdef _Py_JIT
#define GOTO_TIER_TWO(EXECUTOR) \
do { \
jit_func jitted = (EXECUTOR)->jit_code; \
next_instr = jitted(frame, stack_pointer, tstate); \
frame = tstate->current_frame; \
if (next_instr == NULL) { \
goto resume_with_error; \
} \
stack_pointer = _PyFrame_GetStackPointer(frame); \
DISPATCH(); \
} while (0)
#else
#define GOTO_TIER_TWO(EXECUTOR) \
do { \
next_uop = (EXECUTOR)->trace; \
assert(next_uop->opcode == _START_EXECUTOR || next_uop->opcode == _COLD_EXIT); \
goto enter_tier_two; \
} while (0)
#endif

#define GOTO_TIER_ONE(TARGET) \
next_instr = target; \
Expand Down
11 changes: 8 additions & 3 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ _PyJIT_Compile(_PyExecutorObject *executor, _PyUOpInstruction *trace, size_t len
// Loop again to emit the code:
char *code = memory;
char *data = memory + code_size;
char *top = code;
if (trace[0].opcode == _START_EXECUTOR) {
// Don't want to execute this more than once:
top += stencil_groups[_START_EXECUTOR].code.body_size;
}
for (size_t i = 0; i < length; i++) {
_PyUOpInstruction *instruction = &trace[i];
const StencilGroup *group = &stencil_groups[instruction->opcode];
Expand All @@ -335,7 +340,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, _PyUOpInstruction *trace, size_t len
patches[HoleValue_OPARG] = instruction->oparg;
patches[HoleValue_OPERAND] = instruction->operand;
patches[HoleValue_TARGET] = instruction->target;
patches[HoleValue_TOP] = (uint64_t)memory;
patches[HoleValue_TOP] = (uint64_t)top;
patches[HoleValue_ZERO] = 0;
emit(group, patches);
code += group->code.body_size;
Expand All @@ -348,7 +353,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, _PyUOpInstruction *trace, size_t len
return -1;
}
executor->jit_code = memory;
executor->code_size = code_size + data_size;
executor->jit_size = code_size + data_size;
return 0;
}

Expand All @@ -359,7 +364,7 @@ _PyJIT_Free(_PyExecutorObject *executor)
size_t size = executor->code_size;
if (memory) {
executor->jit_code = NULL;
executor->code_size = 0;
executor->jit_size = 0;
if (jit_free(memory, size)) {
PyErr_WriteUnraisable(NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ make_executor_from_uops(_PyUOpInstruction *buffer, const _PyBloomFilter *depende
#endif
#ifdef _Py_JIT
executor->jit_code = NULL;
executor->code_size = 0;
executor->jit_size = 0;
if (_PyJIT_Compile(executor, executor->trace, length+1)) {
Py_DECREF(executor);
return NULL;
Expand Down
0