Automatic Differentiation
 
Loading...
Searching...
No Matches
pack.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_PACK_HPP
2#define STAN_MATH_OPENCL_KERNELS_PACK_HPP
3#ifdef STAN_OPENCL
4
7#include <string>
8
9namespace stan {
10namespace math {
11namespace opencl_kernels {
12// \cond
13static constexpr const char* pack_kernel_code = STRINGIFY(
14 // \endcond
31 __kernel void pack(__global double* A, __global double* B,
32 unsigned int rows, unsigned int cols,
33 unsigned int view) {
34 int i = get_global_id(0);
35 int j = get_global_id(1);
36 if (i < rows && j < cols) {
37 // the packed matrices are stored in row major
38 if (view == LOWER) {
39 const int column_offset = j * rows - (j * (j - 1)) / 2;
40 const int row_offset = (i - j);
41 if (j <= i) {
42 A[column_offset + row_offset] = B(i, j);
43 }
44 } else {
45 const int column_offset = j * (j + 1) / 2;
46 if (j >= i) {
47 A[column_offset + i] = B(i, j);
48 }
49 }
50 }
51 }
52 // \cond
53);
54// \endcond
55
60 "pack", {indexing_helpers, pack_kernel_code});
61
62} // namespace opencl_kernels
63} // namespace math
64} // namespace stan
65#endif
66#endif
const kernel_cl< out_buffer, in_buffer, int, int, matrix_cl_view > pack("pack", {indexing_helpers, pack_kernel_code})
See the docs for pack() .
int64_t cols(const T_x &x)
Returns the number of columns in the specified kernel generator expression.
Definition cols.hpp:21
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
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.