1#ifndef STAN_MATH_OPENCL_KERNEL_GENERATOR_CHECK_CL_HPP
2#define STAN_MATH_OPENCL_KERNEL_GENERATOR_CHECK_CL_HPP
33 using base::operator=;
54 check_cl_(
const char* function,
const char* err_variable, T&& y,
81 std::unordered_map<const void*, const char*>& generated,
82 std::unordered_map<const void*, const char*>& generated_all,
84 const std::string& col_index_name)
const {
88 res =
arg_.get_kernel_parts(generated, generated_all, name_gen,
89 row_index_name, col_index_name,
false);
91 res.
args +=
"__global int* " +
var_name_ +
"_buffer, __global "
92 + type_str<value_type_t<T>>() +
"* " +
var_name_ +
"_value, ";
95 " && atomic_xchg(" +
var_name_ +
"_buffer, 1) == 0){\n"
96 +
var_name_ +
"_buffer[1] = " + row_index_name +
";\n"
97 +
var_name_ +
"_buffer[2] = " + col_index_name +
";\n"
114 std::unordered_map<const void*, const char*>& generated,
115 std::unordered_map<const void*, const char*>& generated_all,
116 cl::Kernel& kernel,
int& arg_num)
const {
117 generated[
this] =
"";
118 arg_.set_args(generated, generated_all, kernel, arg_num);
134 "assigned expression",
rows);
139 "assigned expression",
cols);
149 std::vector<cl::Event>& events)
const {
150 arg_.get_write_events(events);
165 Eigen::VectorXi res = from_matrix_cl<Eigen::VectorXi>(
buffer_);
167 double value = from_matrix_cl<scalar_type_t<T>>(
value_);
170 <<
"] = " << value <<
", but it must be " <<
must_be_ <<
"!";
171 throw std::domain_error(s.str());
218template <
typename T,
typename = require_all_kernel_expressions_t<T>>
219inline auto check_cl(
const char* function,
const char* var_name, T&& y,
220 const char* must_be) {
check_cl_(const char *function, const char *err_variable, T &&y, const char *must_be)
Constructor.
int rows() const
Number of rows of a matrix that would be the result of evaluating this expression.
void add_write_event(cl::Event &e) const
Instead of adding event to matrices, waits on the event and throws if check failed.
int cols() const
Number of columns of a matrix that would be the result of evaluating this expression.
kernel_parts get_kernel_parts(...)=delete
kernel_parts get_kernel_parts_lhs(std::unordered_map< const void *, const char * > &generated, std::unordered_map< const void *, const char * > &generated_all, name_generator &name_gen, const std::string &row_index_name, const std::string &col_index_name) const
Generates kernel code for this and nested expressions.
void set_args(std::unordered_map< const void *, const char * > &generated, std::unordered_map< const void *, const char * > &generated_all, cl::Kernel &kernel, int &arg_num) const
Sets kernel arguments for this expression.
void extreme_diagonals(...)=delete
void check_assign_dimensions(int rows, int cols) const
Checks if desired dimensions match dimensions of the argument.
const char * err_variable_
void get_clear_read_write_events(std::vector< cl::Event > &events) const
Adds all write events on any matrices used by nested expression to a list.
matrix_cl< value_type_t< T > > value_
Represents a check in kernel generator expressions.
const cl::Buffer & buffer() const
const matrix_cl_view & view() const
const tbb::concurrent_vector< cl::Event > & read_events() const
Get the events from the event stacks.
const tbb::concurrent_vector< cl::Event > & write_events() const
Get the events from the event stacks.
Represents an arithmetic matrix on the OpenCL device.
std::string generate()
Generates a unique variable name.
Unique name generator for variables used in generated kernels.
Base for all kernel generator operations that can be used on left hand side of an expression.
static constexpr int dynamic
Represents a scalar in kernel generator expressions.
auto check_cl(const char *function, const char *var_name, T &&y, const char *must_be)
Constructs a check on opencl matrix or expression.
void operator=(bool condition)
Assignment of a scalar bool triggers the scalar check.
auto constant(const T a, int rows, int cols)
Matrix of repeated values in kernel generator expressions.
T_operation && as_operation_cl(T_operation &&a)
Converts any valid kernel generator expression into an operation.
static constexpr double e()
Return the base of the natural logarithm.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Parts of an OpenCL kernel, generated by an expression.