CMS 3D CMS Logo

atomicMaxF.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaCore_interface_atomicMaxF_h
2 #define HeterogeneousCore_AlpakaCore_interface_atomicMaxF_h
3 #include <alpaka/alpaka.hpp>
4 
7 
8 #if defined(__CUDA_ARCH__) or defined(__HIP_DEVICE_COMPILE__)
9 template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
10 static __device__ __forceinline__ float atomicMaxF(const TAcc& acc, float* address, float val) {
11  int ret = __float_as_int(*address);
12  while (val > __int_as_float(ret)) {
13  int old = ret;
14  if ((ret = atomicCAS((int*)address, old, __float_as_int(val))) == old)
15  break;
16  }
17  return __int_as_float(ret);
18 }
19 #else
20 template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
21 ALPAKA_FN_ACC ALPAKA_FN_INLINE static float atomicMaxF(const TAcc& acc, float* address, float val) {
22  // CPU implementation uses edm::bit_cast
23  int ret = edm::bit_cast<int>(*address);
24  while (val > edm::bit_cast<float>(ret)) {
25  int old = ret;
26  if ((ret = alpaka::atomicCas(acc, (int*)address, old, edm::bit_cast<int>(val))) == old)
27  break;
28  }
29  return edm::bit_cast<float>(ret);
30 }
31 #endif // __CUDA_ARCH__ or __HIP_DEVICE_COMPILE__
32 
33 #endif // HeterogeneousCore_AlpakaCore_interface_atomicMaxF_h
#define __forceinline__
Definition: cudaCompat.h:22
T1 atomicCAS(T1 *address, T1 compare, T2 val)
Definition: cudaCompat.h:36
To bit_cast(const From &src) noexcept
Definition: bit_cast.h:29
ret
prodAgent to be discontinued
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float atomicMaxF(const TAcc &acc, float *address, float val)
Definition: atomicMaxF.h:21
#define __device__