Automatic Differentiation
 
Loading...
Searching...
No Matches
sort_asc.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_SORT_ASC_HPP
2#define STAN_MATH_OPENCL_PRIM_SORT_ASC_HPP
3#ifdef STAN_OPENCL
4
7#include <algorithm>
8
11
12namespace stan {
13namespace math {
14
19template <typename T,
20 require_all_nonscalar_prim_or_rev_kernel_expression_t<T>* = nullptr>
21inline auto sort_asc(T&& input) {
22 using T_val = value_type_t<T>;
23 check_vector("sort_asc(OpenCL)", "input", input);
24 matrix_cl<T_val> a = std::forward<T>(input);
25 matrix_cl<T_val> b(a.rows(), a.cols());
26 matrix_cl<T_val>* in_ptr = &a;
27 matrix_cl<T_val>* out_ptr = &b;
28 int compute_units
29 = opencl_context.device()[0].getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();
30 int local = 64;
31 for (int run_len = 1; run_len < input.size(); run_len *= 2) {
32 int runs = (input.size() + run_len - 1) / run_len;
34 cl::NDRange(4 * compute_units * local), cl::NDRange(local), *out_ptr,
35 *in_ptr, run_len, input.size(), (runs + 1) / 2);
36 std::swap(in_ptr, out_ptr);
37 }
38 return *in_ptr;
39}
40} // namespace math
41} // namespace stan
42#endif
43#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
The API to access the methods and values in opencl_context_base.
std::vector< cl::Device > & device() noexcept
Returns a vector containing the OpenCL device used to create the context.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
void check_vector(const char *function, const char *name, const Mat &x)
Check the input is either a row vector or column vector or a matrix with a single row or column.
auto sort_asc(T &&input)
Sort the (row)vector in ascending order.
Definition sort_asc.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
struct containing sort_asc kernels, grouped by scalar type.