Skip to content

Feat distrarray memoryimprov - #216

Draft
mrava87 wants to merge 3 commits into
PyLops:mainfrom
mrava87:feat-distrarray_memoryimprov
Draft

mrava87 wants to merge 3 commits into
PyLops:mainfrom
mrava87:feat-distrarray_memoryimprov

Conversation

@mrava87

@mrava87 mrava87 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #215 - see Issue for details.

NOT READY FOR REVIEW

mrava87SW and others added 3 commits October 20, 2026 09:34
- Add DistributedArray._like to build result arrays without checks or
  collectives (the sub-communicator is reused, so masked arrays no longer
  call Comm.Split for every result), and cache local_shapes after the first
  allgather. Use it in __neg__, add, multiply, conj, copy, zeros_like and
  empty_like, and in StackedDistributedArray.zeros_like/empty_like.
- Add out= to add and multiply, add subtract, and make __iadd__, __isub__
  and the new __imul__ true in-place operators (single pass, no temporary).
  An out= that needs an unsafe cast falls back to assignment as before.
- Use ravel instead of flatten in dot and norm, add _local_dot and
  _local_sqnorm, and add a 2-norm fast path with one float64 allreduce and
  no float64 temporaries (complex data is reduced through a real view).
- Add tests (CPU, cupy and NCCL).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rray

- add, subtract and multiply accept out= (and scalars); each allocates its
  result once with empty_like (or uses out/self) and the children write
  directly into it, recursing into nested stacks. Add subtract and __imul__,
  make __isub__ in-place and __neg__ a single multiply.
- dot and norm (2-norm) sum the local partial results of all the leaves and
  run a single allreduce when every leaf is SCATTER, unmasked and shares the
  communicators; otherwise they use the per-child loop as before.
- Add tests (CPU, cupy and NCCL) for nested out=/in-place arithmetic and for
  fused versus fallback reductions, including the number of allreduces.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- CG and CGLS update x, r, s, c and q in place using the in-place operators
  of DistributedArray and StackedDistributedArray (Opc, and the previous r in
  CGLS, are reused as scratch space), and use vdot=True instead of conj()
  for the dot products of a vector with itself.
- CGLS skips the damping work (x * damp, x.dot(x)) when damp is zero, and
  needs 3 allreduces per iteration (2 for CG) instead of 5-10.
- The residual in the setup of CG and CGLS is written into the output of the
  matvec instead of allocating a new array.
- Add tests (CPU, cupy and NCCL): CGLS with and without damping compared to
  serial pylops (also checking that y and x0 are not modified) and the
  number of allreduces per iteration.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory and compute improvements in internals of DistributedOperator and solvers

2 participants