Automatic Differentiation
 
Loading...
Searching...
No Matches
to_matrix.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_TO_MATRIX_HPP
2#define STAN_MATH_OPENCL_REV_TO_MATRIX_HPP
3#ifdef STAN_OPENCL
4
8
9namespace stan {
10namespace math {
11
25template <typename T_x,
26 require_all_kernel_expressions_and_none_scalar_t<T_x>* = nullptr>
28 int n) {
29 return make_callback_var(
30 to_matrix(value_of(x), m, n),
31 [x, m, n](vari_value<matrix_cl<double>>& res) mutable {
32 matrix_cl<double> x_adj_cpy = std::move(x.adj());
33 matrix_cl<double> reshaped(x_adj_cpy.buffer(), m, n);
34 for (cl::Event e : x_adj_cpy.read_events()) {
35 reshaped.add_read_event(e);
36 }
37 for (cl::Event e : x_adj_cpy.write_events()) {
38 reshaped.add_write_event(e);
39 }
40 reshaped += res.adj();
41 for (cl::Event e : reshaped.write_events()) {
42 x_adj_cpy.add_write_event(e);
43 }
44 x.adj() = std::move(x_adj_cpy);
45 });
46}
47
48} // namespace math
49} // namespace stan
50#endif
51#endif
const cl::Buffer & buffer() const
void add_read_event(cl::Event new_event) const
Add an event to the read event stack.
const tbb::concurrent_vector< cl::Event > & read_events() const
Get the events from the event stacks.
void add_write_event(cl::Event new_event) const
Add an event to the write event stack.
const tbb::concurrent_vector< cl::Event > & write_events() const
Get the events from the event stacks.
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
T_x to_matrix(T_x &&x)
Returns input matrix.
Definition to_matrix.hpp:21
static constexpr double e()
Return the base of the natural logarithm.
Definition constants.hpp:20
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...