-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
combine Consts and API modules (#650)
* combine Consts and API modules * @t-bltg's fixes * Builds docs only for functions in `API` module Co-authored-by: Mosè Giordano <[email protected]>
- Loading branch information
1 parent
5a9ed4e
commit 61947d9
Showing
32 changed files
with
319 additions
and
322 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,5 +45,5 @@ MPI.set_errorhandler! | |
## Miscellaneous | ||
|
||
```@docs | ||
MPI.Consts.@const_ref | ||
MPI.API.@const_ref | ||
``` |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
```@autodocs | ||
Modules = [MPI.API] | ||
Order = [:function] | ||
``` |
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,138 @@ | ||
module API | ||
|
||
export MPI_Aint, MPI_Count, MPI_Offset, MPI_Status, | ||
MPI_Comm, MPI_Datatype, MPI_Errhandler, MPI_File, MPI_Group, | ||
MPI_Info, MPI_Message, MPI_Op, MPI_Request, MPI_Win, | ||
libmpi, mpiexec, @mpichk, @mpicall, MPIPtr, SentinelPtr, FeatureLevelError | ||
|
||
import MPIPreferences | ||
using Libdl | ||
|
||
if MPIPreferences.binary == "MPICH_jll" | ||
import MPICH_jll: libmpi, libmpi_handle, mpiexec | ||
const libmpiconstants = nothing | ||
elseif MPIPreferences.binary == "OpenMPI_jll" | ||
import OpenMPI_jll: libmpi, libmpi_handle, mpiexec | ||
const libmpiconstants = nothing | ||
elseif MPIPreferences.binary == "MicrosoftMPI_jll" | ||
import MicrosoftMPI_jll: libmpi, libmpi_handle, mpiexec | ||
const libmpiconstants = nothing | ||
elseif MPIPreferences.binary == "MPItrampoline_jll" | ||
import MPItrampoline_jll: MPItrampoline_jll, libmpi, libmpi_handle, mpiexec | ||
const libmpiconstants = MPItrampoline_jll.libload_time_mpi_constants_path | ||
elseif MPIPreferences.binary == "system" | ||
import MPIPreferences.System: libmpi, libmpi_handle, mpiexec | ||
const libmpiconstants = nothing | ||
else | ||
error("Unknown MPI binary: $(MPIPreferences.binary)") | ||
end | ||
|
||
import ..MPIError | ||
const initexprs = Any[] | ||
|
||
""" | ||
@const_ref name T expr | ||
Defines an constant binding | ||
```julia | ||
const name = Ref{T}() | ||
``` | ||
and adds a hook to execute | ||
```julia | ||
name[] = expr | ||
``` | ||
at module initialization time. | ||
""" | ||
macro const_ref(name, T, expr) | ||
push!(initexprs, :($name[] = $expr)) | ||
:(const $(esc(name)) = Ref{$T}()) | ||
end | ||
|
||
@static if MPIPreferences.abi == "MPICH" | ||
include("mpich.jl") | ||
elseif MPIPreferences.abi == "OpenMPI" | ||
include("openmpi.jl") | ||
elseif MPIPreferences.abi == "MicrosoftMPI" | ||
include("microsoftmpi.jl") | ||
elseif MPIPreferences.abi == "MPItrampoline" | ||
include("mpitrampoline.jl") | ||
elseif MPIPreferences.abi == "HPE MPT" | ||
include("mpt.jl") | ||
else | ||
error("Unknown MPI ABI $(MPIPreferences.abi)") | ||
end | ||
|
||
primitive type SentinelPtr Sys.WORD_SIZE | ||
end | ||
|
||
primitive type MPIPtr Sys.WORD_SIZE | ||
end | ||
@assert sizeof(MPIPtr) == sizeof(Ptr{Cvoid}) | ||
Base.cconvert(::Type{MPIPtr}, x::SentinelPtr) = x | ||
Base.unsafe_convert(::Type{MPIPtr}, x::SentinelPtr) = reinterpret(MPIPtr, x) | ||
|
||
|
||
# Initialize the ref constants from the library. | ||
# This is not `API.__init__`, as it should be called _after_ | ||
# `dlopen` to ensure the library is opened correctly. | ||
@eval function init_consts() | ||
$(Expr(:block, initexprs...)) | ||
end | ||
|
||
const use_stdcall = startswith(basename(libmpi), "msmpi") | ||
|
||
macro mpicall(expr) | ||
@assert expr isa Expr && expr.head == :call && expr.args[1] == :ccall | ||
|
||
# On unix systems we call the global symbols to allow for LD_PRELOAD interception | ||
# It can be emulated in Windows (via Libdl.dllist), but this is not fast. | ||
if Sys.isunix() && expr.args[2].head == :tuple && | ||
(VERSION ≥ v"1.5-" || expr.args[2].args[1] ≠ :(:MPI_Get_library_version)) | ||
expr.args[2] = expr.args[2].args[1] | ||
end | ||
|
||
# Microsoft MPI uses stdcall calling convention | ||
# this only affects 32-bit Windows | ||
# unfortunately we need to use ccall to call Get_library_version | ||
# so check using library name instead | ||
if use_stdcall | ||
insert!(expr.args, 3, :stdcall) | ||
end | ||
return esc(expr) | ||
end | ||
|
||
""" | ||
FeatureLevelError | ||
Error thrown if a feature is not implemented in the current MPI backend. | ||
""" | ||
struct FeatureLevelError <: Exception | ||
function_name::Symbol | ||
min_version::VersionNumber # minimal MPI version required for this feature to be available | ||
end | ||
function Base.show(io::IO, err::FeatureLevelError) | ||
print(io, "FeatureLevelError($(err.function_name)): Minimum MPI version is $(err.min_version)") | ||
end | ||
|
||
macro mpichk(expr, min_version=nothing) | ||
if !isnothing(min_version) && expr.args[2].head == :tuple | ||
fn = expr.args[2].args[1].value | ||
if isnothing(dlsym(libmpi_handle, fn; throw_error=false)) | ||
return quote | ||
throw(FeatureLevelError($(QuoteNode(fn)), $min_version)) | ||
end | ||
end | ||
end | ||
|
||
expr = macroexpand(@__MODULE__, :(@mpicall($expr))) | ||
# MPI_SUCCESS is defined to be 0 | ||
:((errcode = $(esc(expr))) == 0 || throw(MPIError(errcode))) | ||
end | ||
|
||
|
||
include("generated_api.jl") | ||
|
||
# since this is called by invokelatest, it isn't automatically precompiled | ||
precompile(init_consts, ()) | ||
|
||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.