Automatic Differentiation
 
Loading...
Searching...
No Matches
gp_exp_quad_cov.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_GP_EXP_QUAD_COV_HPP
2#define STAN_MATH_OPENCL_KERNELS_GP_EXP_QUAD_COV_HPP
3#ifdef STAN_OPENCL
4
6#include <string>
7
8namespace stan {
9namespace math {
10namespace opencl_kernels {
11// \cond
12static constexpr const char* gp_exp_quad_cov_kernel_code = STRINGIFY(
13 // \endcond
24 __kernel void gp_exp_quad_cov(const __global double* x,
25 __global double* res, const double sigma_sq,
26 const double neg_half_inv_l_sq,
27 const int size, const int element_size) {
28 const int i = get_global_id(0);
29 const int j = get_global_id(1);
30 if (i < size && j < (size - 1) && i > j) {
31 double sum = 0;
32 for (int k = 0; k < element_size; k++) {
33 double d = x[i * element_size + k] - x[j * element_size + k];
34 sum += d * d;
35 }
36 double a = sigma_sq * exp(neg_half_inv_l_sq * sum);
37 res[j * size + i] = a;
38 res[i * size + j] = a;
39 } else if (i == j) {
40 res[j * size + i] = sigma_sq;
41 }
42 }
43 // \cond
44);
45// \endcond
46
50const kernel_cl<in_buffer, out_buffer, double, double, int, int>
51 gp_exp_quad_cov("gp_exp_quad_cov", {gp_exp_quad_cov_kernel_code});
52
53// \cond
54static constexpr const char* gp_exp_quad_cov_cross_kernel_code = STRINGIFY(
55 // \endcond
72 __kernel void gp_exp_quad_cov_cross(
73 const __global double* x1, const __global double* x2,
74 __global double* res, const double sigma_sq,
75 const double neg_half_inv_l_sq, const int size1, const int size2,
76 const int element_size) {
77 const int i = get_global_id(0);
78 const int j = get_global_id(1);
79 if (i < size1 && j < size2) {
80 double sum = 0;
81 for (int k = 0; k < element_size; k++) {
82 double d = x1[i * element_size + k] - x2[j * element_size + k];
83 sum += d * d;
84 }
85 res[j * size1 + i] = sigma_sq * exp(neg_half_inv_l_sq * sum);
86 }
87 }
88 // \cond
89);
90// \endcond
91
96const kernel_cl<in_buffer, in_buffer, out_buffer, double, double, int, int, int>
97 gp_exp_quad_cov_cross("gp_exp_quad_cov_cross",
98 {gp_exp_quad_cov_cross_kernel_code});
99
100} // namespace opencl_kernels
101} // namespace math
102} // namespace stan
103#endif
104#endif
const kernel_cl< in_buffer, in_buffer, out_buffer, double, double, int, int, int > gp_exp_quad_cov_cross("gp_exp_quad_cov_cross", {gp_exp_quad_cov_cross_kernel_code})
See the docs for gp_exp_quad_cov_cross() .
const kernel_cl< in_buffer, out_buffer, double, double, int, int > gp_exp_quad_cov("gp_exp_quad_cov", {gp_exp_quad_cov_kernel_code})
See the docs for gp_exp_quad_cov() .
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:19
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:15
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
#define STRINGIFY(...)
Definition stringify.hpp:9