-
Notifications
You must be signed in to change notification settings - Fork 5
Implementation of MPI SUMMA matrix mul #160
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
Draft
astroC86
wants to merge
18
commits into
PyLops:main
Choose a base branch
from
astroC86:actual-SUMMA
base: main
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.
+632
−71
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
75c815b
inital-example
astroC86 908d4b9
Merge remote-tracking branch 'origin/main' into actual-SUMMA
astroC86 069e5dd
working simple example
astroC86 5fcbad3
untransformed C
astroC86 d8d9463
Initial impl of SUMMA matmul
astroC86 a9e679e
matmul with padding
astroC86 8142d44
impl adjoint
astroC86 7363431
cleanedup adjoint impl
astroC86 4a94ac6
merge and new example
astroC86 dc00226
added handling for padding
astroC86 58d3ceb
Cleanup
astroC86 1ef09ab
converted Bcast into bcast
astroC86 56e9414
Added docstring
astroC86 f3d1918
removed block distribute function
astroC86 9d36b0c
removed unnecessary check on local matrix A
astroC86 66e3296
Added Generic MatMulOp with docstring
astroC86 fa07ae8
Merge branch 'PyLops:main' into actual-SUMMA
astroC86 0956e7b
Converted it to a function
astroC86 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 hidden or 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,58 @@ | ||
import math | ||
import numpy as np | ||
from mpi4py import MPI | ||
|
||
import pylops_mpi | ||
from pylops_mpi.basicoperators.MatrixMult import (local_block_spit, | ||
block_gather, | ||
MPISummaMatrixMult) | ||
|
||
comm = MPI.COMM_WORLD | ||
rank = comm.Get_rank() | ||
size = comm.Get_size() | ||
|
||
N = 9 | ||
M = 9 | ||
K = 9 | ||
|
||
A_shape = (N, K) | ||
B_shape = (K, M) | ||
C_shape = (N, M) | ||
|
||
p_prime = math.isqrt(size) | ||
assert p_prime * p_prime == size, "Number of processes must be a perfect square" | ||
|
||
A_data = np.arange(int(A_shape[0] * A_shape[1])).reshape(A_shape) | ||
B_data = np.arange(int(B_shape[0] * B_shape[1])).reshape(B_shape) | ||
|
||
A_slice = local_block_spit(A_shape, rank, comm) | ||
B_slice = local_block_spit(B_shape, rank, comm) | ||
A_local = A_data[A_slice] | ||
B_local = B_data[B_slice] | ||
# A_local, (N_new, K_new) = block_distribute(A_data,rank, comm) | ||
# B_local, (K_new, M_new) = block_distribute(B_data,rank, comm) | ||
|
||
B_dist = pylops_mpi.DistributedArray(global_shape=(K * M), | ||
local_shapes=comm.allgather(B_local.shape[0] * B_local.shape[1]), | ||
base_comm=comm, | ||
partition=pylops_mpi.Partition.SCATTER) | ||
B_dist.local_array[:] = B_local.flatten() | ||
|
||
Aop = MPISummaMatrixMult(A_local, M, base_comm=comm) | ||
C_dist = Aop @ B_dist | ||
Z_dist = Aop.H @ C_dist | ||
|
||
C = block_gather(C_dist, (N,M), (N,M), comm) | ||
Z = block_gather(Z_dist, (K,M), (K,M), comm) | ||
if rank == 0 : | ||
C_correct = np.allclose(A_data @ B_data, C) | ||
print("C expected: ", C_correct) | ||
if not C_correct: | ||
print("expected:\n", A_data @ B_data) | ||
print("calculated:\n",C) | ||
|
||
Z_correct = np.allclose((A_data.T.dot((A_data @ B_data).conj())).conj(), Z.astype(np.int32)) | ||
print("Z expected: ", Z_correct) | ||
if not Z_correct: | ||
print("expected:\n", (A_data.T.dot((A_data @ B_data).conj())).conj()) | ||
print("calculated:\n", Z.astype(np.int32)) |
Oops, something went wrong.
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.
no assert in examples