CMS 3D CMS Logo

TrackingRecHitSoADevice.h
Go to the documentation of this file.
1 #ifndef CUDADataFormats_RecHits_TrackingRecHitsDevice_h
2 #define CUDADataFormats_RecHits_TrackingRecHitsDevice_h
3 
4 #include <cstdint>
5 
10 
11 template <typename TrackerTraits>
12 class TrackingRecHitSoADevice : public cms::cuda::PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>> {
13 public:
15  //Need to decorate the class with the inherited portable accessors being now a template
20 
21  TrackingRecHitSoADevice() = default; // cms::cuda::Product needs this
22 
24  using ParamsOnGPU = typename hitSoA::ParamsOnGPU;
25 
26  // Constructor which specifies the SoA size
27  explicit TrackingRecHitSoADevice(uint32_t nHits,
28  int32_t offsetBPIX2,
29  ParamsOnGPU const* cpeParams,
30  uint32_t const* hitsModuleStart,
31  cudaStream_t stream)
34  cudaCheck(cudaMemcpyAsync(&(view().nHits()), &nHits, sizeof(uint32_t), cudaMemcpyDefault, stream));
35  // hitsModuleStart is on Device
36  cudaCheck(cudaMemcpyAsync(view().hitsModuleStart().data(),
37  hitsModuleStart,
38  sizeof(uint32_t) * int(TrackerTraits::numberOfModules + 1),
39  cudaMemcpyDefault,
40  stream));
41  cudaCheck(cudaMemcpyAsync(&(view().offsetBPIX2()), &offsetBPIX2, sizeof(int32_t), cudaMemcpyDefault, stream));
42 
43  // cpeParams argument is a pointer to device memory, copy
44  // its contents into the Layout.
45  cudaCheck(cudaMemcpyAsync(&(view().cpeParams()), cpeParams, int(sizeof(ParamsOnGPU)), cudaMemcpyDefault, stream));
46  }
47 
49  auto ret = cms::cuda::make_host_unique<float[]>(4 * nHits(), stream);
50  size_t rowSize = sizeof(float) * nHits();
51 
52  size_t srcPitch = ptrdiff_t(view().yLocal()) - ptrdiff_t(view().xLocal());
53  cudaCheck(
54  cudaMemcpy2DAsync(ret.get(), rowSize, view().xLocal(), srcPitch, rowSize, 4, cudaMemcpyDeviceToHost, stream));
55 
56  return ret;
57  } //move to utilities
58 
60  auto ret = cms::cuda::make_host_unique<uint32_t[]>(TrackerTraits::numberOfModules + 1, stream);
61  cudaCheck(cudaMemcpyAsync(ret.get(),
62  view().hitsModuleStart().data(),
63  sizeof(uint32_t) * (TrackerTraits::numberOfModules + 1),
64  cudaMemcpyDefault,
65  stream));
66  return ret;
67  }
68 
69  uint32_t nHits() const { return view().metadata().size(); }
70  uint32_t offsetBPIX2() const {
71  return offsetBPIX2_;
72  } //offsetBPIX2 is used on host functions so is useful to have it also stored in the class and not only in the layout
73 private:
74  uint32_t offsetBPIX2_ = 0;
75 };
76 
77 //Classes definition for Phase1/Phase2, to make the classes_def lighter. Not actually used in the code.
81 
82 #endif // CUDADataFormats_Track_TrackHeterogeneousT_H
typename TrackingRecHitSoA< TrackerTraits >::template TrackingRecHitSoALayout<> TrackingRecHitLayout
ret
prodAgent to be discontinued
typename hitSoA::ParamsOnGPU ParamsOnGPU
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
constexpr uint16_t numberOfModules
TrackingRecHitSoADevice()=default
typename hitSoA::AverageGeometry AverageGeometry
Namespace of DDCMS conversion namespace.
pixelCPEforGPU::ParamsOnGPUT< TrackerTraits > ParamsOnGPU
TrackingRecHitSoADevice(uint32_t nHits, int32_t offsetBPIX2, ParamsOnGPU const *cpeParams, uint32_t const *hitsModuleStart, cudaStream_t stream)
pixelTopology::AverageGeometryT< TrackerTraits > AverageGeometry
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
std::unique_ptr< T, impl::HostDeleter > unique_ptr
cms::cuda::host::unique_ptr< float[]> localCoordToHostAsync(cudaStream_t stream) const
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
cms::cuda::host::unique_ptr< uint32_t[]> hitsModuleStartToHostAsync(cudaStream_t stream) const