-
Notifications
You must be signed in to change notification settings - Fork 99
Avoid reallocation for self residual norm calculation #1898
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
base: develop
Are you sure you want to change the base?
Conversation
using dense_b_type = std::remove_cv_t< | ||
std::remove_reference_t<decltype(*dense_b)>>; |
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.
Isn't this the same as
using dense_b_type = std::remove_cv_t< | |
std::remove_reference_t<decltype(*dense_b)>>; | |
using dense_b_type = std::decay_t<decltype(*dense_b)>>; |
initial_res.get()); | ||
auto abs_criterion = this->abs_factory_->generate(system_mtx, rhs, nullptr, | ||
initial_res.get()); | ||
{ |
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.
Either these blocks need a SCOPED_TRACE
or the above is extracted into a new test fixture and the blocks are fully separated.
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.
The aim looks good, but I would like to aim towards reducing mutable
usage in our classes. That would also make thread-safety #996 easier. If we can collect the thread-unsafe parts of Ginkgo in a small number of places, like the dense caches and workspaces, then we only need to make sure those work safely across multiple threads, and the rest follows automatically. Without mutable
, we can also rely on const
-ness implying thread-safety.
mutable gko::array<char> reduction_tmp_; | ||
// temporary rhs for residual computation | ||
mutable std::shared_ptr<LinOp> rhs_{}; |
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 think we should avoid adding more mutable
functionality, and instead either find a way to include the stopping criteria in the workspace setup, or hide it behind an opaque pointer, so at least there is no mutability in the public interface. We could do this by adding a workspace parameter to the check
function and having the old version create a temporary workspace.
In most of our solver, we need to calculate the actual residual norm by
b - Ax
when required because these solvers only have the implicit residual norm, which is updated from the previous iteration such that it might not be correct enough for residual norm like CG.This PR avoids reallocation the internal rhs in each iteration.
Note. we still have the allocation when generating the criterion, but it also requires storing the criterion in the solver and it is more critical when we setup some residual-norm aware smoother not the usual setup.