Skip to content

Add 3 new element-wise vector operations #413

Merged
pelesh merged 14 commits intodevelopfrom
alex/add-elementwise-vector-ops
Mar 18, 2026
Merged

Add 3 new element-wise vector operations #413
pelesh merged 14 commits intodevelopfrom
alex/add-elementwise-vector-ops

Conversation

@alexander-novo
Copy link
Collaborator

@alexander-novo alexander-novo commented Feb 26, 2026

Description

Add a new vector operations:

  • scaleInv which performs like scale, but scales by the inverse of a diagonal matrix.
  • max which computes a vector whose elements are the maximum of the corresponding elements in the two input vectors.
  • abs which computes a vector whose elements are the absolute values of the corresponding element in the input vector.

Supplants #409 and is based on top of #411

Proposed changes

N/A

Checklist

  • All tests pass (make test and make test_install per testing instructions). Code tested on
    • CPU backend
    • CUDA backend
    • HIP backend
  • I have manually run the non-experimental examples and verified that residuals are close to machine precision. (In your build directory run:
    ./examples/<your_example>.exe -h to get instructions how to run examples). 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.
  • I have updated CHANGELOG.md to reflect the changes in this PR. If this is a minor PR that is part of a larger fix already included in the file, state so.

Further comments

N/A

@alexander-novo alexander-novo changed the title Alex/add elementwise vector ops Add 3 new element-wise vector operations Feb 26, 2026
@alexander-novo alexander-novo added enhancement New feature or request hip cuda labels Feb 26, 2026
@alexander-novo alexander-novo added this to the Release 0.99.3 milestone Feb 26, 2026
@pelesh pelesh requested review from pelesh and shakedregev March 2, 2026 22:10
@pelesh
Copy link
Collaborator

pelesh commented Mar 2, 2026

If we are using BLAS-like naming scheme as in #411, I suggest we rename the methods as follows:

void scaleInv(const Vector* D, Vector* x); // multiply each x[i] with 1./D[i]
void max(const Vector* x, const Vector* y, Vector* z); // z[i] = max(x[i], y[i])
void abs(const Vector* x, Vector* y); // y[i] = abs(x[i])

I would allow in max, for example, to have x==z or y==z for more flexibility.

I also wouldn't hard-wire block size within kernels. Try something like

constexpr index_type block_size = 256;

within the proper namespace.

@pelesh pelesh force-pushed the slaven/vector-handler-cleanup branch from 2a26d63 to 8d6fea5 Compare March 3, 2026 20:51
@pelesh pelesh changed the base branch from slaven/vector-handler-cleanup to develop March 3, 2026 21:05
@alexander-novo alexander-novo force-pushed the alex/add-elementwise-vector-ops branch from 1bbdabc to 910c90d Compare March 3, 2026 22:09
@alexander-novo
Copy link
Collaborator Author

I also wouldn't hard-wire block size within kernels. Try something like

constexpr index_type block_size = 256;

within the proper namespace.

The rest of the kernels in this module have hard-wired block sizes.

@alexander-novo
Copy link
Collaborator Author

Should be ready to review

Copy link
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.

I fixed issues with HIP and CUDA kernels. Would like review by @shakedregev before merging.

Copy link
Collaborator

@shakedregev shakedregev left a comment

Choose a reason for hiding this comment

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

Fix the naming stuff, otherwise looks good. I still need to run it.

@alexander-novo
Copy link
Collaborator Author

@shakedregev Can you show me where the floating point conventions are described? There are several other .5 values without the 0 in the same file.

@shakedregev
Copy link
Collaborator

@shakedregev Can you show me where the floating point conventions are described? There are several other .5 values without the 0 in the same file.

You're correct that the rules don't say that. We will update them. Almost everywhere in the code, including in the file we wrote 0.5, but yes it seems someone violated the unwritten convention there. The rationale is that you want it to be as obvious as possible that this is a number.

@pelesh pelesh merged commit 03d11bd into develop Mar 18, 2026
@shakedregev shakedregev deleted the alex/add-elementwise-vector-ops branch March 18, 2026 21:12
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.

3 participants