Automatic Differentiation
 
Loading...
Searching...
No Matches
atomic_add_double.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_ATOMIC_ADD_DOUBLE_HPP
2#define STAN_MATH_OPENCL_KERNELS_DEVICE_ATOMIC_ADD_DOUBLE_HPP
3#ifdef STAN_OPENCL
4
6#include <string>
7
8namespace stan {
9namespace math {
10namespace opencl_kernels {
11// \cond
12static constexpr const char *atomic_add_double_device_function
13 = "\n"
14 "#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_ATOMIC_ADD_DOUBLE\n"
15 "#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_ATOMIC_ADD_DOUBLE\n"
16 "#pragma OPENCL EXTENSION cl_khr_int64_base_atomics: enable\n" STRINGIFY(
17 // \endcond
27 void atomic_add_double(__global double *val, double delta) {
28 union {
29 double f;
30 ulong i;
31 } old_val;
32 union {
33 double f;
34 ulong i;
35 } new_val;
36 do {
37 old_val.f = *val;
38 new_val.f = old_val.f + delta;
39 } while (atom_cmpxchg((volatile __global ulong *)val, old_val.i,
40 new_val.i)
41 != old_val.i);
42 }
52 void local_atomic_add_double(__local double *val, double delta) {
53 union {
54 double f;
55 ulong i;
56 } old_val;
57 union {
58 double f;
59 ulong i;
60 } new_val;
61 do {
62 old_val.f = *val;
63 new_val.f = old_val.f + delta;
64 } while (atom_cmpxchg((volatile __local ulong *)val, old_val.i,
65 new_val.i)
66 != old_val.i);
67 }
68 // \cond
69 ) "\n#endif\n"; // NOLINT
70// \endcond
71
72} // namespace opencl_kernels
73} // namespace math
74} // namespace stan
75
76#endif
77#endif
void atomic_add_double(__global double *val, double delta)
Atomically add to a double value.
void local_atomic_add_double(__local double *val, double delta)
Atomically add to a local double value.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
#define STRINGIFY(...)
Definition stringify.hpp:9