Skip to content
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

Fix and simplify inference timing logic #47711

Merged
merged 2 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
14 changes: 8 additions & 6 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3419,18 +3419,20 @@ int jl_has_concrete_subtype(jl_value_t *typ)

JL_DLLEXPORT void jl_typeinf_timing_begin(void)
{
if (jl_atomic_load_relaxed(&jl_measure_compile_time_enabled)) {
jl_task_t *ct = jl_current_task;
if (ct->inference_start_time == 0 && ct->reentrant_inference == 1)
ct->inference_start_time = jl_hrtime();
jl_task_t *ct = jl_current_task;
if (!ct->timing_inference++) {
ct->inference_start_time = jl_hrtime();
}
}

JL_DLLEXPORT void jl_typeinf_timing_end(void)
{
jl_task_t *ct = jl_current_task;
if (ct->inference_start_time != 0 && ct->reentrant_inference == 1) {
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - ct->inference_start_time));
if (!--ct->timing_inference) {
if (jl_atomic_load_relaxed(&jl_measure_compile_time_enabled)) {
uint64_t inftime = jl_hrtime() - ct->inference_start_time;
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, inftime);
}
ct->inference_start_time = 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,7 @@ typedef struct _jl_task_t {
void *stkbuf; // malloc'd memory (either copybuf or stack)
size_t bufsz; // actual sizeof stkbuf
uint64_t inference_start_time; // time when inference started
unsigned int timing_inference; // whether inference is currently timing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use another 4 bytes for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we believe that inference and codegen aren't going to exceed 65536 recursions, we can drop all of the recursion trackers to 2 bytes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yes I think the issue was that I wasn't initializing the inference start time to 0, so junk times ended up being recorded. I'll adjust it to rely on the reentrant inference tracker again.

unsigned int reentrant_inference; // How many times we've reentered inference
unsigned int reentrant_codegen; // How many times we've reentered codegen
unsigned int copy_stack:31; // sizeof stack for copybuf
Expand Down
4 changes: 4 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ JL_DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, jl_value_t *completion
t->world_age = ct->world_age;
t->reentrant_codegen = 0;
t->reentrant_inference = 0;
t->inference_start_time = 0;
t->timing_inference = 0;

#ifdef COPY_STACKS
if (!t->copy_stack) {
Expand Down Expand Up @@ -1527,6 +1529,8 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
ct->world_age = 1; // OK to run Julia code on this task
ct->reentrant_codegen = 0;
ct->reentrant_inference = 0;
ct->inference_start_time = 0;
ct->timing_inference = 0;
ptls->root_task = ct;
jl_atomic_store_relaxed(&ptls->current_task, ct);
JL_GC_PROMISE_ROOTED(ct);
Expand Down