-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Sparse] Support Diag sparse format in C++ #5432
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ c10::intrusive_ptr<SparseMatrix> SpSpAdd( | |
const c10::intrusive_ptr<SparseMatrix>& A, | ||
const c10::intrusive_ptr<SparseMatrix>& B) { | ||
ElementwiseOpSanityCheck(A, B); | ||
if (A->HasDiag() && B->HasDiag()) { | ||
return SparseMatrix::FromDiagPointer( | ||
A->DiagPtr(), A->value() + B->value(), A->shape()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I will usually prefer parallel if-else branch, e.g., if (...) {
...
} else {
...
} @frozenbugs what would you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation is better.
|
||
auto torch_A = COOToTorchCOO(A->COOPtr(), A->value()); | ||
auto torch_B = COOToTorchCOO(B->COOPtr(), B->value()); | ||
auto sum = (torch_A + torch_B).coalesce(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this 3 conversion? In which case, they will be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are used for operators that do not have implementation on Diag format, e.g., SpMM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the implication of the performance here if we convert diag to COO/CSR/CSV for operators?
Will it strongly decrease the spmm performance?
This solution looks good to me, but let's make sure we understand the trade-off we are making here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply follow our current implementation to ensure no performance regression. Currently, we also convert the DiagMatrix to SparseMatrix for SpMM on the Python side.