Automatic Differentiation
 
Loading...
Searching...
No Matches
rep_matrix.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_REP_MATRIX_HPP
2#define STAN_MATH_OPENCL_KERNELS_REP_MATRIX_HPP
3#ifdef STAN_OPENCL
4
8#include <string>
9
10namespace stan {
11namespace math {
12namespace opencl_kernels {
13// \cond
14static constexpr const char* rep_matrix_rev_kernel_code = STRINGIFY(
15 // \endcond
25 __kernel void rep_matrix_rev(__global double* A_adj, __global double* B_adj,
26 unsigned int B_rows, unsigned int B_cols,
27 unsigned int view_B) {
28 const int gid_i = get_global_id(0);
29 const int gid_j = get_global_id(1);
30 const int gsize_i = get_global_size(0);
31 const int gsize_j = get_global_size(1);
32 double tmp = 0;
33 for (int j = gid_j; j < B_cols; j += gsize_j) {
34 int i_start
35 = contains_nonzero(view_B, UPPER)
36 ? gid_i
37 : ((j - gid_i + gsize_i - 1) / gsize_i) * gsize_i + gid_i;
38 int i_end = contains_nonzero(view_B, LOWER) ? B_rows : j + 1;
39 for (int i = i_start; i < i_end; i += gsize_i) {
40 tmp += B_adj[j * B_rows + i];
41 }
42 }
43 A_adj[gid_j * gsize_i + gid_i] += tmp;
44 }
45 // \cond
46);
47// \endcond
48
52const kernel_cl<in_out_buffer, in_buffer, int, int, matrix_cl_view>
53 rep_matrix_rev("rep_matrix_rev",
54 {view_kernel_helpers, rep_matrix_rev_kernel_code});
55
56} // namespace opencl_kernels
57} // namespace math
58} // namespace stan
59#endif
60#endif
const kernel_cl< in_out_buffer, in_buffer, int, int, matrix_cl_view > rep_matrix_rev("rep_matrix_rev", {view_kernel_helpers, rep_matrix_rev_kernel_code})
See the docs for rep_matrix_rev() .
bool contains_nonzero(const matrix_cl_view view, const matrix_cl_view part)
Check whether a view contains certain nonzero part.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
#define STRINGIFY(...)
Definition stringify.hpp:9