-
Notifications
You must be signed in to change notification settings - Fork 89
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
MPI workarounds for aarch64 #999
Open
abussy
wants to merge
3
commits into
JuliaMolSim:master
Choose a base branch
from
abussy:mpi_aarch64
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.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
""" | ||
MPI reduction opertations with custom types (i.e. anything that has not a MPI datatype equivalent) | ||
are not available on aarch64. These are temprorary workarounds, where variables with custom types | ||
are broken down to standard types before communication, and recast to the initial types after. | ||
This file was created by fixing all MPI errors encountered by running the tests on an ARM machine: | ||
all sensible MPI reduction routines are implemented for each custom type causing an error. | ||
""" | ||
|
||
# Julia's Bool type has no direct equivalent MPI datatype => need integer conversion | ||
function mpi_min(bool::Bool, comm::MPI.Comm) | ||
int = Int(bool) | ||
Bool(mpi_min(int, comm)) | ||
end | ||
|
||
function mpi_max(bool::Bool, comm::MPI.Comm) | ||
int = Int(bool) | ||
Bool(mpi_max(int, comm)) | ||
end | ||
|
||
# Vec3{T} must be cast to Vector{T} before MPI reduction | ||
function mpi_sum!(arr::Vector{Vec3{T}}, comm::MPI.Comm) where{T} | ||
n = length(arr) | ||
new_arr = zeros(T, 3n) | ||
for i in 1:n | ||
new_arr[3(i-1)+1:3(i-1)+3] = @view arr[i][1:3] | ||
end | ||
mpi_sum!(new_arr, comm) | ||
for i in 1:n | ||
arr[i] = Vec3{T}(@view new_arr[3(i-1)+1:3(i-1)+3]) | ||
end | ||
arr | ||
end | ||
|
||
# ForwardDiff.Dual{T, U, V} and arrays of it must be cast to Vector{U} as well | ||
# utility function to cast a Dual type to an array containing a value and the partial diffs | ||
function dual_array(dual::ForwardDiff.Dual{T, U, V}) where{T, U, V} | ||
dual_array = zeros(U, ForwardDiff.npartials(dual)+1) | ||
dual_array[1] = ForwardDiff.value(dual) | ||
dual_array[2:end] = @view dual.partials[1:end] | ||
dual_array | ||
end | ||
|
||
# utility function that casts back an array to a Dual type, based on a template Dual | ||
function new_dual(dual_array, template::ForwardDiff.Dual{T, U, V}) where{T, U, V} | ||
ForwardDiff.Dual{T}(dual_array[1], Tuple(@view dual_array[2:end])) | ||
end | ||
|
||
# MPI reductions of single ForwardDiff.Dual types | ||
function mpi_sum(dual::ForwardDiff.Dual{T, U, V}, comm::MPI.Comm) where{T, U, V} | ||
arr = dual_array(dual) | ||
mpi_sum!(arr, comm) | ||
new_dual(arr, dual) | ||
end | ||
|
||
function mpi_min(dual::ForwardDiff.Dual{T, U, V}, comm::MPI.Comm) where{T, U, V} | ||
arr = dual_array(dual) | ||
mpi_min!(arr, comm) | ||
new_dual(arr, dual) | ||
end | ||
|
||
function mpi_max(dual::ForwardDiff.Dual{T, U, V}, comm::MPI.Comm) where{T, U, V} | ||
arr = dual_array(dual) | ||
mpi_max!(arr, comm) | ||
new_dual(arr, dual) | ||
end | ||
|
||
function mpi_mean(dual::ForwardDiff.Dual{T, U, V}, comm::MPI.Comm) where{T, U, V} | ||
arr = dual_array(dual) | ||
mpi_mean!(arr, comm) | ||
new_dual(arr, dual) | ||
end | ||
|
||
# MPI reductions of arrays of ForwardDiff.Dual types | ||
function mpi_sum!(dual::Array{ForwardDiff.Dual{T, U, V}, N}, comm::MPI.Comm) where{T, U, V, N} | ||
array = Vector{U}([]) | ||
lengths = [] | ||
for i in 1:length(dual) | ||
tmp = dual_array(dual[i]) | ||
append!(array, tmp) | ||
append!(lengths, length(tmp)) | ||
end | ||
mpi_sum!(array, comm) | ||
offset = 0 | ||
for i in 1:length(dual) | ||
view = @view array[offset+1:offset+lengths[i]] | ||
dual[i] = new_dual(view, dual[i]) | ||
offset += lengths[i] | ||
end | ||
dual | ||
end |
Oops, something went wrong.
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.
Can this not be solved by a reinterpret(reshape, ... )? Then there is no copy
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 this one is tricky to get without copies, because
SVector
are immutable. So even if I use something likenew_aarr = reshape(reinterpret(T, arr), 3, :)
, I still could not callmpi_sum!()
. And assuming I callmpi_sum()
instead, I also end up with a copy.