Automatic Differentiation
 
Loading...
Searching...
No Matches
unpack.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_UNPACK_HPP
2#define STAN_MATH_OPENCL_KERNELS_UNPACK_HPP
3#ifdef STAN_OPENCL
4
7#include <string>
8
9namespace stan {
10namespace math {
11namespace opencl_kernels {
12// \cond
13static constexpr const char* unpack_kernel_code = STRINGIFY(
14 // \endcond
32 __kernel void unpack(__global double* B, __global double* A,
33 unsigned int rows, unsigned int cols,
34 unsigned int view) {
35 int i = get_global_id(0);
36 int j = get_global_id(1);
37 if (i < rows && j < cols) {
38 // the packed matrices are stored in row major
39 if (view == LOWER) {
40 const int column_offset = j * rows - (j * (j - 1)) / 2;
41 const int row_offset = (i - j);
42 if (j <= i) {
43 B(i, j) = A[column_offset + row_offset];
44 } else {
45 B(i, j) = 0.0;
46 }
47 } else {
48 const int column_offset = j * (j + 1) / 2;
49 if (j >= i) {
50 B(i, j) = A[column_offset + i];
51 } else {
52 B(i, j) = 0.0;
53 }
54 }
55 }
56 }
57 // \cond
58);
59// \endcond
60
65 "unpack", {indexing_helpers, unpack_kernel_code});
66
67} // namespace opencl_kernels
68} // namespace math
69} // namespace stan
70#endif
71#endif
const kernel_cl< out_buffer, in_buffer, int, int, matrix_cl_view > unpack("unpack", {indexing_helpers, unpack_kernel_code})
See the docs for unpack() .
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.