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

Native svd #16205

Closed
wants to merge 11 commits into from
Closed

Native svd #16205

wants to merge 11 commits into from

Conversation

rahulghangas
Copy link
Member

@rahulghangas rahulghangas commented Aug 6, 2020

  • Add tests

@rahulghangas rahulghangas marked this pull request as ready for review August 10, 2020 15:28
Copy link
Member

@ben-albrecht ben-albrecht left a comment

Choose a reason for hiding this comment

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

@rahulghangas - Nice start. I took a high-level pass over this and have some comments. I will pass the review torch to @dgarvit to take the next more in-depth review iteration.

Some notes:

  • Performance
    • I am seeing a lot of nested parallelism and parallel forall loops over small ranges.
    • I would experiment to see if the nested parallel loops are beneficial or are degrading performance due to task creation overhead / too many tasks running in parallel
  • Docs/comments
    • I think we should reference the numerical recipes book chapter in the comment block above the function. It's good to cite references, and also helpful for someone else trying to follow the code.
    • We can update the other svd() comment block to remove the note about requiring LAPACK for svd
      • Or maybe the native svd() deserves its own separate documented function (what do others think?)
    • Speaking of comments, this code could use some more comments describing what's going on in general 😄
  • Testing
    • We could use more testing (correctness and performance). More details inline.

BTW - there are some interesting improvements discussed in #16200 (comment) (I think you're following along). We should discuss these as follow-on improvements (as time permits this summer).

Thanks!

@@ -0,0 +1,26 @@
use LinearAlgebra;
Copy link
Member

Choose a reason for hiding this comment

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

Good initial tests. I think it would be beneficial to cover some of the edge cases (over/under-determined matrices, singular matrices).

The scipy.linalg has some example cases to check against.

If we end up not adding complex support for this PR, we ought to add a future for it (let me know if you have any questions about that process).

Copy link
Member

Choose a reason for hiding this comment

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

Also, a performance test would be great, since we intend to optimize this implementation going forward.

In fact, getting LAPACK svd vs. Chapel svd on the same nightly performance-tracking plot could be really cool

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add those ASAP


if i < m {

forall k in i..<m with (+ reduce scale) do scale += abs(U[k,i]);
Copy link
Member

Choose a reason for hiding this comment

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

Can this be written as something like this? (note: I didn't try this myself)

Suggested change
forall k in i..<m with (+ reduce scale) do scale += abs(U[k,i]);
scale = + reduce (abs(U[1..<m, i]));

Copy link
Member

Choose a reason for hiding this comment

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

This applies to a bunch of reductions below as well.

Copy link
Member Author

@rahulghangas rahulghangas Aug 17, 2020

Choose a reason for hiding this comment

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

I did that because Damian mentioned something about it in the mailing lists - explicit forall loops performing better for reductions than array slicing. I'll double check the emails and perform some local testing as well to confirm

return if b >= 0:t then (if a >= 0 then a else -a) else (if a >= 0 then -a else a);
}

private inline proc pythag(a : ?t, b : t) : t {
Copy link
Member

Choose a reason for hiding this comment

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

Even private helper functions deserve doc strings IMO.

@@ -1757,6 +1757,261 @@ proc svd(A: [?Adom] ?t) throws
return (u, s, vt);
}

pragma "no doc"
proc svd(A : [?Adom] ?eltType, iterations : int = 30, eps : real = 1e-8)
Copy link
Member

Choose a reason for hiding this comment

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

These news args will need to be documented. Maybe we want 2 separate documented functions for svd since their interface doesn't 100% match.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would be in favor of having separate documentations until both interfaces can be unified

@e-kayrakli
Copy link
Contributor

Hi @rahulghangas -- will you be able to make some progress on the open discussions on this PR soon? If not, I'd encourage closing the PR and reopen once you have the time to work on it.

@e-kayrakli
Copy link
Contributor

Based on silence, I am closing this PR.

@rahulghangas -- Please feel free to reopen when you have the time to work on this.

@e-kayrakli e-kayrakli closed this Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants