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

[FR] reduce_sum does not block SoA #1236

Open
wds15 opened this issue Aug 8, 2022 · 3 comments
Open

[FR] reduce_sum does not block SoA #1236

wds15 opened this issue Aug 8, 2022 · 3 comments
Labels
feature New feature or request optimization

Comments

@wds15
Copy link

wds15 commented Aug 8, 2022

Current Behavior:

Stan models using reduce_sum cannot benefit from the SoA optimisation whenever reduce_sum is used with a data only slicing argument.

Expected Behavior:

If the argument to be sliced for reduce_sum is data only, then SoA should work just fine, given that the shared arguments are simply copied as a whole. Moreover, whenever the slicing argument is an array of parameters, then SoA should also work given that an array ( std::vector) is being chopped into pieces.

Model Code

Model which exhibits the issue
  // likelihood including constants
  if (!prior_only) {
    // reduce_sum is blocking SoA, but it should not since the slice
    // argument is data in this case
    //target += reduce_sum(partial_log_lik_lpmf, seq, grainsize, Y, Xc, b, Intercept, sigma, J_1, Z_1_1, r_1_1);
    // this call instead gives me a full SoA program
    target += partial_log_lik_lpmf(seq| 1, N, Y, Xc, b, Intercept, sigma, J_1, Z_1_1, r_1_1);
  }

Environment:

Stan 2.30.0

Anything else:

Here is the full Stan model, which is a minor modification of a brms generated one. So the goal is to get brms to create reduce_sum programs which can benefit from SoA in addition to within-chain parallelisation.

soa-example-brms-soa_stan.txt

@SteveBronder
Copy link
Contributor

I discussed this in the link below. TL;DR anytime a matrix/vector goes into a UDF we need to run an analysis to see what signatures are valid with SoA/AoS variables. This is very doable but will require a bit of work. I made #1237 to describe what I think needs to happen in the compiler

https://discourse.mc-stan.org/t/30-40-drop-in-sampling-time-using-stanc-o1-optimizations/28347/18?u=stevebronder

@SteveBronder SteveBronder changed the title [BUG] reduce_sum blocks SoA [FR] reduce_sum does not block SoA Aug 8, 2022
@SteveBronder
Copy link
Contributor

SteveBronder commented Aug 8, 2022

@wds15 fyi I update the description of the issue to reflect the problem. I think this is more of a feature request and not a bug as not supporting reduce sum atm is intended behavior

@wds15
Copy link
Author

wds15 commented Aug 8, 2022

Yeah…looked as a bug to me from a user perspective…but it’s a new feature given where we stand.

@WardBrian WardBrian added the feature New feature or request label Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request optimization
Projects
None yet
Development

No branches or pull requests

3 participants