Skip to content

Red2Band: use well-formed reflector for internal panel computations#1348

Merged
rasolca merged 2 commits into
masterfrom
alby/r2b-well-formed-refactoring
Oct 21, 2025
Merged

Red2Band: use well-formed reflector for internal panel computations#1348
rasolca merged 2 commits into
masterfrom
alby/r2b-well-formed-refactoring

Conversation

@albestro
Copy link
Copy Markdown
Collaborator

@albestro albestro commented Oct 8, 2025

This PR

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the reduction to band algorithm to use well-formed reflectors for internal panel computations, addressing both local and distributed implementations while extracting common operations in preparation for future refactoring.

Key changes include:

  • Extracted common reflector scaling operations into a reusable scaleReflector function
  • Modified panel computation to use well-formed reflectors (head = 1) temporarily during computations
  • Simplified function signatures by removing unused parameters and improving parameter types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 175 to +176
void updateTrailingPanel(const bool has_head, const std::vector<matrix::Tile<T, D>>& panel, SizeType j,
const std::vector<T>& w, const T tau, const std::size_t begin,
const std::size_t end) {
const TileElementIndex index_el_x0(j, j);

bool has_first_component = has_head;

const T* w, const T tau, const std::size_t begin, const std::size_t end) {
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

The parameter type changed from const std::vector<T>& w to const T* w. This is a breaking change that removes type safety and loses size information. Consider using std::span<const T> or keeping the vector reference to maintain type safety.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This change is part of the refactoring needed for #1338 where, to group communications, w is just a slice of a vector (e.g. algo_data[2:2+pt_cols]).

std::span might actually be the solution, but we have to wait for c++20.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Considering we switched to c++20 with #1346, I might be able to address this in #1338 😉


// STEP3: update trailing panel (multi-threaded)
updateTrailingPanel(has_head, tiles, j, w[0], taus({j, 0}), begin, end);
updateTrailingPanel(has_head, tiles, j, w[0].data(), taus({j, 0}), begin, end);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

Using .data() to convert from vector to raw pointer removes bounds checking and type safety. The function signature change appears to be unnecessary since the original vector reference was more type-safe.

Suggested change
updateTrailingPanel(has_head, tiles, j, w[0].data(), taus({j, 0}), begin, end);
updateTrailingPanel(has_head, tiles, j, w[0], taus({j, 0}), begin, end);

Copilot uses AI. Check for mistakes.

// STEP3: update trailing panel (multi-threaded)
updateTrailingPanel(has_head, tiles, j, w[0], taus({j, 0}), begin, end);
updateTrailingPanel(has_head, tiles, j, w[0].data(), taus({j, 0}), begin, end);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

Using .data() to convert from vector to raw pointer removes bounds checking and type safety. The function signature change appears to be unnecessary since the original vector reference was more type-safe.

Suggested change
updateTrailingPanel(has_head, tiles, j, w[0].data(), taus({j, 0}), begin, end);
updateTrailingPanel(has_head, tiles, j, w[0], taus({j, 0}), begin, end);

Copilot uses AI. Check for mistakes.
@albestro albestro changed the title Red2Band: use well-formed reflector for interal panel computations Red2Band: use well-formed reflector for internal panel computations Oct 9, 2025
@albestro
Copy link
Copy Markdown
Collaborator Author

albestro commented Oct 9, 2025

cscs-ci run

@albestro
Copy link
Copy Markdown
Collaborator Author

albestro commented Oct 9, 2025

Just double checked with a quick benchmark that this is going to be neither an harm nor a benefit performance-wise. It is more for the sake of the cleanup/refactoring.

Figure 5

I would say that the differences are almost null and probably due to noise.

@albestro albestro requested review from RMeli, msimberg and rasolca October 9, 2025 14:27
@albestro albestro marked this pull request as ready for review October 9, 2025 14:27
Copy link
Copy Markdown
Collaborator

@msimberg msimberg left a comment

Choose a reason for hiding this comment

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

Just a question about the use of optionals. The rest of the changes I can't judge too well, but looks good to me at a high level.

NB for the C++20/span question #1346 works well in DLA-Future, but still needs some verification in CP2K. I wouldn't wait for that to be able to use std::span, but at least according to https://en.cppreference.com/w/cpp/compiler_support.html#C.2B.2B20_library_features we should be able to unconditionally use std::span once that's in.

Comment thread include/dlaf/eigensolver/reduction_to_band/impl.h
Comment thread include/dlaf/eigensolver/reduction_to_band/impl.h
@albestro albestro moved this from In Progress to Review in DLA-F Planning Oct 20, 2025
@github-project-automation github-project-automation Bot moved this from Review to In Progress in DLA-F Planning Oct 21, 2025
@rasolca rasolca merged commit 49ad584 into master Oct 21, 2025
5 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in DLA-F Planning Oct 21, 2025
@rasolca rasolca deleted the alby/r2b-well-formed-refactoring branch October 21, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants