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

Update dpnp.linalg.svd() to run on CUDA #2212

Merged
merged 5 commits into from
Dec 6, 2024
Merged

Conversation

vlad-perevezentsev
Copy link
Collaborator

@vlad-perevezentsev vlad-perevezentsev commented Dec 4, 2024

This PR suggests updating dpnp.linagl.svd() implementation to support running on CUDA devices.
Since cuSolver gesvd only supports m>=n (Remark 1) the previous implementation crashed with Segmentation fault (core dumped)

$ ONEAPI_DEVICE_SELECTOR=cuda:gpu pytest -v dpnp/tests/test_linalg.py::TestSvd::test_svd

Python error: Segmentation fault

This suggests adding checks for m>=n otherwise transpose the input array.

Passing the transposed array to oneapi::mkl::lapack::gesvd increases the performance of dpnp.linalg.svd() due to the reducing a matrix with m >= n to bidiagonal form (inside lapack::gesvd) is more efficient


# 2D array 

$ a_shape = (1024,2048)
$ na = generate_random_numpy_array(a_shape, dtype='f4', seed_value=81)

$ a_dp = dpnp.array(na, device='gpu')

# GPU 
$ %timeit res_dp = dpnp.linalg.svd(a_dp);q.wait()
# 1.07 s ± 11 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

$ %timeit res_dp = dpnp.linalg.svd(a_dp,new=True);q.wait()
# 881 ms ± 2.52 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

$ a_dp = dpnp.array(na, device='cpu')

# CPU 
$ %timeit res_dp = dpnp.linalg.svd(a_dp);q.wait()
# 1.1 s ± 3.63 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

$ %timeit res_dp = dpnp.linalg.svd(a_dp,new=True);q.wait()
# 897 ms ± 3.89 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# 3D array

$ a_shape = (16,256,512)
$ na = generate_random_numpy_array(a_shape, dtype='f4', seed_value=81)


# GPU
$ %timeit res_dp = dpnp.linalg.svd(a_dp);q.wait()
# 979 ms ± 9.84 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

$ %timeit res_dp = dpnp.linalg.svd(a_dp,new=True);q.wait()
# 895 ms ± 6.79 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# CPU

$ %timeit res_dp = dpnp.linalg.svd(a_dp);q.wait()
# 753 ms ± 39.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

$ %timeit res_dp = dpnp.linalg.svd(a_dp,new=True);q.wait()
# 679 ms ± 26.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you filing the PR as a draft?

Copy link
Contributor

github-actions bot commented Dec 4, 2024

View rendered docs @ https://intelpython.github.io/dpnp/index.html

Copy link
Contributor

@antonwolfy antonwolfy left a comment

Choose a reason for hiding this comment

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

Thank you @vlad-perevezentsev, LGTM

@vlad-perevezentsev vlad-perevezentsev merged commit 4875e59 into master Dec 6, 2024
47 of 50 checks passed
@vlad-perevezentsev vlad-perevezentsev deleted the update_svd_cuda branch December 6, 2024 14:43
github-actions bot added a commit that referenced this pull request Dec 6, 2024
This PR suggests updating `dpnp.linagl.svd()` implementation to support
running on CUDA devices.
Since cuSolver gesvd only supports m>=n the previous implementation crashed with `Segmentation fault (core
dumped)`

This suggests adding checks for `m>=n` otherwise transpose the input
array.

Passing the transposed array to `oneapi::mkl::lapack::gesvd` increases
the performance of `dpnp.linalg.svd()` due to the reducing a matrix with
`m >= n` to bidiagonal form (inside `lapack::gesvd`) is more efficient 4875e59
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.

2 participants