-
-
Notifications
You must be signed in to change notification settings - Fork 128
Add gc_safe option to @mpicall and @mpichk macros
#955
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
base: master
Are you sure you want to change the base?
Changes from all commits
6cd957f
379c831
7d1ed2d
3488d31
7f020e2
ebfa38a
510c625
9493e24
086a941
95bd07c
83f4535
564d6e1
0f368ac
5bfda86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| *.cov | ||
| *.mem | ||
| Manifest.toml | ||
| Manifest-v*.toml | ||
| LocalPreferences.toml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,9 @@ module MPIgenerator | |
| mkpath(out) | ||
|
|
||
| options = load_options(joinpath(@__DIR__, "generator.toml")) # wrapper generator options | ||
| options["general"]["callback_documentation"] = node -> [string('$', "(_doc_external(:", node.id, "))")] | ||
| # NOTE: in Clang.jl v0.19+ the callback takes also the docstring extracted from the | ||
| # C comments as second argument, which we ignore | ||
| options["general"]["callback_documentation"] = (node, doc) -> [string('$', "(_doc_external(:", node.id, "))")] | ||
|
|
||
| include_dir = normpath(artifact_dir, "include") | ||
|
|
||
|
|
@@ -48,6 +50,52 @@ module MPIgenerator | |
| :MPI_Wtick, | ||
| ) | ||
|
|
||
| # these methods are called with `gc_safe=true`, to allow the garbage | ||
| # collector to run concurrently with the (potentially blocking) MPI call. | ||
| # The criterion for inclusion is that the worst-case duration of the call | ||
| # is unbounded because it waits on the progress of peer ranks, rather than | ||
| # being bounded by local work, and that the call can only re-enter Julia | ||
| # through `@cfunction` callbacks (e.g. custom reduction operators), which | ||
| # are safe in `gc_safe` regions | ||
| gc_safe = ( | ||
| # request completion | ||
| :MPI_Wait, | ||
| :MPI_Waitall, | ||
| :MPI_Waitany, | ||
| :MPI_Waitsome, | ||
| :MPI_Mrecv, | ||
| # blocking point-to-point | ||
| :MPI_Send, | ||
| :MPI_Ssend, | ||
| :MPI_Recv, | ||
| :MPI_Sendrecv, | ||
| :MPI_Sendrecv_replace, | ||
| # blocking collectives | ||
| :MPI_Barrier, | ||
| :MPI_Bcast, | ||
| :MPI_Gather, | ||
| :MPI_Gatherv, | ||
| :MPI_Scatter, | ||
| :MPI_Scatterv, | ||
| :MPI_Allgather, | ||
| :MPI_Allgatherv, | ||
| :MPI_Alltoall, | ||
| :MPI_Alltoallv, | ||
| :MPI_Alltoallw, | ||
| :MPI_Reduce, | ||
| :MPI_Allreduce, | ||
| :MPI_Reduce_scatter, | ||
| :MPI_Reduce_scatter_block, | ||
| :MPI_Scan, | ||
| :MPI_Exscan, | ||
| # blocking neighborhood collectives | ||
| :MPI_Neighbor_allgather, | ||
| :MPI_Neighbor_allgatherv, | ||
| :MPI_Neighbor_alltoall, | ||
| :MPI_Neighbor_alltoallv, | ||
| :MPI_Neighbor_alltoallw, | ||
| ) | ||
|
Comment on lines
+60
to
+97
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The bot suggests gc_safe = (
# request completion and probes
:MPI_Wait, :MPI_Waitall, :MPI_Waitany, :MPI_Waitsome,
:MPI_Probe, :MPI_Mprobe, :MPI_Mrecv,
# blocking point-to-point
:MPI_Send, :MPI_Ssend, :MPI_Recv, :MPI_Sendrecv, :MPI_Sendrecv_replace,
# blocking collectives
:MPI_Barrier, :MPI_Bcast,
:MPI_Gather, :MPI_Gatherv, :MPI_Scatter, :MPI_Scatterv,
:MPI_Allgather, :MPI_Allgatherv, :MPI_Alltoall, :MPI_Alltoallv, :MPI_Alltoallw,
:MPI_Reduce, :MPI_Allreduce, :MPI_Reduce_scatter, :MPI_Reduce_scatter_block,
:MPI_Scan, :MPI_Exscan,
# blocking neighborhood collectives
:MPI_Neighbor_allgather, :MPI_Neighbor_allgatherv,
:MPI_Neighbor_alltoall, :MPI_Neighbor_alltoallv, :MPI_Neighbor_alltoallw,
)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only thing I am worried about is the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bot really insisted that probes are fine
In any case I don't have a need for marking these functions as gc-safe, so I dropped them. |
||
|
|
||
| versioned = Dict( | ||
| :MPI_Dist_graph_create_adjacent => v"2.2", | ||
| :MPI_Dist_graph_neighbors_count => v"2.2", | ||
|
|
@@ -59,19 +107,45 @@ module MPIgenerator | |
| :MPI_Neighbor_alltoall => v"3.0", | ||
| ) | ||
|
|
||
| src, fn = joinpath(out, "api.jl"), replace(@__FILE__, r".*MPI.jl" => "MPI.jl") | ||
| lines = String["# WARNING: this signature file for $(MPIPreferences.binary) has been auto-generated, please edit $fn instead !\n"] | ||
| src, fn = joinpath(out, "api.jl"), joinpath("MPI.jl", relpath(@__FILE__, normpath(@__DIR__, "..", ".."))) | ||
| lines = String[] | ||
| for line in readlines(src) | ||
| if (m = match(r"^ccall.*:([\w_]+)", lstrip(line))) ≢ nothing | ||
| sym = first(m.captures) |> Symbol | ||
| repl = sym ∈ mpicall ? "@mpicall ccall" : "@mpichk ccall" | ||
| repl = (sym ∈ mpicall ? "@mpicall" : "@mpichk") * | ||
| (sym ∈ gc_safe ? " gc_safe=true" : "") * " ccall" | ||
| line = replace(line, "Ptr{Cvoid}" => "MPIPtr", "ccall" => repl) | ||
| if (ver = get(versioned, sym, nothing)) ≢ nothing | ||
| line *= " $(repr(ver))" | ||
| end | ||
| end | ||
| push!(lines, replace(line, raw"\$" => '$')) | ||
| end | ||
|
|
||
| # group the lines into blocks (docstring + function definition) and sort them by | ||
| # name of the function, to make the output stable: the order in which the | ||
| # functions are declared in the headers may change between releases of the MPI | ||
| # implementations | ||
| blocks = Vector{Vector{String}}() | ||
| block = String[] | ||
| for line in lines | ||
| # drop the blank lines separating the blocks, they are re-added below | ||
| isempty(block) && isempty(line) && continue | ||
| push!(block, line) | ||
| if line == "end" # end of a function definition | ||
| push!(blocks, block) | ||
| block = String[] | ||
| end | ||
| end | ||
| isempty(block) || error("malformed generated file $src, trailing lines: $block") | ||
| function_name(block) = match(r"^function (\w+)", block[findfirst(startswith("function "), block)]).captures[1] | ||
| sort!(blocks; by=function_name) | ||
|
|
||
| lines = String["# WARNING: this signature file for $(MPIPreferences.binary) has been auto-generated, please edit $fn instead !\n"] | ||
| for block in blocks | ||
| append!(lines, block) | ||
| push!(lines, "") | ||
| end | ||
| write(src, join(lines, "\n")) | ||
|
|
||
| dst = normpath(@__DIR__, "..", "..", "src", "api", "generated_api.jl") | ||
|
|
||
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 this was entirely the bot's initiative, I'm not quite sure whether it's true that multi-threaded applications need
to make the GC run concurrently with the MPI functions. I'm happy to remove this if it's garbage (pun intended).
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.
Oh that is fun... it is an interesting question what happens when we run
MPI_*_freefrom a finalizer...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 think the problem is that Julia these days becomes multi-threaded as soon as you do
using CUDAso you don't know that you are serial.Or even today just starting Julia will give me an interactive and a worker thread. So we are already in a world where the user can't reason about being single-threaded