Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Aliasing issue in OpenCL #2943

Merged
merged 11 commits into from
Sep 28, 2023
Prev Previous commit
Next Next commit
update docs
  • Loading branch information
SteveBronder committed Sep 13, 2023
commit 02554505b0e6e5fa665a67ce564e7b99baac7db2
8 changes: 8 additions & 0 deletions stan/math/opencl/kernel_generator/as_operation_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace math {
/**
* Converts any valid kernel generator expression into an operation. This is an
* overload for operations - a no-op
* @tparam AssignOp ignored
* @tparam T_operation type of the input operation
* @param a an operation
* @return operation
Expand All @@ -34,6 +35,7 @@ inline T_operation&& as_operation_cl(T_operation&& a) {
/**
* Converts any valid kernel generator expression into an operation. This is an
* overload for scalars (arithmetic types). It wraps them into \c scalar_.
* @tparam AssignOp ignored
* @tparam T_scalar type of the input scalar
* @param a scalar
* @return \c scalar_ wrapping the input
Expand All @@ -48,6 +50,7 @@ inline scalar_<T_scalar> as_operation_cl(const T_scalar a) {
* Converts any valid kernel generator expression into an operation. This is an
* overload for bool scalars. It wraps them into \c scalar_<char> as \c bool can
* not be used as a type of a kernel argument.
* @tparam AssignOp ignored
* @param a scalar
* @return \c scalar_<char> wrapping the input
*/
Expand All @@ -57,6 +60,8 @@ inline scalar_<char> as_operation_cl(const bool a) { return scalar_<char>(a); }
/**
* Converts any valid kernel generator expression into an operation. This is an
* overload for \c matrix_cl. It wraps them into into \c load_.
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
* @tparam T_matrix_cl \c matrix_cl
* @param a \c matrix_cl
* @return \c load_ wrapping the input
Expand All @@ -75,6 +80,9 @@ inline load_<T_matrix_cl, AssignOp> as_operation_cl(T_matrix_cl&& a) {
* as_operation_cl_t<T>. If the return value of \c as_operation_cl() would be a
* rvalue reference, the reference is removed, so that a variable of this type
* actually stores the value.
* @tparam T a `matrix_cl` or `Scalar` type
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
*/
template <typename T, assign_op_cl AssignOp = assign_op_cl::equals>
using as_operation_cl_t = std::conditional_t<
Expand Down
20 changes: 17 additions & 3 deletions stan/math/opencl/kernel_generator/multi_result_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ class results_cl {
* Incrementing \c results_ object by \c expressions_cl object
* executes the kernel that evaluates expressions and increments results by
* those expressions.
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
* @tparam T_expressions types of expressions
* @param exprs expressions
*/
Expand Down Expand Up @@ -360,7 +362,7 @@ class results_cl {
}

/**
* Incrementing \c results_ object by \c expressions_cl object
* Decrement \c results_ object by \c expressions_cl object
* executes the kernel that evaluates expressions and increments results by
* those expressions.
* @tparam T_expressions types of expressions
Expand All @@ -374,7 +376,7 @@ class results_cl {
}

/**
* Incrementing \c results_ object by \c expressions_cl object
* Elementwise divide \c results_ object by \c expressions_cl object
* executes the kernel that evaluates expressions and increments results by
* those expressions.
* @tparam T_expressions types of expressions
Expand All @@ -388,7 +390,7 @@ class results_cl {
}

/**
* Incrementing \c results_ object by \c expressions_cl object
* Elementwise multiply \c results_ object by \c expressions_cl object
* executes the kernel that evaluates expressions and increments results by
* those expressions.
* @tparam T_expressions types of expressions
Expand Down Expand Up @@ -581,6 +583,10 @@ class results_cl {
/**
* Makes a std::pair of one result and one expression and wraps it into a
* tuple.
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
* @tparam T_result An non scalar type that is normally an `result_cl` operation holding a `matrix_cl`
* @tparam T_expression An expression of set of operations on `matrix_cl` and scalar types.
* @param result result
* @param expression expression
* @return a tuple of pair of result and expression
Expand All @@ -600,6 +606,10 @@ class results_cl {

/**
* If an expression does not need to be calculated this returns an empty tuple
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
* @tparam T_result An non scalar type that is normally an `result_cl` operation holding a `matrix_cl`
* @tparam T_expression An expression of set of operations on `matrix_cl` and scalar types.
* @param result result
* @param expression expression
* @return a tuple of pair of result and expression
Expand All @@ -614,6 +624,10 @@ class results_cl {
/**
* Checks on scalars are done separately in this overload instead of in
* kernel.
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
* @tparam T_check A scalar type
* @tparam T_pass An integral type
* @param result result - check
* @param pass bool scalar
* @return an empty tuple
Expand Down
4 changes: 4 additions & 0 deletions stan/math/opencl/rev/adjoint_results.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class adjoint_results_cl : protected results_cl<T_results...> {

/**
* Selects assignments that have non-scalar var results.
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
* @tparam T_result type of result. This overload is used for non-scalar vars.
* @tparam T_expression type of expression
* @param result result
Expand All @@ -119,6 +121,8 @@ class adjoint_results_cl : protected results_cl<T_results...> {
}
/**
* Selects assignments that have non-scalar var results.
* @tparam AssignOp an optional `assign_op_cl` that dictates whether the object
* is assigned using standard or compound assign.
* @tparam T_result type of result. This overload is used for results that are
* either scalars or not vars.
* @tparam T_expression type of expression
Expand Down
Loading