Skip to content

Implement cupy.linalg.eig / cupy.linalg.eigvals#8854

Merged
13 commits merged intocupy:mainfrom
EarlMilktea:impl-eig
May 29, 2025
Merged

Implement cupy.linalg.eig / cupy.linalg.eigvals#8854
13 commits merged intocupy:mainfrom
EarlMilktea:impl-eig

Conversation

@EarlMilktea
Copy link
Copy Markdown
Member

@EarlMilktea EarlMilktea commented Dec 27, 2024

This closes #3255 and also closes #6359 .

This PR uses cusolverDnXgeev to solve non-hermitian eigenvalue problems on GPU.

@EarlMilktea EarlMilktea marked this pull request as ready for review January 8, 2025 07:55
@EarlMilktea EarlMilktea marked this pull request as draft January 8, 2025 08:13
cupy.linalg._util._check_cusolver_dev_info_if_synchronization_allowed(
cusolver.xgeev, dev_info)

if all(w.imag == 0.0):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like the NumPy behavior but it looks like we have to follow... 🙁

Q: can we find a way to not create an intermediate array of bools for later reduction? Perhaps this can be replaced by a simple ReductionKernel?

Comment on lines +245 to +247
work = [_geev(a[ind, :, :], True) for ind in numpy.ndindex(a.shape[:-2])]
w = cupy.stack([x[0] for x in work])
v = cupy.stack([x[1] for x in work])
Copy link
Copy Markdown
Member

@leofang leofang Jan 9, 2025

Choose a reason for hiding this comment

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

This uses a Python loop to call geev. I suggest:

  1. either we create an issue to track this overhead before merging, or
  2. we just move this loop to C++ in this PR (see cusolver.pyx for batched SVD/QR examples)



# TODO(okuta): Implement eig
def _geev(a, with_eigen_vector, overwrite_a=False):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Q: it seems we never see overwrite_a being set to True?

@leofang
Copy link
Copy Markdown
Member

leofang commented Feb 11, 2025

@EarlMilktea any chance we can push this across the finish line? Do you need any help? Or should I find someone to take over?

@leofang

This comment was marked as resolved.

@leofang
Copy link
Copy Markdown
Member

leofang commented Feb 12, 2025

sorry, confused myself...

/test mini

@asi1024 asi1024 closed this pull request by merging all changes into cupy:main in 1cbf094 May 29, 2025
@kmaehashi kmaehashi added this to the v14.0.0a2 milestone Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:feature New features/APIs prio:high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation of numpy.linalg.eigvals equivalent Implementation of numpy.linalg.eig equivalent

4 participants