-
-
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 for :foreigncall to transition to GC safe automatically #49933
base: master
Are you sure you want to change the base?
Conversation
Since we already have the trampoline stuff, what about adding a safepoint into every call into the julia runtime? Similar to the safepoint in JIT function calls? |
How would this affect packages that use CxxWrap or jlrs to provide access to C++ and Rust libraries, which call back into into Julia from foreign functions? |
All in Julia itself? Perhaps. All in all Julia packages? Definitely not! That would be a breaking change. |
Can you point at a for-instance @fingolfin? |
The not common but existing case is for julia code to call c code that calls julia runtime functions. |
@kpamnany any package using a JLL linking against I am not saying this is an impossible change, but only if there is a well thought out migration strategy that is coordinated with all stakeholders. But just saying "it probably won't affect that many packages, let's just do it", without a full analysis and without involving the community, repeats the "main" debacle. Let's not go there. Overall, I prefer "code that is not as fast as it could be but is correct" over "code that is perhaps a bit faster, or not, but will occasionally crash or produce garbage... A more viable alternative would be an opt-in solution -- but then of course many packages will miss this opportunity. A pity, but it wouldn't leave us worse than we are right now, new packages could benefit from it. (If we had something like Rust editions, then for "new" packages this could become the default, I guess...?) |
aca69d9
to
47a08bb
Compare
47a08bb
to
6fcef7c
Compare
Now is:
The safepoint emission at that point needs to be cleaner. @vtjnash that's probably closer to what it needs to be? |
Value *ptls = get_current_ptls_from_task(builder, T_size, get_current_task_from_pgcstack(builder, T_size, pgcstack), tbaa_gcframe); | ||
Value *last_gc_state = emit_gc_safe_enter(builder, T_size, ptls, false); | ||
builder.SetInsertPoint(CI->getNextNode()); | ||
// Can't use `emit_gc_safe_exit` since that wan'ts to emit some branches... |
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.
I am guessing you would need to make a new block for this specific emit call, then fix up the IR by calling SplitBlockAndInsertIfThenElse and splice the instructions back into their respective parts of the IfThenElse blocks and delete the new blocks
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.
Yeah I was trying that and had an infinite loop in the iteration here so I am not sure if this is the right place.
I would also like to support a more region based approach, since it would be interesting for long running for loops
Note for when this lands: we should redo JuliaLang/MbedTLS.jl#265. |
This allows the GC to run while potentially blocking in a CUDA library. To make this safe, callbacks into Julia should again transition to GC-unsafe mode. It should be reimplemented when JuliaLang/julia#49933 lands. Co-authored-by: Tim Besard <tim.besard@gmail.com>
This has been bouncing around as a idea for a while.
One of the challenges around time-to-safepoint has been Julia code
that is calling libraries.
Since foreign code will not include safepoints we see increased latency
when one thread is running a foreign-call and another wants to trigger GC.
The open design question here is:
keyword arg to
@ccall
or a specific calling-convetion.There is relativly little code outside the Julia runtime that needs to be "GC unsafe",
exception are programs that directly use the Julia C-API. Incidentially
jl_adopt_thread
and
@cfunction
/@ccallable
do the right thing and transition to "GC unsafe", regardlessof what state the thread currently is in.
I still need to figure out how to reliably detect Julia runtime calls, but I think we can
switch all other calls to "GC safe". We should also consider optimizations that mark large
regions of code without Julia runtime interactions as "GC safe" in particular numeric
for-loops.