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

Add to_matrix_cl() vector<var> and minor OpenCL fixes #2226

Merged
merged 9 commits into from
Dec 4, 2020
4 changes: 2 additions & 2 deletions stan/math/opencl/opencl.hpp → stan/math/opencl/prim.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef STAN_MATH_OPENCL_OPENCL
#define STAN_MATH_OPENCL_OPENCL
#ifndef STAN_MATH_OPENCL_PRIM_HPP
#define STAN_MATH_OPENCL_PRIM_HPP
#ifdef STAN_OPENCL

/**
Expand Down
4 changes: 2 additions & 2 deletions stan/math/opencl/prim/rows.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef STAN_MATH_OPENCL_PRIM_COLS_HPP
#define STAN_MATH_OPENCL_PRIM_COLS_HPP
#ifndef STAN_MATH_OPENCL_PRIM_ROWS_HPP
#define STAN_MATH_OPENCL_PRIM_ROWS_HPP
#ifdef STAN_OPENCL

#include <stan/math/opencl/matrix_cl.hpp>
Expand Down
6 changes: 3 additions & 3 deletions stan/math/opencl/rev/opencl.hpp → stan/math/opencl/rev.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef STAN_MATH_OPENCL_OPENCL_REV
#define STAN_MATH_OPENCL_OPENCL_REV
#ifndef STAN_MATH_OPENCL_REV_HPP
#define STAN_MATH_OPENCL_REV_HPP
#ifdef STAN_OPENCL

#include <stan/math/opencl/rev/size.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/opencl/rev/arena_matrix_cl.hpp>
#include <stan/math/opencl/rev/arena_type.hpp>
#include <stan/math/opencl/rev/cholesky_decompose.hpp>
Expand Down
17 changes: 16 additions & 1 deletion stan/math/opencl/rev/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ inline var_value<matrix_cl<value_type_t<T>>> to_matrix_cl(
a.vi_->adj_);
}

/** \ingroup opencl
* Copies the source std::vector of vars to a destination var that has
* data stored on the OpenCL device.
*
* @tparam T type of the std::vector
* @param a source Eigen matrix
* @return var with a copy of the data on the OpenCL device
*/
template <typename T, require_stan_scalar_t<T>* = nullptr>
inline var_value<matrix_cl<value_type_t<T>>> to_matrix_cl(
std::vector<var_value<T>>& a) {
return to_matrix_cl(Eigen::Map<Eigen::Matrix<var_value<T>, Eigen::Dynamic, 1>>(a.data(),
a.size()));
}

namespace internal {
template <typename T, int Rows, int Cols,
require_all_kernel_expressions_t<T>* = nullptr>
Expand All @@ -63,7 +78,7 @@ class op_copy_from_cl_vari final
public:
explicit op_copy_from_cl_vari(vari_value<T>& a)
: vari_value<Eigen::Matrix<value_type_t<T>, Rows, Cols>>(
from_matrix_cl<Rows, Cols>(a.val_)),
from_matrix_cl<Rows, Cols>(a.val_)),
a_(a) {}

virtual void chain() { a_.adj_ = a_.adj_ + to_matrix_cl(this->adj_); }
Expand Down
4 changes: 4 additions & 0 deletions stan/math/prim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
#include <stan/math/prim/functor.hpp>
#include <stan/math/prim/prob.hpp>

#ifdef STAN_OPENCL
#include <stan/math/opencl/prim.hpp>
#endif

#endif
2 changes: 1 addition & 1 deletion stan/math/prim/fun/cholesky_decompose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stan/math/prim/err.hpp>
#include <stan/math/prim/fun/Eigen.hpp>
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#endif

#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/gp_exp_quad_cov.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stan/math/prim/fun/exp.hpp>
#include <stan/math/prim/fun/square.hpp>
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#endif

#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/mdivide_left_tri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/fun/to_ref.hpp>
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#endif

namespace stan {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/mdivide_right_tri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/fun/to_ref.hpp>
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#endif

namespace stan {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/multiply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/fun/dot_product.hpp>
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#endif
#include <type_traits>

Expand Down
2 changes: 2 additions & 0 deletions stan/math/rev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stan/math/prim/fun/Eigen.hpp>

#include <stan/math/opencl/rev.hpp>

#include <stan/math/rev/core.hpp>
#include <stan/math/rev/meta.hpp>

Expand Down
2 changes: 1 addition & 1 deletion stan/math/rev/fun/cholesky_decompose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stan/math/prim/err/check_symmetric.hpp>

#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#endif

#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion stan/math/rev/fun/mdivide_left_tri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/fun/typedefs.hpp>
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#endif

namespace stan {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/assign_event_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL

#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/opencl/kernel_cl.hpp>
#include <gtest/gtest.h>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/async_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifdef STAN_OPENCL

#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/check_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <gtest/gtest.h>
#include <limits>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/check_vector_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <gtest/gtest.h>
#include <limits>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/cholesky_decompose_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/is_matrix_cl_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <gtest/gtest.h>
#include <type_traits>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/kernel_cl_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifdef STAN_OPENCL

#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/opencl_context_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/add_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/cholesky_decompose_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/crossprod_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/prim/fun/crossprod.hpp>
#include <gtest/gtest.h>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/divide_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/inv_logit_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/prim/fun/inv_logit.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/typedefs.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/inv_square_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/prim/fun/inv_square.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/typedefs.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/log1m_inv_logit_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/prim/fun/log1m_inv_logit.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/typedefs.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/logit_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/prim/fun/logit.hpp>
#include <stan/math/prim/fun/constants.hpp>
#include <stan/math/prim/fun/typedefs.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/mdivide_left_tri_low_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/math/expect_near_rel.hpp>
#include <test/unit/util.hpp>
#include <boost/random/mersenne_twister.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/mdivide_right_tri_low_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/math/expect_near_rel.hpp>
#include <test/unit/util.hpp>
#include <boost/random/mersenne_twister.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/multiply_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/sign_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <test/unit/util.hpp>

TEST(MathMatrixCL, sign_test) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/subtract_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <gtest/gtest.h>
#include <algorithm>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/tcrossprod_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/prim/fun/tcrossprod.hpp>
#include <gtest/gtest.h>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/prim/transpose_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math/prim.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <gtest/gtest.h>
#include <algorithm>

Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/require_generics_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL

#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <stan/math/prim/meta.hpp>
#include <gtest/gtest.h>
#include <type_traits>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math.hpp>
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/rev/bernoulli_logit_lpmf_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <stan/math.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/rev/bernoulli_lpmf_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <stan/math.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/rev/beta_lpdf_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <stan/math.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/rev/beta_proportion_lpdf_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <stan/math.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef STAN_OPENCL
#include <stan/math.hpp>
#include <stan/math/opencl/opencl.hpp>
#include <stan/math/opencl/prim.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/rev/cauchy_lpdf_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <stan/math.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/rev/chi_square_lpdf_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <stan/math.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/math/opencl/rev/cholesky_decompose_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev/opencl.hpp>
#include <stan/math/opencl/rev.hpp>
#include <stan/math.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/opencl/util.hpp>
Expand Down
Loading