CMS 3D CMS Logo

AtomicPairCounter.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDAUtilities_interface_AtomicPairCounter_h
2 #define HeterogeneousCore_CUDAUtilities_interface_AtomicPairCounter_h
3 
4 #include <cstdint>
5 
7 
8 namespace cms {
9  namespace cuda {
10 
12  public:
13  using c_type = unsigned long long int;
14 
17 
19  counter.ac = i;
20  return *this;
21  }
22 
23  struct Counters {
24  uint32_t n; // in a "One to Many" association is the number of "One"
25  uint32_t m; // in a "One to Many" association is the total number of associations
26  };
27 
28  union Atomic2 {
31  };
32 
33  static constexpr c_type incr = 1UL << 32;
34 
35  __device__ __host__ Counters get() const { return counter.counters; }
36 
37  // increment n by 1 and m by i. return previous value
39  c_type c = i;
40  c += incr;
41  Atomic2 ret;
42 #ifdef __CUDA_ARCH__
43  ret.ac = atomicAdd(&counter.ac, c);
44 #else
45  ret.ac = counter.ac;
46  counter.ac += c;
47 #endif
48  return ret.counters;
49  }
50 
51  private:
53  };
54 
55  } // namespace cuda
56 } // namespace cms
57 
58 #endif // HeterogeneousCore_CUDAUtilities_interface_AtomicPairCounter_h
unsigned long long int c_type
#define __forceinline__
Definition: cudaCompat.h:22
#define __host__
ret
prodAgent to be discontinued
__device__ __host__ AtomicPairCounter & operator=(c_type i)
static constexpr c_type incr
Namespace of DDCMS conversion namespace.
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
#define __device__
T1 atomicAdd(T1 *a, T2 b)
Definition: cudaCompat.h:61