-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathTrackingRecHitsDevice.h
60 lines (46 loc) · 2.85 KB
/
TrackingRecHitsDevice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef DataFormats_TrackingRecHitSoA_interface_TrackingRecHitSoADevice_h
#define DataFormats_TrackingRecHitSoA_interface_TrackingRecHitSoADevice_h
#include <cstdint>
#include <alpaka/alpaka.hpp>
#include "DataFormats/Common/interface/Uninitialized.h"
#include "DataFormats/Portable/interface/PortableDeviceCollection.h"
#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsHost.h"
#include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h"
#include "Geometry/CommonTopologies/interface/SimpleSeedingLayersTopology.h"
template <typename TrackerTraits, typename TDev>
class TrackingRecHitDevice : public PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev> {
public:
using hitSoA = TrackingRecHitSoA<TrackerTraits>;
// Need to decorate the class with the inherited portable accessors being now a template
using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::view;
using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::const_view;
using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::buffer;
TrackingRecHitDevice(edm::Uninitialized)
: PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>{edm::kUninitialized} {}
// Constructor which specifies the SoA size, number of BPIX1 hits, and the modules entry points
template <typename TQueue>
explicit TrackingRecHitDevice(TQueue queue, uint32_t nHits, int32_t offsetBPIX2, uint32_t const* hitsModuleStart)
: PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>(nHits, queue), offsetBPIX2_{offsetBPIX2} {
auto start_h = cms::alpakatools::make_device_view(queue, hitsModuleStart, TrackerTraits::numberOfModules + 1);
auto start_d =
cms::alpakatools::make_device_view(queue, view().hitsModuleStart().data(), TrackerTraits::numberOfModules + 1);
alpaka::memcpy(queue, start_d, start_h);
auto off_h = cms::alpakatools::make_host_view(offsetBPIX2_);
auto off_d = cms::alpakatools::make_device_view(queue, view().offsetBPIX2());
alpaka::memcpy(queue, off_d, off_h);
}
uint32_t nHits() const { return view().metadata().size(); }
int32_t offsetBPIX2() const { return offsetBPIX2_; }
uint32_t const* hitsModuleStart() const { return view().hitsModuleStart().data(); }
// asynchronously update the information cached within the class itself from the information on the device
template <typename TQueue>
void updateFromDevice(TQueue queue) {
auto off_h = cms::alpakatools::make_host_view(offsetBPIX2_);
auto off_d = cms::alpakatools::make_device_view(queue, view().offsetBPIX2());
alpaka::memcpy(queue, off_h, off_d);
}
private:
// offsetBPIX2 is used on host functions so is useful to have it also stored in the class and not only in the layout
int32_t offsetBPIX2_ = 0;
};
#endif // DataFormats_RecHits_interface_TrackingRecHitSoADevice_h