Stan Math Library  2.20.0
reverse mode automatic differentiation
cholesky_decompose.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_OPENCL_KERNELS_CHOLESKY_DECOMPOSE_HPP
2 #define STAN_MATH_OPENCL_KERNELS_CHOLESKY_DECOMPOSE_HPP
3 #ifdef STAN_OPENCL
4 
7 
8 namespace stan {
9 namespace math {
10 namespace opencl_kernels {
11 // \cond
12 static const char *cholesky_decompose_kernel_code = STRINGIFY(
13  // \endcond
32  __kernel void cholesky_decompose(__global double *A, int rows) {
33  const int local_index = get_local_id(0);
34  // The following code is the sequential version of the inplace
35  // cholesky decomposition. Only the innermost loops are parallelized. The
36  // rows are processed sequentially. This loop process all the rows:
37  for (int j = 0; j < rows; j++) {
38  if (local_index == 0) {
39  double sum = 0.0;
40  for (int k = 0; k < j; k++) {
41  sum = sum + A(j, k) * A(j, k);
42  }
43  A(j, j) = sqrt(A(j, j) - sum);
44  }
45  barrier(CLK_LOCAL_MEM_FENCE);
46  if (local_index < j) {
47  A(local_index, j) = 0.0;
48  } else if (local_index > j) {
49  double sum = 0.0;
50  for (int k = 0; k < j; k++)
51  sum = sum + A(local_index, k) * A(j, k);
52  A(local_index, j) = (A(local_index, j) - sum) / A(j, j);
53  }
54  barrier(CLK_LOCAL_MEM_FENCE);
55  }
56  }
57  // \cond
58 );
59 // \endcond
60 
66  "cholesky_decompose", {indexing_helpers, cholesky_decompose_kernel_code});
67 
68 } // namespace opencl_kernels
69 } // namespace math
70 } // namespace stan
71 #endif
72 #endif
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition: sum.hpp:20
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
Definition: rows.hpp:20
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:13
#define STRINGIFY(src)
Definition: kernel_cl.hpp:22
static const char * indexing_helpers
Definition: helpers.hpp:14
const kernel_cl< in_out_buffer, int > cholesky_decompose("cholesky_decompose", {indexing_helpers, cholesky_decompose_kernel_code})
See the docs for cholesky_decompose() .
Creates functor for kernels.
Definition: kernel_cl.hpp:201

     [ Stan Home Page ] © 2011–2018, Stan Development Team.