Automatic Differentiation
 
Loading...
Searching...
No Matches
batch_identity.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_IDENTITY_HPP
2#define STAN_MATH_OPENCL_KERNELS_IDENTITY_HPP
3#ifdef STAN_OPENCL
4
7#include <string>
8
9namespace stan {
10namespace math {
11namespace opencl_kernels {
12// \cond
13static constexpr const char* batch_identity_kernel_code = STRINGIFY(
14 // \endcond
15
40 __kernel void batch_identity(__global double* A, unsigned int batch_rows,
41 unsigned int size) {
42 // The ID of the matrix in the batch the thread is assigned to
43 int batch_id = get_global_id(0);
44 // The row and column of the matrix in the batch
45 int batch_row = get_global_id(1);
46 int batch_col = get_global_id(2);
47 int index = batch_id * batch_rows * batch_rows + batch_col * batch_rows
48 + batch_row;
49 // Check for potential overflows of A.
50 if (index < size) {
51 if (batch_row == batch_col) {
52 A[index] = 1.0;
53 } else {
54 A[index] = 0.0;
55 }
56 }
57 }
58 // \cond
59);
60// \endcond
61
66 "batch_identity", {indexing_helpers, batch_identity_kernel_code});
67
68} // namespace opencl_kernels
69} // namespace math
70} // namespace stan
71#endif
72#endif
const kernel_cl< out_buffer, int, int > batch_identity("batch_identity", {indexing_helpers, batch_identity_kernel_code})
See the docs for batch_identity() .
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:19
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.