CMS 3D CMS Logo

SiPixelDigisCUDASOAView.h
Go to the documentation of this file.
1 #ifndef CUDADataFormats_SiPixelDigi_interface_SiPixelDigisCUDASOAView_h
2 #define CUDADataFormats_SiPixelDigi_interface_SiPixelDigisCUDASOAView_h
3 
4 #include <cuda_runtime.h>
5 
9 
10 #include <cstdint>
11 
13 public:
14  friend class SiPixelDigisCUDA;
16  enum class StorageLocation {
17  kCLUS = 0,
18  kPDIGI = 2,
19  kRAWIDARR = 4,
20  kADC = 6,
21  kXX = 7,
22  kYY = 8,
23  kMODULEIND = 9,
24  kMAX = 10
25  };
26  /*
27  ============================================================================================================================
28  | CLUS | PDIGI | RAWIDARR | ADC | XX | YY | MODULEIND |
29  ============================================================================================================================
30  | 0: N*32 | 2: N*32 | 4: N*32 | 6: N*16 | 7: N*16 | 8: N*16 | 9: N*16 |
31  ============================================================================================================================
32  */
33  // These are for CPU output
34  // we don't copy local x and y coordinates and module index
35  enum class StorageLocationHost { kCLUS = 0, kPDIGI = 2, kRAWIDARR = 4, kADC = 6, kMAX = 7 };
36  /*
37  ========================================================================================
38  | CLUS | PDIGI | RAWIDARR | ADC |
39  ========================================================================================
40  | 0: N*32 | 2: N*32 | 4: N*32 | 6: N*16 |
41  ========================================================================================
42  */
43 
44  SiPixelDigisCUDASOAView() = default;
45 
46  template <typename StoreType>
47  SiPixelDigisCUDASOAView(StoreType& store, int maxFedWords, StorageLocation s) {
48  xx_ = getColumnAddress<uint16_t>(StorageLocation::kXX, store, maxFedWords);
49  yy_ = getColumnAddress<uint16_t>(StorageLocation::kYY, store, maxFedWords);
50  adc_ = getColumnAddress<uint16_t>(StorageLocation::kADC, store, maxFedWords);
51  moduleInd_ = getColumnAddress<uint16_t>(StorageLocation::kMODULEIND, store, maxFedWords);
52  clus_ = getColumnAddress<int32_t>(StorageLocation::kCLUS, store, maxFedWords);
53  pdigi_ = getColumnAddress<uint32_t>(StorageLocation::kPDIGI, store, maxFedWords);
54  rawIdArr_ = getColumnAddress<uint32_t>(StorageLocation::kRAWIDARR, store, maxFedWords);
55  }
56 
57  template <typename StoreType>
58  SiPixelDigisCUDASOAView(StoreType& store, int maxFedWords, StorageLocationHost s) {
59  adc_ = getColumnAddress<uint16_t>(StorageLocationHost::kADC, store, maxFedWords);
60  clus_ = getColumnAddress<int32_t>(StorageLocationHost::kCLUS, store, maxFedWords);
61  pdigi_ = getColumnAddress<uint32_t>(StorageLocationHost::kPDIGI, store, maxFedWords);
62  rawIdArr_ = getColumnAddress<uint32_t>(StorageLocationHost::kRAWIDARR, store, maxFedWords);
63  }
64 
65  __device__ __forceinline__ uint16_t xx(int i) const { return __ldg(xx_ + i); }
66  __device__ __forceinline__ uint16_t yy(int i) const { return __ldg(yy_ + i); }
67  __device__ __forceinline__ uint16_t adc(int i) const { return __ldg(adc_ + i); }
68  __device__ __forceinline__ uint16_t moduleInd(int i) const { return __ldg(moduleInd_ + i); }
69  __device__ __forceinline__ int32_t clus(int i) const { return __ldg(clus_ + i); }
70  __device__ __forceinline__ uint32_t pdigi(int i) const { return __ldg(pdigi_ + i); }
71  __device__ __forceinline__ uint32_t rawIdArr(int i) const { return __ldg(rawIdArr_ + i); }
72 
73  const uint16_t* xx() const { return xx_; }
74  const uint16_t* yy() const { return yy_; }
75  const uint16_t* adc() const { return adc_; }
76  const uint16_t* moduleInd() const { return moduleInd_; }
77  const int32_t* clus() const { return clus_; }
78  const uint32_t* pdigi() const { return pdigi_; }
79  const uint32_t* rawIdArr() const { return rawIdArr_; }
80 
81  uint16_t* xx() { return xx_; }
82  uint16_t* yy() { return yy_; }
83  uint16_t* adc() { return adc_; }
84  uint16_t* moduleInd() { return moduleInd_; }
85  int32_t* clus() { return clus_; }
86  uint32_t* pdigi() { return pdigi_; }
87  uint32_t* rawIdArr() { return rawIdArr_; }
88 
89 private:
90  uint16_t* xx_; // local coordinates of each pixel
91  uint16_t* yy_;
92  uint16_t* adc_; // ADC of each pixel
93  uint16_t* moduleInd_; // module id of each pixel
94  int32_t* clus_; // cluster id of each pixel
95  uint32_t* pdigi_;
96  uint32_t* rawIdArr_;
97 
98  template <typename ReturnType, typename StoreType, typename LocationType>
99  ReturnType* getColumnAddress(LocationType column, StoreType& store, int size) {
100  return reinterpret_cast<ReturnType*>(store.get() + static_cast<int>(column) * roundFor128ByteAlignment(size));
101  }
102 
103  static int roundFor128ByteAlignment(int size) {
104  constexpr int mul = 128 / sizeof(uint16_t);
105  return ((size + mul - 1) / mul) * mul;
106  };
107 };
108 
109 #endif
size
Write out results.
static int roundFor128ByteAlignment(int size)
const uint16_t * yy() const
#define __forceinline__
Definition: cudaCompat.h:22
const uint16_t * xx() const
SiPixelDigisCUDASOAView(StoreType &store, int maxFedWords, StorageLocation s)
const uint32_t * pdigi() const
const int32_t * clus() const
std::map< DetId, double > ReturnType
const uint16_t * adc() const
T __ldg(T const *x)
Definition: cudaCompat.h:137
ReturnType * getColumnAddress(LocationType column, StoreType &store, int size)
SiPixelDigisCUDASOAView(StoreType &store, int maxFedWords, StorageLocationHost s)
SiPixelDigisCUDASOAView()=default
#define __device__
const uint32_t * rawIdArr() const
const uint16_t * moduleInd() const