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

[C++][Compute] "Scatter" vector functions #44393

Closed
zanmato1984 opened this issue Oct 13, 2024 · 1 comment
Closed

[C++][Compute] "Scatter" vector functions #44393

zanmato1984 opened this issue Oct 13, 2024 · 1 comment

Comments

@zanmato1984
Copy link
Contributor

Describe the enhancement requested

We discussed the solution for #41094 , the conclusion is that the "special form" is the way. Comment #41094 (comment) gives a thorough description of how special forms work.

Here I summarize a bit: a special form "mask-ably" evaluates some of its subexpressions based on some masks obtained from its other subexpressions. For example consider if cond then expr1 else expr2, the result of cond is the mask, which controls which rows goes to expr1 and which goes to expr2. Another example is logical and/or, each of its subexpressions is part of the mask to evaluate the rest subexpressions (boolean short-circuit).

One way to implement special forms is that every expression selectively executes its kernel by respecting a selection vector (which rows this kernel should execute on) or a equally boolean mask. But unfortunately this isn't practical because we can't afford to change every (scalar) compute functions to support selection vector/mask all at once. So we must take an adaptive way, allowing functions to be selection vector/mask agnostic. To do so, a special form should 1) takes rows specific to each branch; 2) invoke the function of each branch on each group of these rows; 3) combine the results of all the branches by scattering each row to its original position in the input.

So far we have vector function filter/take to do 1), but there isn't a handy utility to do 3).

Component(s)

C++

pitrou added a commit that referenced this issue Jan 15, 2025
…ion` and `scatter` (#44394)

### Rationale for this change

For background please see #44393.

When implementing the "scatter" function requested in #44393, I found it also useful to make it a public vector API. After a painful thinking, I decided to name it "permute". And when implementing permute, I found it fairly easy to implement it by first computing the "reverse indices" of the positions, and then invoking the existing "take", where I think "reverse_indices"  itself can also be a useful public vector API. Thus the PR categorized them as "placement functions".

### What changes are included in this PR?

Implement vector selection API `inverse_permutation` and `scatter`, where `scatter(values, indices)` is implemented as `take(values, inverse_permutation(indices))`.

### Are these changes tested?

UT included.

### Are there any user-facing changes?

Yes, new public APIs added. Documents updated.

* GitHub Issue: #44393

Lead-authored-by: Ruoxi Sun <[email protected]>
Co-authored-by: Rossi Sun <[email protected]>
Co-authored-by: Antoine Pitrou <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
@pitrou pitrou added this to the 20.0.0 milestone Jan 15, 2025
@pitrou
Copy link
Member

pitrou commented Jan 15, 2025

Issue resolved by pull request 44394
#44394

@pitrou pitrou closed this as completed Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants