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

WIP: TFQMR classes and reference kernels #23

Closed
wants to merge 4 commits into from
Closed

Conversation

hartwiganzt
Copy link
Collaborator

this is the initial tfqmr pull request. Core functionality + reference kernels

rel_residual_goal_)) {
break;
}
if (iter % 2 != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this if clause can go into an helper function after combining the two steps 1 and 5 so that you just have to pass in your different inputs to the helper function.

@gflegar gflegar added the is:new-feature A request or implementation of a feature that does not exist yet. label Mar 23, 2018
@gflegar gflegar changed the title Initial tfqmr TFQMR classes and reference kernels Mar 23, 2018
@gflegar gflegar removed the request for review from ginkgo-bot March 23, 2018 14:24
Copy link
Member

@gflegar gflegar left a comment

Choose a reason for hiding this comment

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

I didn't go through the whole thing, but I did find some serious problems with it - it seem that something is not right here. See inline comments. (That's why I haven't look at the rest in more detail.)

Also, I think we have a general problem with reviewing Krylov solvers, see #29.

Spent the whole day on this, but at least something useful came out of it: found a bug here, found several possible improvements, started a discussion on how we review Krylov solvers, reminded myself of the details of CG, and created a draft for better CG documentation.

{
for (size_type j = 0; j < d->get_num_cols(); ++j) {
if (alpha->at(j) != zero<ValueType>()) {
sigma->at(j) = theta->at(j) / alpha->at(j) * eta->at(j);
Copy link
Member

Choose a reason for hiding this comment

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

step_2 description says sigma = (theta^2 / alpha) * eta

} else {
theta->at(j) = one<ValueType>();
}
auto tmp = one<ValueType>() / sqrt(one<ValueType>() + theta->at(j));
Copy link
Member

Choose a reason for hiding this comment

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

description says c_mp1 = 1 / (1 + theta)

Ad->copy_from(d.get());

for (int iter = 0; iter < max_iters_; ++iter) {
if (iter % 2 == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Trying to mask two clearly different iterations into one has serious drawbacks:

  1. It is virtually impossible to understand (I just spent several hours trying to figure out what's going on here!). Krylov methods already have extremely complicated loop invariants, adding control statements to them just to decrease code size makes reasoning about them difficult. You need to mentally unroll the loop anyway, so why not just write it like that in the first place?
  2. You can merge more kernels than you have currently merged.
  3. You have quite a few additional operations that are completely unnecessary.

After figuring out what this does (all without understanding the Krylov method, just by looking at the sequence of operations), I found that there must be at least 1 bug in the algorithm here, that you actually need only 5 merged kernels for 2 iterations (instead of 7 for 1) and that you can avoid copying vectors 3 times and scalars 1 time over the course of 2 iterations. This is all by taking only a superficial look, and it might be possible to get even more savings. Of course, it didn't make sense to look into it in more detail, since there's a bug in the algorithm anyway.

See the following file for details: tfqmr.txt

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to keep the code as close as possible to the MATLAB code. The idea was that this could be used by users to match the functionality. I you outlined in #29 there may be another, more efficient way to go.

You can merge more kernels than you have currently merged.

Yes, I think we had this discussion on the phone. I would like to see timings to decide whether it is a good idea. But sure, I can do that.

You have quite a few additional operations that are completely unnecessary.

Not sure about that. For example, I think

[u_mp1] = u_m - [alpha] * v ! ERROR: the result is never used

is needed in the update step

pu_m = M^-1 [u_mp1] <- apply

for the even iteration counts.

you actually need only 5 merged kernels for 2 iterations (instead of 7 for 1)

Yes, we have more merging in MAGMA-sparse. And I wanted to see the performance difference because less merging is easier to understand.

Copy link
Member

Choose a reason for hiding this comment

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

I tried to keep the code as close as possible to the MATLAB code. The idea was that this could be used by users to match the functionality.

Functionality isn't dictated by implementation details, we shouldn't blindly stick to something if it doesn't work well.

Yes, I think we had this discussion on the phone. I would like to see timings to decide whether it is a good idea. But sure, I can do that.

I am aware of our discussion:

  1. Even if you keep scalar updates separate from vector updates, you can still merge more.
  2. Either way, you should merge Ginkgo kernels, and have some of them call two CUDA kernels. This performance issue is an implementation detail, which can differ for different devices, and shouldn't leak to the top-level solver implementation.

Not sure about that. For example, I think

[u_mp1] = u_m - [alpha] * v ! ERROR: the result is never used

is needed in the update step

pu_m = M^-1 [u_mp1] <- apply

for the even iteration counts.

u_mp1 gets updated before it's used here: [u_mp1] = w + [beta] * u_m. Just search for u_mp1 in any of the codes (the original file, my transcript of the code, or the unrolled one), and you'll see that there are two consecutive assigns to u_mp1.
This is something that's hard to notice in the original version of the code due to the convoluted implementation. If that's based on MATLAB's code, then their implementation is quite horrible.
Please take some more time to look through my comments (at least the error, and opt ones), and point out exactly what's wrong if something is wrong with them.

less merging is easier to understand.

I disagree, we have comments below, so you don't look at the merged call anyway. Where's the difference for the user if he sees calls to step_1 ..., step_5 as oposed to step_1, ...., step_7?
Also this code has far greater issues when it comes to "understanding".

@gflegar gflegar changed the title TFQMR classes and reference kernels WIP: TFQMR classes and reference kernels Jun 26, 2018
@gflegar gflegar added mod:core This is related to the core module. mod:reference This is related to the reference module. labels Jun 28, 2018
@gflegar
Copy link
Member

gflegar commented Nov 26, 2018

Closing this due to inactivity and interface changes done to the main Ginkgo branch that make this implementation obsolete (e.g. updated EnableLinOp mixin implementation, stopping criteria, loggers).

We should probably keep the branch for reference, until a proper TFQMR implementation is made.

@gflegar gflegar closed this Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:new-feature A request or implementation of a feature that does not exist yet. mod:core This is related to the core module. mod:reference This is related to the reference module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants