Skip to content

Xorgqr - #1112

Draft
jprhyne wants to merge 43 commits into
Reference-LAPACK:masterfrom
jprhyne:xorgqr
Draft

Xorgqr#1112
jprhyne wants to merge 43 commits into
Reference-LAPACK:masterfrom
jprhyne:xorgqr

Conversation

@jprhyne

@jprhyne jprhyne commented Mar 8, 2025

Copy link
Copy Markdown
Contributor

Description
Hey Y'all!

I implementted some performance improvements for computing the explicit Q factor in the X{or,un}gY routines. This takes 2 forms.

  1. I added an xlarfb that takes into account the fact that we always apply to a C where C_1 is 0. This leads to some improvements in performance as well as on the first iteration assuming that C_2 is I. This also leads to some performance improvements especially as the block size increases
  2. For the routines X{or,un}gq{rl} where the T matrix returned from Xlarft is the same shape as the triangular factor, we can actually omit the workspace requirements for this routine (aside from calls to X{or,un}2{rl} which still needs that extra vector) which opens the door for some more
    improvements down the line which I am in the process of implementing.
    1. Vendors and users can investigate the blocksize (NB) increasing more freely as we no longer have the concern of memory availability.
    2. This allows for an in place panel factorization which is faster than the unblocked code for the standard blocksize of 32 on the machine I tested this on.

A more formal writeup of this can be found at my repository for my Master's Project

I compiled the tex file with the current version of pdftex on a linux machine.

In addition, I have attached some performance plots of computing the Q factor from the QR and LQ factorizations in double precision to motivate why I think it will be beneficial to refactor xLARFT to return a T matrix of the same shape as the triangular factor even before implementing the panel factorization. To see the justification of the panel factorization, see the above linked repository folder

dorgqrDorglqOptPerfExperiments.pdf
dorgqrDorglqPerfExperiments.pdf
dorgqrPerfExperiments.pdf

I ran these experiments on an AMD EPYC 7502 CPU and I ran each experiment 10 times reporting the mean of those experiments. To see the form of these experiments, see the files titled timeDorgqrVsDorglq.c, timeDorgqrVsDorglq.sh, and time_dorgqr_vs_dorglq.batch found here. The .c file is the main driver that calls our FORTRAN routines and times execution, the .sh file calls our .c file with varying inputs, and the .batch file is what is used to run the job via slurm on the HPC I used.

The main takeaway from these figures is that the slight improvements that we see in QR are not present as much in the LQ factorization so even without the more efficient panel factorization.

Checklist

  • The documentation has been updated.
  • If the PR solves a specific issue, it is set to be closed on merge.

langou
langou previously approved these changes May 7, 2025
@jprhyne
jprhyne marked this pull request as draft October 23, 2025 21:54
@mohawk2

mohawk2 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

This may be none of my business, sorry if so. It looks a lot to me like ?ACXPY should be a BLAS level 1 routine?

Also, 27000+ lines of code is quite a lot. Might it make sense to break this down into chunks?

Also also, from a git point of view, merging master onto your branch instead of rebasing your branch against master can create chaos and confusion, and best practice is instead to use rebase. I'd be happy to help with either of these points if you'd like.

@jprhyne

jprhyne commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

This may be none of my business, sorry if so. It looks a lot to me like ?ACXPY should be a BLAS level 1 routine?

Also, 27000+ lines of code is quite a lot. Might it make sense to break this down into chunks?

Also also, from a git point of view, merging master onto your branch instead of rebasing your branch against master can create chaos and confusion, and best practice is instead to use rebase. I'd be happy to help with either of these points if you'd like.

@mohawk2

?ACXPY was a bit of a hack job by me to try to avoid calling {c,z}gemm in some cases, but after some more development we concluded that it's just better to use GEMM unless we want to take on the mantle of adding this to BLAS and pushing for it to be optimized, which is a bit beyond the scope of what I am able to do at this point.

We also agree that doing all this in one go was not the correct move and we are breaking this down as follows:

  1. Do lvl2 stuff (need to fix some errors and conflicts there which I plan to do today)
  1. Update computing the T factor and implement the UT based form
  2. Add a larfb0c2 that properly takes into account the 0 block
    • Files are here but not in a new PR yet (will do the above first)
  3. Add the new panel factorization (new routines I am currently calling {or/un}gkr)
    • Files are here but not in a new PR yet (will do the above first)
  4. Update the q generation routines with all the above changes

I would like to keep this draft around so that I can reference it in the new PRs and give some reasoning for why we are doing some things as I think it makes some of them more defensible (And reminds me to actually finish the job instead of sitting around on it for way too long), but we can delete it if that's poor practice/not how we want to work in this repository.

For the 3 that are not made yet, I may add more smaller PRs to keep it more reasonable.

It's my first time really working in a repo this large, so I appreciate all the insight and help structuring everything in a sensible way!

I'll keep the rebase idea in mind as I am fixing other conflicts as I did the merge previously and that kinda made the history hard to read (only 3 commits but I can see how larger PRs would drastically complicate this)

@mohawk2

mohawk2 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

?ACXPY was a bit of a hack job by me to try to avoid calling {c,z}gemm in some cases, but after some more development we concluded that it's just better to use GEMM unless we want to take on the mantle of adding this to BLAS and pushing for it to be optimized, which is a bit beyond the scope of what I am able to do at this point.

My understanding of general practice in this project is it would definitely want to be in BLAS. It being optimised isn't a thing the reference implementation needs to do, though; that only needs to be correct (and have good tests).

We also agree that doing all this in one go was not the correct move and we are breaking this down as follows:
[snip]

Looks like a good plan to me.

I would like to keep this draft around so that I can reference it in the new PRs and give some reasoning for why we are doing some things as I think it makes some of them more defensible (And reminds me to actually finish the job instead of sitting around on it for way too long), but we can delete it if that's poor practice/not how we want to work in this repository.

That's not for me to say, but it being in draft makes it clear what is going on at least to me.

I'll keep the rebase idea in mind as I am fixing other conflicts as I did the merge previously and that kinda made the history hard to read (only 3 commits but I can see how larger PRs would drastically complicate this)

@jprhyne Based on my experience dealing with other large projects, getting the branch strategy right can make things a lot easier. I suggested above that you rebase this against current master, but I should qualify that. There is, as we can tell, at least one conflict between this change as written, and the latest code. To avoid having to resolve that any more than necessary, it would be very beneficial to rebase -i this set of commits into a smaller set, reflecting the set of changes you materially want to make. You'd do that against the point you started your branch, and squash (or fixup) things until you had a smaller set of commits - one huge commit is possible, but I'd recommend somewhere between 1 and the current number according to taste and your understanding of your change. An example of a change that doesn't need to remain separate is where you fixed some compilation warnings.

With that smaller set of commits, you would then rebase those against current master, doing resolution. Once done, you might then have some commits that you could pull out into immediate other PRs.

An alternative approach is to boil things down to one huge commit, rebase that against master (so only doing the resolving once), then split that commit up into atomic pieces by doing:

  • git reset HEAD^ - this leaves all the files changed, none staged or committed
  • git diff - analyse what all the diffs are, though this won't show files you've added so bear that in mind
  • Form a plan of how to structure the changes in a set of commits
  • git add -p to selectively add parts - an alternative is just to git add individual files
  • git commit -m "suitable commit message" - iterate this with the previous step until everything is there

You may also need to actually rebase this set of changes against sub-parts you've already made, to avoid clashes and redundancy. This is quite a complex set of activities, but I don't think it's simplifiable a lot further. One possibility would be to make sub-PRs by cherry-picking either the uber-commit, or some commits from this untouched branch, git reset HEAD^, add the things you want to, and then erase the rest of the changes, which is safe because you'd be on a new branch.

If you'd like to discuss this further, it would probably make most sense to do over email or even something like Teams.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants