|
27 | 27 | #include <thrust/detail/functional/composite.h> |
28 | 28 | #include <thrust/detail/functional/operators/assignment_operator.h> |
29 | 29 | #include <thrust/functional.h> |
| 30 | +#include <thrust/type_traits/logical_metafunctions.h> |
| 31 | + |
| 32 | +#include <type_traits> |
30 | 33 |
|
31 | 34 | namespace thrust |
32 | 35 | { |
@@ -62,135 +65,38 @@ template<typename Eval> |
62 | 65 | return eval_type::eval(thrust::null_type()); |
63 | 66 | } // end basic_environment::operator() |
64 | 67 |
|
65 | | -template<typename Eval> |
66 | | - template<typename T0> |
67 | | - __host__ __device__ |
68 | | - typename apply_actor< |
69 | | - typename actor<Eval>::eval_type, |
70 | | - typename thrust::tuple<T0&> |
71 | | - >::type |
72 | | - actor<Eval> |
73 | | - ::operator()(T0 &_0) const |
74 | | -{ |
75 | | - return eval_type::eval(thrust::tie(_0)); |
76 | | -} // end basic_environment::operator() |
| 68 | +// actor::operator() needs to construct a tuple of references to its |
| 69 | +// arguments. To make this work with thrust::reference<T>, we need to |
| 70 | +// detect thrust proxy references and store them as T rather than T&. |
| 71 | +// This check ensures that the forwarding references passed into |
| 72 | +// actor::operator() are either: |
| 73 | +// - T&& if and only if T is a thrust::reference<U>, or |
| 74 | +// - T& for any other types. |
| 75 | +// This struct provides a nicer diagnostic for when these conditions aren't |
| 76 | +// met. |
| 77 | +template <typename T> |
| 78 | +using actor_check_ref_type = |
| 79 | + thrust::detail::integral_constant<bool, |
| 80 | + ( std::is_lvalue_reference<T>::value || |
| 81 | + thrust::detail::is_wrapped_reference<T>::value )>; |
| 82 | + |
| 83 | +template <typename... Ts> |
| 84 | +using actor_check_ref_types = |
| 85 | + thrust::conjunction<actor_check_ref_type<Ts>...>; |
77 | 86 |
|
78 | 87 | template<typename Eval> |
79 | | - template<typename T0, typename T1> |
80 | | - __host__ __device__ |
81 | | - typename apply_actor< |
82 | | - typename actor<Eval>::eval_type, |
83 | | - typename thrust::tuple<T0&,T1&> |
84 | | - >::type |
85 | | - actor<Eval> |
86 | | - ::operator()(T0 &_0, T1 &_1) const |
| 88 | +template<typename... Ts> |
| 89 | +__host__ __device__ |
| 90 | +typename apply_actor<typename actor<Eval>::eval_type, |
| 91 | + thrust::tuple<eval_ref<Ts>...>>::type |
| 92 | +actor<Eval>::operator()(Ts&&... ts) const |
87 | 93 | { |
88 | | - return eval_type::eval(thrust::tie(_0,_1)); |
89 | | -} // end basic_environment::operator() |
90 | | - |
91 | | -template<typename Eval> |
92 | | - template<typename T0, typename T1, typename T2> |
93 | | - __host__ __device__ |
94 | | - typename apply_actor< |
95 | | - typename actor<Eval>::eval_type, |
96 | | - typename thrust::tuple<T0&,T1&,T2&> |
97 | | - >::type |
98 | | - actor<Eval> |
99 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2) const |
100 | | -{ |
101 | | - return eval_type::eval(thrust::tie(_0,_1,_2)); |
102 | | -} // end basic_environment::operator() |
103 | | - |
104 | | -template<typename Eval> |
105 | | - template<typename T0, typename T1, typename T2, typename T3> |
106 | | - __host__ __device__ |
107 | | - typename apply_actor< |
108 | | - typename actor<Eval>::eval_type, |
109 | | - typename thrust::tuple<T0&,T1&,T2&,T3&> |
110 | | - >::type |
111 | | - actor<Eval> |
112 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3) const |
113 | | -{ |
114 | | - return eval_type::eval(thrust::tie(_0,_1,_2,_3)); |
115 | | -} // end basic_environment::operator() |
116 | | - |
117 | | -template<typename Eval> |
118 | | - template<typename T0, typename T1, typename T2, typename T3, typename T4> |
119 | | - __host__ __device__ |
120 | | - typename apply_actor< |
121 | | - typename actor<Eval>::eval_type, |
122 | | - typename thrust::tuple<T0&,T1&,T2&,T3&,T4&> |
123 | | - >::type |
124 | | - actor<Eval> |
125 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4) const |
126 | | -{ |
127 | | - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4)); |
128 | | -} // end basic_environment::operator() |
129 | | - |
130 | | -template<typename Eval> |
131 | | - template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> |
132 | | - __host__ __device__ |
133 | | - typename apply_actor< |
134 | | - typename actor<Eval>::eval_type, |
135 | | - typename thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&> |
136 | | - >::type |
137 | | - actor<Eval> |
138 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5) const |
139 | | -{ |
140 | | - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5)); |
141 | | -} // end basic_environment::operator() |
142 | | - |
143 | | -template<typename Eval> |
144 | | - template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> |
145 | | - __host__ __device__ |
146 | | - typename apply_actor< |
147 | | - typename actor<Eval>::eval_type, |
148 | | - typename thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&> |
149 | | - >::type |
150 | | - actor<Eval> |
151 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6) const |
152 | | -{ |
153 | | - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6)); |
154 | | -} // end basic_environment::operator() |
155 | | - |
156 | | -template<typename Eval> |
157 | | - template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> |
158 | | - __host__ __device__ |
159 | | - typename apply_actor< |
160 | | - typename actor<Eval>::eval_type, |
161 | | - typename thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&> |
162 | | - >::type |
163 | | - actor<Eval> |
164 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7) const |
165 | | -{ |
166 | | - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6,_7)); |
167 | | -} // end basic_environment::operator() |
168 | | - |
169 | | -template<typename Eval> |
170 | | - template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> |
171 | | - __host__ __device__ |
172 | | - typename apply_actor< |
173 | | - typename actor<Eval>::eval_type, |
174 | | - typename thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&,T8&> |
175 | | - >::type |
176 | | - actor<Eval> |
177 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8) const |
178 | | -{ |
179 | | - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6,_7,_8)); |
180 | | -} // end basic_environment::operator() |
181 | | - |
182 | | -template<typename Eval> |
183 | | - template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> |
184 | | - __host__ __device__ |
185 | | - typename apply_actor< |
186 | | - typename actor<Eval>::eval_type, |
187 | | - typename thrust::tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&,T8&,T9&> |
188 | | - >::type |
189 | | - actor<Eval> |
190 | | - ::operator()(T0 &_0, T1 &_1, T2 &_2, T3 &_3, T4 &_4, T5 &_5, T6 &_6, T7 &_7, T8 &_8, T9 &_9) const |
191 | | -{ |
192 | | - return eval_type::eval(thrust::tie(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9)); |
193 | | -} // end basic_environment::operator() |
| 94 | + static_assert(actor_check_ref_types<Ts...>::value, |
| 95 | + "Actor evaluations only support rvalue references to " |
| 96 | + "thrust::reference subclasses."); |
| 97 | + using tuple_type = thrust::tuple<eval_ref<Ts>...>; |
| 98 | + return eval_type::eval(tuple_type(THRUST_FWD(ts)...)); |
| 99 | +} // end actor<Eval>::operator() |
194 | 100 |
|
195 | 101 | template<typename Eval> |
196 | 102 | template<typename T> |
|
0 commit comments