Skip to content

Commit

Permalink
Fix and simplify inference timing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi authored and DilumAluthge committed Nov 26, 2022
1 parent 02aa0b0 commit d5ea1f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 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->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
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

0 comments on commit d5ea1f1

Please sign in to comment.