Stan Math Library  2.20.0
reverse mode automatic differentiation
add.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_OPENCL_KERNELS_ADD_HPP
2 #define STAN_MATH_OPENCL_KERNELS_ADD_HPP
3 #ifdef STAN_OPENCL
4 
7 
8 namespace stan {
9 namespace math {
10 namespace opencl_kernels {
11 // \cond
12 static const char *add_kernel_code = STRINGIFY(
13  // \endcond
26  __kernel void add(__global double *C, __global double *A,
27  __global double *B, unsigned int rows,
28  unsigned int cols) {
29  const int i = get_global_id(0);
30  const int j = get_global_id(1);
31  if (i < rows && j < cols) {
32  C(i, j) = A(i, j) + B(i, j);
33  }
34  }
35  // \cond
36 );
37 // \endcond
38 
43  "add", {indexing_helpers, add_kernel_code});
44 // \cond
45 static const char *add_batch_kernel_code = STRINGIFY(
46  // \endcond
62  __kernel void add_batch(__global double *B, __global double *A,
63  unsigned int rows, unsigned int cols,
64  unsigned int batch_size) {
65  const int i = get_global_id(0);
66  const int j = get_global_id(1);
67  if (i < rows && j < cols) {
68  double temp = 0.0;
69  for (int k = 0; k < batch_size; k++) {
70  temp += A_batch(i, j, k);
71  }
72  B(i, j) = temp;
73  }
74  }
75  // \cond
76 );
77 // \endcond
78 
83  "add_batch", {indexing_helpers, add_batch_kernel_code});
84 } // namespace opencl_kernels
85 } // namespace math
86 } // namespace stan
87 #endif
88 #endif
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
#define STRINGIFY(src)
Definition: kernel_cl.hpp:22
static const char * indexing_helpers
Definition: helpers.hpp:14
const kernel_cl< out_buffer, in_buffer, in_buffer, int, int > add("add", {indexing_helpers, add_kernel_code})
See the docs for add() .
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
Definition: cols.hpp:20
const kernel_cl< out_buffer, in_buffer, int, int, int > add_batch("add_batch", {indexing_helpers, add_batch_kernel_code})
See the docs for add_batch() .
Creates functor for kernels.
Definition: kernel_cl.hpp:201

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