Automatic Differentiation
 
Loading...
Searching...
No Matches
autodiffstackstorage.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_AUTODIFFSTACKSTORAGE_HPP
2#define STAN_MATH_REV_CORE_AUTODIFFSTACKSTORAGE_HPP
3
5#include <vector>
6
7namespace stan {
8namespace math {
9
10// Internal macro used to modify global pointer definition to the
11// global AD instance.
12#ifdef STAN_THREADS
13// Whenever STAN_THREADS is set a TLS keyword is used. For reasons
14// explained below we use the GNU compiler extension __thread if
15// supported by the compiler while the generic thread_local C++11
16// keyword is used otherwise.
17#ifdef __GNUC__
18#define STAN_THREADS_DEF __thread
19#else
20#define STAN_THREADS_DEF thread_local
21#endif
22#else
23// In case STAN_THREADS is not set, then no modifier is needed.
24#define STAN_THREADS_DEF
25#endif
26
88template <typename ChainableT, typename ChainableAllocT>
92
95 if (own_instance_) {
96 delete instance_;
97 instance_ = nullptr;
98 }
99 }
100
103
104 std::vector<ChainableT *> var_stack_;
105 std::vector<ChainableT *> var_nochain_stack_;
106 std::vector<ChainableAllocT *> var_alloc_stack_;
108
109 // nested positions
110 std::vector<size_t> nested_var_stack_sizes_;
113 };
114
117
119
120 private:
121 static bool init() {
122 static STAN_THREADS_DEF bool is_initialized = false;
123 if (!is_initialized) {
124 is_initialized = true;
126 return true;
127 }
128 if (!instance_) {
129 is_initialized = true;
131 return true;
132 }
133 return false;
134 }
135
137};
138
139template <typename ChainableT, typename ChainableAllocT>
141 typename AutodiffStackSingleton<ChainableT,
142 ChainableAllocT>::AutodiffStackStorage
144
145} // namespace math
146} // namespace stan
147#endif
#define STAN_THREADS_DEF
An instance of this class provides a memory pool through which blocks of raw memory may be allocated ...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
AutodiffStackStorage & operator=(const AutodiffStackStorage &)=delete
AutodiffStackSingleton(AutodiffStackSingleton_t const &)=delete
AutodiffStackSingleton & operator=(const AutodiffStackSingleton_t &)=delete
static thread_local AutodiffStackStorage * instance_
This struct always provides access to the autodiff stack using the singleton pattern.