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

Mixed Precision ISAI #719

Closed
wants to merge 5 commits into from
Closed

Mixed Precision ISAI #719

wants to merge 5 commits into from

Conversation

fritzgoebel
Copy link
Collaborator

@fritzgoebel fritzgoebel commented Mar 10, 2021

This PR makes the ISAI preconditioner support reduced precision storage format.
It is based on Tobias' mp spmv approach for ell, which is slightly changed to use an accessor on both the matrix values and the input vector, for now always using the ValueType of the output vector as arithmetic type.

Points I would like to discuss are:

  • The ISAI matrix is now stored in ell. Without breaking interface, we would need to convert this to csr when retrieving the preconditioner matrix with get_approximate_inverse().
  • I introduced GKO_INSTANTIATE_FOR_EACH_VALUE_INDEX_AND_STORAGE_TYPE in types.hpp to make this work. I'm not really happy with having this additional to the mixed value and index types Tobias already introduced, maybe we can find a better way.
  • The preconditioner matrix is stored in the precision of StorageType. When retrieving the preconditioner matrix of a preconditioner with ValueType, I'm not 100% sure which precision the returned matrix should be stored in. For now, I went with converting it to ValueType.
  • For now, the storage type of the preconditioner matrix is a template. Another option would be to have it as a factory parameter somehow, for that I didn't find a nice way to do it yet though.
  • To support half precision storage, I think Ell will have to fully support half.

Todos:

@ginkgo-bot ginkgo-bot added mod:all This touches all Ginkgo modules. reg:benchmarking This is related to benchmarking. reg:build This is related to the build system. reg:ci-cd This is related to the continuous integration system. reg:documentation This is related to documentation. reg:example This is related to the examples. reg:testing This is related to testing. type:matrix-format This is related to the Matrix formats type:preconditioner This is related to the preconditioners type:solver This is related to the solvers labels Mar 10, 2021
@fritzgoebel fritzgoebel added the 1:ST:WIP This PR is a work in progress. Not ready for review. label Mar 10, 2021
@fritzgoebel fritzgoebel requested review from a team, hartwiganzt, pratikvn, Slaedr, tcojean, thoasm, upsj and yhmtsai and removed request for a team March 10, 2021 16:48
@fritzgoebel fritzgoebel self-assigned this Mar 10, 2021
@fritzgoebel
Copy link
Collaborator Author

format!

@fritzgoebel fritzgoebel added 1:ST:ready-for-review This PR is ready for review and removed 1:ST:WIP This PR is a work in progress. Not ready for review. labels Mar 17, 2021
@codecov
Copy link

codecov bot commented Mar 19, 2021

Codecov Report

Merging #719 (334b5ca) into develop (95c7652) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #719   +/-   ##
========================================
  Coverage    94.17%   94.18%           
========================================
  Files          400      400           
  Lines        31051    31084   +33     
