Skip to content

Added methods to diagonally scale csr matrices on the left and right.#283

Merged
shakedregev merged 14 commits intodevelopfrom
shaked/real_diagonal_scale
May 27, 2025
Merged

Added methods to diagonally scale csr matrices on the left and right.#283
shakedregev merged 14 commits intodevelopfrom
shaked/real_diagonal_scale

Conversation

@shakedregev
Copy link
Copy Markdown
Collaborator

@shakedregev shakedregev commented May 23, 2025

Description

This is necessary to solve the issue of L and U being in the right format. See details here. Additionally, diagonal scaling is needed for SUNDIALS and HyKKT integration.

1 of the 2 steps necessary to close issue 251

Proposed changes

I added methods to diagonally scale CSR matrices on the left and right. This will allow the use of external codes and moving the unit diagonal when we transpose and switch L and U by interpreting their CSC representation as CSR. New unit tests pass.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask. We're here
to help! This is simply a reminder of what we are going to look for before
merging your code.

  • All tests pass. Code tested on
    • CPU backend
    • CUDA backend
    • HIP backend
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • The new code follows Re::Solve style guidelines.
  • There are unit tests for the new code.
  • The new code is documented.
  • The feature branch is rebased with respect to the target branch.

Further comments

This replaces #281 which was somehow hopelessly broken. A clarification: The different order of arguments for leftDiagonalScale(vector_type diag, matrix::Csr A) and rightDiagonalScale(matrix::Csr A, vector_type diag) is intentional to reflect the mathematics. There is no danger of the code compiling if the order of the arguments is switched. The functions have a different stamp so that the user is intentional about which one to call.

@shakedregev shakedregev marked this pull request as draft May 23, 2025 18:38
@shakedregev shakedregev marked this pull request as ready for review May 23, 2025 19:10
@shakedregev shakedregev self-assigned this May 23, 2025
@shakedregev shakedregev requested a review from pelesh May 23, 2025 19:10
@pelesh pelesh added enhancement New feature or request hip cuda labels May 25, 2025
Copy link
Copy Markdown
Collaborator

@pelesh pelesh left a comment

Choose a reason for hiding this comment

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

All tests pass on CUDA and HIP backends, code is reasonably well documented and unit tests are implemented.

One thing to take care of before merging is to put the code in line with style guidelines (or alternatively to wait until #261 is merged). In particular, note that:

  • Long function names are not correctly aligned.
  • There are no empty lines between different functions.
  • There are redundant empty lines i. the code.

I flagged a couple of examples, please check style in all new code.

Comment on lines +190 to +196
*/
__global__ void leftDiagScale(index_type n,
const index_type* a_row_ptr,
real_type* a_val,
const real_type* d_val)
{
// Get row index from thread and block indices
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either fix these or wait for #261 to be merged.

Comment on lines +213 to +215
}
/**
* @brief Scales a csr matrix on the right by a diagonal matrix
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

An empty line is needed between functions per Re::Solve guidelines.

Comment thread resolve/hip/hipKernels.hip Outdated
Comment on lines +542 to +543

// Define block size and number of blocks
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Te empty line is redundant here.

Comment thread resolve/matrix/MatrixHandler.cpp Outdated
pelesh
pelesh previously requested changes May 25, 2025
Copy link
Copy Markdown
Collaborator

@pelesh pelesh left a comment

Choose a reason for hiding this comment

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

Please wait for #284 to be merged first and then rebase.

@maksud maksud force-pushed the shaked/real_diagonal_scale branch from c18775b to 9682336 Compare May 27, 2025 18:10
@shakedregev shakedregev requested a review from pelesh May 27, 2025 18:30
@shakedregev shakedregev dismissed pelesh’s stale review May 27, 2025 18:31

I fixed the whitespace and rebased according to your comments. Please re-review.

@shakedregev shakedregev merged commit 36e9dc6 into develop May 27, 2025
4 checks passed
@shakedregev shakedregev deleted the shaked/real_diagonal_scale branch May 27, 2025 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda enhancement New feature or request hip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LinSolverDirectKLU quietly assumes each matrix is a CSC matrix

2 participants