CMS 3D CMS Logo

atomicMaxF.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaInterface_interface_atomicMaxF_h
2 #define HeterogeneousCore_AlpakaInterface_interface_atomicMaxF_h
3 
4 #include <alpaka/alpaka.hpp>
5 
7 
8 // FIXME: this should be rewritten using the correct template specialisation for the different accelerator types
9 
10 template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
11 ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE static float atomicMaxF(const TAcc& acc, float* address, float val) {
12 #if defined(__CUDA_ARCH__) or defined(__HIP_DEVICE_COMPILE__)
13  // GPU implementation uses __float_as_int / __int_as_float
14  int ret = __float_as_int(*address);
15  while (val > __int_as_float(ret)) {
16  int old = ret;
17  if ((ret = atomicCAS((int*)address, old, __float_as_int(val))) == old)
18  break;
19  }
20  return __int_as_float(ret);
21 #else
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 #endif // __CUDA_ARCH__ or __HIP_DEVICE_COMPILE__
31 }
32 
33 #endif // HeterogeneousCore_AlpakaInterface_interface_atomicMaxF_h
T1 atomicCAS(T1 *address, T1 compare, T2 val)
Definition: cudaCompat.h:36
ret
prodAgent to be discontinued
ALPAKA_FN_HOST_ACC static ALPAKA_FN_INLINE float atomicMaxF(const TAcc &acc, float *address, float val)
Definition: atomicMaxF.h:11