========================================
+ Hits         29241    29275   +34     
+ Misses        1810     1809    -1     
Impacted Files Coverage Δ
core/preconditioner/isai.cpp 95.16% <100.00%> (-0.94%) ⬇️
include/ginkgo/core/preconditioner/isai.hpp 100.00% <100.00%> (ø)
reference/test/preconditioner/isai_kernels.cpp 96.42% <100.00%> (+0.07%) ⬆️
core/base/extended_float.hpp 92.23% <0.00%> (+0.97%) ⬆️
include/ginkgo/core/base/utils_helper.hpp 87.17% <0.00%> (+2.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95c7652...334b5ca. Read the comment docs.

thoasm
thoasm previously requested changes Mar 23, 2021
Copy link
Member

@thoasm thoasm left a comment

Choose a reason for hiding this comment

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

There are some parts that I would really like to change before merging this PR.

Additionally, I realized that it might make sense to make SpdIsai and GeneralIsai separate classes or at least specialization of the current Isai because:

  1. they seem to not share too much with LowerIsai and UpperIsai
  2. there is a lot of branching in all functions
  3. all Isai preconditioner (including LowerIsai and UpperIsai) are stored in ELL in the current implementation
  4. get_approximate_inverse has a lot of overhead now

Comment on lines 255 to 252
template <typename OutType, typename InType>
std::shared_ptr<OutType> convert_matrix_formats(
std::shared_ptr<InType> in) const
{
if (std::is_same<OutType, InType>::value) {
return as<OutType>(in);
}

auto out = OutType::create(in->get_executor());
if (std::is_same<
InType, gko::matrix::Csr<typename InType::value_type,
typename InType::index_type>>::value) {
auto tmp = gko::matrix::Csr<
typename OutType::value_type,
typename InType::index_type>::create(in->get_executor());
as<Csr>(in)->convert_to(tmp.get());
tmp->convert_to(out.get());
return share(out);
} else {
auto tmp = gko::matrix::Ell<
typename OutType::value_type,
typename InType::index_type>::create(in->get_executor());
as<Ell>(in)->convert_to(tmp.get());
tmp->convert_to(out.get());
return share(out);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I have some problems with this function:

  1. It should be private to not be part of the public interface
  2. It needs documentation
  3. The function can only convert CSR <-> ELL and not arbitrary conversions (which the use of templates suggest)

@sonarqubecloud
Copy link

@thoasm thoasm mentioned this pull request Mar 26, 2021
4 tasks
@upsj upsj added this to the Ginkgo 1.4.0 milestone May 5, 2021
Copy link
Member

@tcojean tcojean left a comment

Choose a reason for hiding this comment

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

LGTM. Some minor comments.

@upsj upsj modified the milestones: Ginkgo 1.4.0, Ginkgo 1.5.0 Jun 1, 2021
@thoasm thoasm dismissed their stale review June 3, 2021 17:30

Stale Review

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 6, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

90.3% 90.3% Coverage
0.0% 0.0% Duplication

thoasm
thoasm previously approved these changes Jun 10, 2021
Copy link
Member

@thoasm thoasm left a comment

Choose a reason for hiding this comment

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

LGTM!

tcojean
tcojean previously approved these changes Jun 10, 2021
Copy link
Member

@tcojean tcojean left a comment

Choose a reason for hiding this comment

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

LGTM.

@tcojean tcojean added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:ready-for-review This PR is ready for review labels Jun 10, 2021
Copy link
Member

@upsj upsj left a comment

Choose a reason for hiding this comment

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

LGTM in general. To be honest though, I would rather want to wait for full mixed-precision support in Csr instead of choosing Ell just because it is the only type where we put in the effort to make it mixed-precision capable. Coo would probably also be alternative with low development effort for the changes, and could provide much better worst-case performance.

Comment on lines +123 to +125
Isai<IsaiType == isai_type::lower
? isai_type::upper
: IsaiType == isai_type::upper ? isai_type::lower : IsaiType,
Copy link
Member

@upsj upsj Jun 10, 2021

Choose a reason for hiding this comment

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

could we move this into a

constexpr isai_type transpose(isai_type type) {
    return type == isai_type::lower ? isai_type::upper : type == isai_type::upper ? isai_type::lower : type;
}

function?

Suggested change
Isai<IsaiType == isai_type::lower
? isai_type::upper
: IsaiType == isai_type::upper ? isai_type::lower : IsaiType,
Isai<transpose(IsaiType),

@thoasm thoasm added 1:ST:WIP This PR is a work in progress. Not ready for review. and removed 1:ST:ready-to-merge This PR is ready to merge. labels Jun 14, 2021
@tcojean tcojean added mod:core This is related to the core module. mod:reference This is related to the reference module. and removed mod:all This touches all Ginkgo modules. reg:benchmarking This is related to benchmarking. reg:build This is related to the build system. reg:ci-cd This is related to the continuous integration system. reg:documentation This is related to documentation. reg:example This is related to the examples. type:matrix-format This is related to the Matrix formats type:preconditioner This is related to the preconditioners labels Jun 24, 2021
@upsj upsj dismissed stale reviews from tcojean and thoasm August 26, 2022 14:54

stale

@tcojean tcojean removed this from the Ginkgo 1.5.0 milestone Oct 20, 2022
@upsj
Copy link
Member

upsj commented Jun 27, 2023

I think this PR may be obsolete with Csr now being mixed-precision capable?

@fritzgoebel
Copy link
Collaborator Author

Yes, I will close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:WIP This PR is a work in progress. Not ready for review. mod:core This is related to the core module. mod:reference This is related to the reference module. reg:testing This is related to testing. type:solver This is related to the solvers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants