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

Fix RuntimeError raising in dpnp.linalg.solve() #1763

Merged
merged 15 commits into from
Apr 8, 2024
Merged

Conversation

vlad-perevezentsev
Copy link
Collaborator

@vlad-perevezentsev vlad-perevezentsev commented Mar 28, 2024

This PR suggests using oneapi::mkl::lapack::getrf and oneapi::mkl::lapack::getrs call instead of oneapi::mkl::lapack::gesv in implementation of dpnp.linalg.solve() as a workaround for MKLD-17226 and allows to handle cases where nrhs > n for a_shape (n x n) and b_shape (n x nrhs).

Example output with RuntimeError

import dpnp
a = dpnp.random.randn(4, 4)
b = dpnp.random.randn(4,8)
dpnp.linalg.solve(a,b) 

RuntimeError: oneapi::mkl::lapack::oneapi::mkl::lapack::gesv_scratchpad_size: invalid argument: Illegal value supplied for parameter ldb

Output after changes

import dpnp
a = dpnp.random.randn(4, 4)
b = dpnp.random.randn(4,8)
dpnp.linalg.solve(a,b)

array([[ 0.27049825, -0.0759692 , -0.07950702,  0.0958712 , -0.02981571,
        -0.12020214,  0.04122682,  0.3428937 ],
       [ 0.2031857 ,  0.7249918 , -0.02911178,  0.70907384,  1.1388483 ,
        -1.0657178 , -0.20844322,  0.5454692 ],
       [-0.07283728,  1.4617094 ,  0.3319773 , -0.11885316,  2.1953962 ,
        -0.2161203 , -0.43200532, -0.52245396],
       [-3.145333  ,  0.72767526, -1.4317869 , -0.53916854, -1.2468526 ,
         2.3493161 ,  1.0770481 ,  0.02750631]], dtype=float32)

  • 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 Mar 28, 2024

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

dpnp/backend/extensions/lapack/getrs.cpp Outdated Show resolved Hide resolved
tests/test_linalg.py Outdated Show resolved Hide resolved
dpnp/linalg/dpnp_utils_linalg.py Outdated Show resolved Hide resolved
@vlad-perevezentsev vlad-perevezentsev changed the title Update dpnp.linalg.solve() with w/a for SAT-6701 Fix RuntimeError raising in dpnp.linalg.solve() Apr 3, 2024
@antonwolfy antonwolfy merged commit 2a2cdfa into master Apr 8, 2024
45 checks passed
@antonwolfy antonwolfy deleted the solve_workaround branch April 8, 2024 21:13
github-actions bot added a commit that referenced this pull request Apr 8, 2024
* Correct parameter calculation for gesv

* Use getrf and getrs MKL funcs in dpnp_solve for 2d array

* Add test to cover SAT-6701 case

* Extend test_solve in test_sycl_queue.py

* Address remarks

* Support  as F-contiguous for _getrs

---------

Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com> 2a2cdfa
github-actions bot added a commit to antonwolfy/dpnp that referenced this pull request Apr 8, 2024
* Correct parameter calculation for gesv

* Use getrf and getrs MKL funcs in dpnp_solve for 2d array

* Add test to cover SAT-6701 case

* Extend test_solve in test_sycl_queue.py

* Address remarks

* Support  as F-contiguous for _getrs

---------

Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com> 2a2cdfa
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