Skip to content

Commit

Permalink
Fix and simplify inference timing logic (#47711)
Browse files Browse the repository at this point in the history
* Fix and simplify inference timing logic

* Reduce task struct size
  • Loading branch information
pchintalapudi authored Nov 26, 2022
1 parent 02aa0b0 commit 88a0627
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
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->reentrant_inference == 1) {
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->reentrant_inference == 1) {
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
4 changes: 2 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1940,8 +1940,8 @@ 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 reentrant_inference; // How many times we've reentered inference
unsigned int reentrant_codegen; // How many times we've reentered codegen
uint16_t reentrant_inference; // How many times we've reentered inference
uint16_t reentrant_codegen; // How many times we've reentered codegen
unsigned int copy_stack:31; // sizeof stack for copybuf
unsigned int started:1;
} jl_task_t;
Expand Down
2 changes: 2 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ 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;

#ifdef COPY_STACKS
if (!t->copy_stack) {
Expand Down Expand Up @@ -1527,6 +1528,7 @@ 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;
ptls->root_task = ct;
jl_atomic_store_relaxed(&ptls->current_task, ct);
JL_GC_PROMISE_ROOTED(ct);
Expand Down

2 comments on commit 88a0627

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.