-
Notifications
You must be signed in to change notification settings - Fork 118
Fix scalar jacobi generate on different precision and add DiagonalLinOpExtractable #834
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
Changes from all commits
47312f1
d9392ee
76b3881
824e7e4
914d0f4
28e8097
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
| #include <ginkgo/core/base/executor.hpp> | ||||||
| #include <ginkgo/core/base/math.hpp> | ||||||
| #include <ginkgo/core/base/precision_dispatch.hpp> | ||||||
| #include <ginkgo/core/base/temporary_conversion.hpp> | ||||||
| #include <ginkgo/core/base/utils.hpp> | ||||||
| #include <ginkgo/core/matrix/csr.hpp> | ||||||
| #include <ginkgo/core/matrix/dense.hpp> | ||||||
|
|
@@ -231,11 +232,20 @@ void Jacobi<ValueType, IndexType>::generate(const LinOp *system_matrix, | |||||
| using csr_type = matrix::Csr<ValueType, IndexType>; | ||||||
| const auto exec = this->get_executor(); | ||||||
| if (parameters_.max_block_size == 1) { | ||||||
| auto diag = as<DiagonalExtractable<ValueType>>(system_matrix) | ||||||
| ->extract_diagonal(); | ||||||
| auto temp = gko::Array<ValueType>::view( | ||||||
| exec, system_matrix->get_size()[0], diag->get_values()); | ||||||
| auto diag = share(as<DiagonalLinOpExtractable>(system_matrix) | ||||||
| ->extract_diagonal_linop()); | ||||||
| auto diag_vt = | ||||||
| ::gko::detail::temporary_conversion<matrix::Diagonal<ValueType>>:: | ||||||
|
Member
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. same here: Is the fully qualified name necessary?
Suggested change
Member
Author
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. I need to put |
||||||
| template create<matrix::Diagonal<next_precision<ValueType>>>( | ||||||
| diag.get()); | ||||||
| if (!diag_vt) { | ||||||
| GKO_NOT_SUPPORTED(system_matrix); | ||||||
| } | ||||||
| auto temp = Array<ValueType>::view(diag_vt->get_executor(), | ||||||
| diag_vt->get_size()[0], | ||||||
| diag_vt->get_values()); | ||||||
| this->blocks_ = temp; | ||||||
| this->num_blocks_ = diag_vt->get_size()[0]; | ||||||
| } else { | ||||||
| auto csr_mtx = convert_to_with_sorting<csr_type>(exec, system_matrix, | ||||||
| skip_sorting); | ||||||
|
|
||||||
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.
Is there some reason we need the
extract_diagonal_linopandextract_diagonalwill not work ?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.
extract_diagonal require the valuetype, but extract_diagonal_linop does not. we can get the diag first and then check which precision to work.
I am thinking do the dynamic_cast to check the matrix type and use corresponding extract_diag.
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.
An alternative to DiagonalLinOpExtractable would be using
from the non-scalar branch and extracting from that. That would also make for more consistent behavior between scalar and block Jacobi.
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 would like to avoid the converting matrix self because we need to pay more for it against converting diag
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.
Could we also not convert the extracted diagonal after calling the
extract_diagonal. Currently,Diagonaldoes not have mixed precision convert methods, but we could easily add thoseThere 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.
Oh yes, I think I like that idea best of all suggestions yet :)
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.
but the issue is different, right?
you still need to dynamic_cast to the correct type first.
and it is the same impl in the current one if we use default behavior
if we use direct mapping, we need to add all matrix to support it (at least csr)
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.
Actually, i am a bit confused as to how the current implementation works.
extract_diagonal_linopshould return aDiagonalofValueTyperight ? Because it is just calling theextract_diagonalofCsr<ValueType, IndexType>. So, the else if branch in line 243, will never be taken ?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.
extract_diagonal_linopreturns LinOp (it isDiaonal<system_matrix ValueType>), the valuetype is from system matrix not from the jacobi.I realize we miss the precision convert in Diagonal, but I guess I can not use it directly 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.
You could use something similar to
make_temporary_conversion. The framework also supports other matrix types, you only need to wrap it like you see in that function. Precision conversions in Diagonal is definitely a good idea, I forgot to suggest those when we added the format.