Skip to content
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: Mitigate SparseFunction setup costs #1720

Merged
merged 3 commits into from Aug 9, 2021
Merged

Conversation

mloubout
Copy link
Contributor

@mloubout mloubout commented Jul 2, 2021

Some better use of numpy broadcasting to setup sparse functions

I get a ~X5 speedup on 256*256 receivers on my desktop.

@codecov
Copy link

codecov bot commented Jul 2, 2021

Codecov Report

Merging #1720 (6aed60b) into master (4f2a1fb) will decrease coverage by 2.68%.
The diff coverage is 96.36%.

❗ Current head 6aed60b differs from pull request most recent head 07d2ead. Consider uploading reports for the commit 07d2ead to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1720      +/-   ##
==========================================
- Coverage   89.61%   86.93%   -2.69%     
==========================================
  Files         206      201       -5     
  Lines       33216    32655     -561     
  Branches     4314     4277      -37     
==========================================
- Hits        29766    28388    -1378     
- Misses       2960     3758     +798     
- Partials      490      509      +19     
Impacted Files Coverage Δ
devito/mpi/distributed.py 92.14% <88.23%> (+0.35%) ⬆️
devito/passes/clusters/utils.py 86.66% <100.00%> (ø)
devito/types/sparse.py 87.74% <100.00%> (-0.26%) ⬇️
tests/test_mpi.py 99.06% <100.00%> (+<0.01%) ⬆️
tests/test_gpu_openmp.py 4.71% <0.00%> (-93.20%) ⬇️
tests/test_adjoint.py 26.66% <0.00%> (-73.34%) ⬇️
examples/seismic/tti/operators.py 46.05% <0.00%> (-51.04%) ⬇️
examples/seismic/self_adjoint/operators.py 58.46% <0.00%> (-41.54%) ⬇️
examples/seismic/tti/wavesolver.py 57.02% <0.00%> (-41.33%) ⬇️
examples/seismic/viscoacoustic/operators.py 59.49% <0.00%> (-40.51%) ⬇️
... and 42 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f2a1fb...07d2ead. Read the comment docs.

@mloubout mloubout force-pushed the mpi-sparse-setup branch 3 times, most recently from 02e2326 to bf680e0 Compare July 2, 2021 13:42
@mloubout mloubout added the MPI mpi-related label Jul 2, 2021
@FabioLuporini FabioLuporini changed the title Mpi sparse setup mpi: Mitigate SparseFunction setup costs Jul 6, 2021
@mloubout mloubout force-pushed the mpi-sparse-setup branch 2 times, most recently from 16ef69d to 4388657 Compare July 7, 2021 14:04
return as_tuple(ret)
elif sum(index.shape) == 1:
return index
print(index.shape, self.ndim)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aside from this print, is this PR basically good to go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry yes did the fix locally and then forgot about pushing so gotta redo it, basically is yes. Did you give it a spin?

devito/mpi/distributed.py Show resolved Hide resolved
for r in self.grid.distributor.glb_to_rank(s):
ret.setdefault(r, []).append(i)
return {k: filter_ordered(v) for k, v in ret.items()}
dmap = self.grid.distributor.glb_to_rank(self._support)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single line return self. ... ?

"""
This method is analogous to :meth:`_dist_scatter_mask`, although
the mask is now suitable to index into self's SubFunctions, rather
than into ``self.data``.
"""
return self._dist_scatter_mask[self._sparse_position]
return self._dist_scatter_mask(dmap=dmap)[self._sparse_position]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is, essentially, to avoid recomputation of _dist_datamap when processing eg coordinates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's called like 8 times so this gain quite a bit to do it only once.

index = np.expand_dims(index, axis=2)

ret = {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no blank line

devito/mpi/distributed.py Show resolved Hide resolved
retrieved.
"""
assert isinstance(index, (tuple, list))
if len(index) == 0:
assert isinstance(index, np.ndarray)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this fixes the python 3.9 issue as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly, where is the issue for it again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no issue was opened, need to check

devito/types/sparse.py Show resolved Hide resolved
@FabioLuporini FabioLuporini merged commit f53c45a into master Aug 9, 2021
@FabioLuporini FabioLuporini deleted the mpi-sparse-setup branch August 9, 2021 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MPI mpi-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants