Automatic Differentiation
 
Loading...
Searching...
No Matches
holder_cl.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNEL_GENERATOR_holder_cl__HPP
2#define STAN_MATH_OPENCL_KERNEL_GENERATOR_holder_cl__HPP
3#ifdef STAN_OPENCL
4
11#include <memory>
12#include <string>
13#include <type_traits>
14#include <set>
15#include <tuple>
16#include <utility>
17
18namespace stan {
19namespace math {
20
32template <typename T, typename... Ptrs>
34 : public operation_cl<holder_cl_<T, Ptrs...>,
35 typename std::remove_reference_t<T>::Scalar, T> {
36 public:
37 using Scalar = typename std::remove_reference_t<T>::Scalar;
38 using base = operation_cl<holder_cl_<T, Ptrs...>, Scalar, T>;
39 using base::var_name_;
40
41 protected:
42 std::tuple<std::unique_ptr<Ptrs>...> m_unique_ptrs;
43
44 public:
50 holder_cl_(T&& a, Ptrs*... ptrs)
51 : base(std::forward<T>(a)),
52 m_unique_ptrs(std::unique_ptr<Ptrs>(ptrs)...) {}
53};
54
65template <typename T, typename... Ptrs,
66 require_all_kernel_expressions_t<T, Ptrs...>* = nullptr>
67auto holder_cl(T&& a, Ptrs*... ptrs) {
68 return holder_cl_<as_operation_cl_t<T>, Ptrs...>(
69 as_operation_cl(std::forward<T>(a)), ptrs...);
70}
71
72namespace internal {
83template <typename T, std::size_t... Is, typename... Args>
84auto make_holder_cl_impl_step2(T&& expr, std::index_sequence<Is...>,
85 const std::tuple<Args*...>& ptrs) {
86 return holder_cl(std::forward<T>(expr), std::get<Is>(ptrs)...);
87}
88
98template <typename T, std::size_t... Is, typename... Args>
99auto make_holder_cl_impl_step1(const T& func, std::index_sequence<Is...>,
100 Args&&... args) {
101 std::tuple<std::remove_reference_t<Args>*...> res;
102 auto ptrs = std::tuple_cat(
103 holder_handle_element(std::forward<Args>(args), std::get<Is>(res))...);
105 func(*std::get<Is>(res)...),
106 std::make_index_sequence<std::tuple_size<decltype(ptrs)>::value>(), ptrs);
107}
108
109} // namespace internal
110
121template <typename T, typename... Args,
123 decltype(std::declval<T>()(std::declval<Args&>()...)),
124 Args...>* = nullptr>
125auto make_holder_cl(const T& func, Args&&... args) {
127 func, std::make_index_sequence<sizeof...(Args)>(),
128 std::forward<Args>(args)...);
129}
130
132} // namespace math
133} // namespace stan
134
135#endif
136#endif
typename std::remove_reference_t< T >::Scalar Scalar
Definition holder_cl.hpp:37
std::tuple< std::unique_ptr< Ptrs >... > m_unique_ptrs
Definition holder_cl.hpp:42
holder_cl_(T &&a, Ptrs *... ptrs)
Constructor.
Definition holder_cl.hpp:50
Represents a no-op in kernel generator expressions.
Definition holder_cl.hpp:35
Base for all kernel generator operations.
auto make_holder_cl(const T &func, Args &&... args)
Constructs an expression from given arguments using given functor.
auto holder_cl(T &&a, Ptrs *... ptrs)
Constructs a no-op operation that also holds pointer to some other expressions, allocated on heap.
Definition holder_cl.hpp:67
require_all_t< is_kernel_expression< Types >... > require_all_kernel_expressions_t
Enables a template if all given types are are a valid kernel generator expressions.
T_operation && as_operation_cl(T_operation &&a)
Converts any valid kernel generator expression into an operation.
auto make_holder_cl_impl_step1(const T &func, std::index_sequence< Is... >, Args &&... args)
First step in implementation of construction holder_cl from a functor.
Definition holder_cl.hpp:99
auto make_holder_cl_impl_step2(T &&expr, std::index_sequence< Is... >, const std::tuple< Args *... > &ptrs)
Second step in implementation of construction holder_cl from a functor.
Definition holder_cl.hpp:84
auto holder_handle_element(T &a, T *&res)
Handles single element (moving rvalue non-expressions to heap) for construction of holder or holder_c...
Definition holder.hpp:261
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
STL namespace.