Automatic Differentiation
 
Loading...
Searching...
No Matches
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#include <string>
8
9namespace stan {
10namespace math {
11namespace opencl_kernels {
12// \cond
13static constexpr const char* cholesky_decompose_kernel_code = STRINGIFY(
14 // \endcond
33 __kernel void cholesky_decompose(__global double* A, int rows) {
34 const int local_index = get_local_id(0);
35 // The following code is the sequential version of the inplace
36 // cholesky decomposition. Only the innermost loops are parallelized. The
37 // rows are processed sequentially. This loop process all the rows:
38 for (int j = 0; j < rows; j++) {
39 if (local_index == 0) {
40 double sum = 0.0;
41 for (int k = 0; k < j; k++) {
42 sum = sum + A(j, k) * A(j, k);
43 }
44 A(j, j) = sqrt(A(j, j) - sum);
45 }
46 barrier(CLK_LOCAL_MEM_FENCE);
47 if (local_index < j) {
48 A(local_index, j) = 0.0;
49 } else if (local_index > j) {
50 double sum = 0.0;
51 for (int k = 0; k < j; k++)
52 sum = sum + A(local_index, k) * A(j, k);
53 A(local_index, j) = (A(local_index, j) - sum) / A(j, j);
54 }
55 barrier(CLK_LOCAL_MEM_FENCE);
56 }
57 }
58 // \cond
59);
60// \endcond
61
67 "cholesky_decompose", {indexing_helpers, cholesky_decompose_kernel_code});
68
69} // namespace opencl_kernels
70} // namespace math
71} // namespace stan
72#endif
73#endif
const kernel_cl< in_out_buffer, int > cholesky_decompose("cholesky_decompose", {indexing_helpers, cholesky_decompose_kernel_code})
See the docs for cholesky_decompose() .
int64_t rows(const T_x &x)
Returns the number of rows in the specified kernel generator expression.
Definition rows.hpp:22
static const std::string indexing_helpers
Defines helper macros for common matrix indexing operations.
Definition helpers.hpp:14
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:18
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
#define STRINGIFY(...)
Definition stringify.hpp:9
Creates functor for kernels.