1#ifndef STAN_MATH_OPENCL_PRIM_GP_EXPONENTIAL_COV_HPP
2#define STAN_MATH_OPENCL_PRIM_GP_EXPONENTIAL_COV_HPP
10#include <CL/opencl.hpp>
26template <
typename T1,
typename T2,
typename T3,
27 require_all_kernel_expressions_and_none_scalar_t<T1>* =
nullptr,
28 require_all_arithmetic_t<T2, T3>* =
nullptr>
30 const T1& x,
const T2 sigma,
const T3 length_scale) {
31 const auto& x_eval = x.eval();
34 int n_blocks = (x.cols() + block_size - 1) / block_size;
35 int blocked_size = block_size * n_blocks;
38 cl::NDRange(block_size, block_size),
39 x_eval, res, sigma * sigma,
40 -1.0 / length_scale, x.
cols(), x.rows());
41 }
catch (
const cl::Error&
e) {
64template <
typename T1,
typename T2,
typename T3,
typename T4,
68 const T1& x,
const T2& y,
const T3 sigma,
const T4 length_scale) {
71 const auto& x_eval = x.eval();
72 const auto& y_eval = y.eval();
74 int x_blocks = (x.cols() + block_size - 1) / block_size;
75 int x_blocked_size = block_size * x_blocks;
76 int y_blocks = (y.cols() + block_size - 1) / block_size;
77 int y_blocked_size = block_size * y_blocks;
80 cl::NDRange(x_blocked_size, y_blocked_size),
81 cl::NDRange(block_size, block_size), x_eval, y_eval, res, sigma * sigma,
82 -1.0 / length_scale, x.
cols(), y.cols(), x.rows());
83 }
catch (
const cl::Error&
e) {
101template <
typename T1,
typename T2,
typename T3,
105 const T1& x,
const T2 sigma,
const T3 length_scale) {
107 matrix_cl<return_type_t<T1, T2, T3>> res(x.cols(), x.cols());
109 int n_blocks = (x.cols() + block_size - 1) / block_size;
110 int blocked_size = block_size * n_blocks;
113 cl::NDRange(block_size, block_size),
114 x_eval, res, sigma * sigma, -1.0,
116 }
catch (
const cl::Error&
e) {
140 typename T1,
typename T2,
typename T3,
typename T4,
141 require_all_kernel_expressions_and_none_scalar_t<T1, T2, T4>* =
nullptr,
142 require_all_arithmetic_t<T3>* =
nullptr>
144 const T1& x,
const T2& y,
const T3 sigma,
const T4 length_scale) {
146 matrix_cl<return_type_t<T1, T2, T3, T4>> res(x.cols(), y.cols());
150 int x_blocks = (x.cols() + block_size - 1) / block_size;
151 int x_blocked_size = block_size * x_blocks;
152 int y_blocks = (y.cols() + block_size - 1) / block_size;
153 int y_blocked_size = block_size * y_blocks;
156 cl::NDRange(x_blocked_size, y_blocked_size),
157 cl::NDRange(block_size, block_size), x_eval, y_eval, res, sigma * sigma,
158 -1.0, x.cols(), y.cols(), x.rows());
159 }
catch (
const cl::Error&
e) {
Represents an arithmetic matrix on the OpenCL device.
require_all_t< std::is_arithmetic< std::decay_t< Types > >... > require_all_arithmetic_t
Require all of the types satisfy std::is_arithmetic.
void check_opencl_error(const char *function, const cl::Error &e)
Throws the domain error with specifying the OpenCL error that occurred.
elt_divide_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_divide(T_a &&a, T_b &&b)
auto rowwise_broadcast(T &&a)
Broadcast an expression in rowwise dimmension.
require_all_t< is_kernel_expression_and_not_scalar< Types >... > require_all_kernel_expressions_and_none_scalar_t
Enables a template if all given types are non-scalar types that are a valid kernel generator expressi...
const kernel_cl< in_buffer, in_buffer, out_buffer, double, double, int, int, int > gp_exponential_cov_cross("gp_exponential_cov_cross", {gp_exponential_cov_cross_kernel_code})
See the docs for gp_exponential_cov_cross() .
const kernel_cl< in_buffer, out_buffer, double, double, int, int > gp_exponential_cov("gp_exponential_cov", {gp_exponential_cov_kernel_code})
See the docs for gp_exponential_cov() .
matrix_cl< return_type_t< T1, T2, T3 > > gp_exponential_cov(const T1 &x, const T2 sigma, const T3 length_scale)
Matern exponential kernel on the GPU.
static constexpr double e()
Return the base of the natural logarithm.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...