Skip to content

Recover higher performance from re-enabling bounds checking. #853

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

Closed
ryan-richt opened this issue Mar 10, 2021 · 2 comments
Closed

Recover higher performance from re-enabling bounds checking. #853

ryan-richt opened this issue Mar 10, 2021 · 2 comments

Comments

@ryan-richt
Copy link

ryan-richt commented Mar 10, 2021

Ask

We would like a way to recover the improved speed from the version of Stanc3 prior to #849 . This PR re-introduced array bounds checking for safety and user experience at a significant performance cost.

One proposed solution is to create a "debug/test vs production" Stan compiler flag or otherwise option that (1) by default is turned to the safe and informative debug mode to serve new adopters and (2) can be actively set/changed by those with higher performance needs to get the performance.

Background

Many awesome devs and community managers did great work to establish:

  • Array bounds checking and other similar checks can incur a significant performance penalty on models (order of 30%), which is a huge problem for Stan users with performance-critical models
  • Eliminating array bounds checking in Stanc3 by default causes many new-adopters to generate seg faults at run time, not know why, and post to the forums, possibly turning them off of Stan and its community.

These checks were eliminated / never implemented in Stanc3. Someone did excellent work to support and add them all into Stanc3, which was originally rejected b/c of well-thought-out-and-executed performance tests that showed a 30% performance hit. After the new user issue surfaced several times, that PR with the safety checks was revived and merged, and someone suggested we add this ticket!

@SteveBronder
Copy link
Contributor

I think what we are talking about is just having -DNDEBUG not perform range checks. Would that work for you? It's assuming the overhead here is just in checking the bounds and not the actual rvalue() function call but I think that's a reasonable assumption

@bbbales2
Copy link
Member

@ryan-richt it should be possible to use CXXFLAGS to turn off bounds check for production models with -DSTAN_NO_RANGE_CHECKS: stan-dev/math#2423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants