-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Allow threadsafe access to buffer of type inference profiling trees #47615
Open
vilterp
wants to merge
2
commits into
JuliaLang:master
Choose a base branch
from
vilterp:pv-compiler-timings-lock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−71
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Implementation for type inference profiling | ||
|
||
#include "julia.h" | ||
#include "julia_internal.h" | ||
|
||
jl_mutex_t typeinf_profiling_lock; | ||
|
||
// == exported interface == | ||
|
||
JL_DLLEXPORT jl_array_t* jl_typeinf_profiling_clear_and_fetch( | ||
jl_array_t *inference_profiling_results_array, | ||
jl_value_t *array_timing_type | ||
) | ||
{ | ||
JL_LOCK(&typeinf_profiling_lock); | ||
|
||
size_t len = jl_array_len(inference_profiling_results_array); | ||
|
||
jl_array_t *out = jl_alloc_array_1d(array_timing_type, len); | ||
JL_GC_PUSH1(&out); | ||
|
||
memcpy(out->data, inference_profiling_results_array->data, len * sizeof(void*)); | ||
|
||
jl_array_del_end(inference_profiling_results_array, len); | ||
|
||
JL_UNLOCK(&typeinf_profiling_lock); | ||
|
||
JL_GC_POP(); | ||
return out; | ||
} | ||
|
||
JL_DLLEXPORT void jl_typeinf_profiling_push_timing( | ||
jl_array_t *inference_profiling_results_array, | ||
jl_value_t *timing | ||
) | ||
{ | ||
JL_LOCK(&typeinf_profiling_lock); | ||
|
||
jl_array_grow_end(inference_profiling_results_array, 1); | ||
size_t len = jl_array_len(inference_profiling_results_array); | ||
jl_array_ptr_set(inference_profiling_results_array, len - 1, timing); | ||
|
||
JL_UNLOCK(&typeinf_profiling_lock); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vchuravy / @pchintalapudi / @kpamnany: I finally got around to testing this, and indeed it doesn't work. :(
It turns out that
Base.IdDict
andCore.Compiler.IdDict
are not the same thing. 😢Does anyone know why that is? Why doesn't Base just reexport the IdDict from Core.Compiler?
I.e. here:
julia/base/Base.jl
Line 165 in 80aeebe
Why doesn't it just reexport the IdDict from Core.Compiler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BUT anyway, the error we encounter is that we're not allowed to set the Task's
.storage
field to a Core.Compiler.IdDict; it's expected to be a Base.IdDict.So is there just no way to use task-local storage from Core.Compiler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly a more robust solution here, which might also last longer if we parallelize inference, would be to store this on the
AbstractInterpreter
orInferenceState
objects? Does anyone know if that's plausible? We essentially want some object that lives for the lifetime of the inference invocation, and is local to this invocation, where we can store the stack of timers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we'd have to thread it through every function call, but that seems like possibly a nonstarter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nobody needed this before it seems :)
Likely to isolate the compiler code from Base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do:
to get around the bootstrapping issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is because the compiler is forbidden from accessing TLS. Since we hijack the current task to run codegen, it could corrupt the running task if it does anything to interact with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(instead, you could perhaps replace the TLS on entry with one from Core.Compiler, and restore it on return)