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

adds full impl for std allocator conformance #2227

Closed
wants to merge 3 commits into from

Conversation

SteveBronder
Copy link
Collaborator

Summary

Adds full conformance for arena_allocator. For multi indexing on var<matrix> types I need std::unordered_set which requires some additional member functions that std::vector<> does not.

Tests

Tests we added to make sure std::unordered_set compiles and handles mem correctly.

Side Effects

We should be able to use arena_allocator<> with the other allocator aware classes in the standard library.

Release notes

Makes arena_allocator standard compliant

Checklist

  • Math issue #(issue number)

  • Copyright holder: Steve Bronder

    The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
    - Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
    - Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

  • the basic tests are passing

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

@SteveBronder
Copy link
Collaborator Author

Oh actually we don't need this anymore. It's pretty simple to add though so I'll leave it open if you have time to review it @t4c1

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.49 3.49 1.0 -0.01% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.97 -2.85% slower
eight_schools/eight_schools.stan 0.12 0.11 1.03 2.6% faster
gp_regr/gp_regr.stan 0.17 0.16 1.01 1.1% faster
irt_2pl/irt_2pl.stan 5.78 5.86 0.99 -1.46% slower
performance.compilation 87.24 85.73 1.02 1.72% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.43 8.46 1.0 -0.37% slower
pkpd/one_comp_mm_elim_abs.stan 29.75 29.01 1.03 2.5% faster
sir/sir.stan 127.57 131.66 0.97 -3.2% slower
gp_regr/gen_gp_data.stan 0.04 0.04 0.98 -1.58% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 2.92 3.08 0.95 -5.63% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.37 0.38 0.97 -2.89% slower
arK/arK.stan 1.82 1.8 1.01 0.83% faster
arma/arma.stan 0.73 0.74 0.99 -0.73% slower
garch/garch.stan 0.61 0.61 1.0 -0.04% slower
Mean result: 0.993858148168

Jenkins Console Log
Blue Ocean
Commit hash: 063670a


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix


/**
* Allocates space for `n` items of type `T`.
*
* @param n number of items to allocate space for
* @return pointer to allocated space
*/
T* allocate(std::size_t n) {
static inline T* allocate(std::size_t n) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why noexcept? Allocations can throw!

Comment on lines +24 to +32
constexpr arena_allocator() noexcept {};

template <class U>
constexpr arena_allocator(const arena_allocator<U>&) noexcept {}

template <class U>
constexpr arena_allocator<T>& operator=(const arena_allocator<U>&) noexcept {
return *this;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to explicitely define these, as the implementations are the same as defaults.

new (static_cast<void*>(p)) T(val);
}

static inline void destroy(pointer p) { (static_cast<T*>(p))->~T(); }
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for cast. p is of type T*. I would prefere if you used T* / T& everywhere instead of typedefs, so such mistakes would not happen.

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.4 3.37 1.01 1.01% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 0.99 -0.85% slower
eight_schools/eight_schools.stan 0.11 0.11 0.96 -3.9% slower
gp_regr/gp_regr.stan 0.15 0.15 1.01 1.22% faster
irt_2pl/irt_2pl.stan 5.38 5.16 1.04 4.16% faster
performance.compilation 91.31 89.96 1.01 1.48% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.65 8.63 1.0 0.14% faster
pkpd/one_comp_mm_elim_abs.stan 29.05 28.86 1.01 0.63% faster
sir/sir.stan 139.51 132.82 1.05 4.79% faster
gp_regr/gen_gp_data.stan 0.04 0.04 1.0 0.32% faster
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.05 3.15 0.97 -3.37% slower
pkpd/sim_one_comp_mm_elim_abs.stan 0.37 0.4 0.93 -7.87% slower
arK/arK.stan 2.56 2.53 1.01 1.12% faster
arma/arma.stan 0.6 0.61 1.0 -0.21% slower
garch/garch.stan 0.67 0.67 0.99 -0.58% slower
Mean result: 0.999609431669

Jenkins Console Log
Blue Ocean
Commit hash: 063670a


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@SteveBronder SteveBronder mentioned this pull request Mar 9, 2021
5 tasks
@SteveBronder
Copy link
Collaborator Author

Closing this because idt we need it

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

Successfully merging this pull request may close these issues.

4 participants