Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SeedFinder.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SeedFinder.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 // System include(s)
10 #include <algorithm>
11 #include <cmath>
12 #include <utility>
13 
14 // VecMem include(s).
15 #include "vecmem/containers/vector.hpp"
16 
17 // Acts include(s).
21 
22 // SYCL plugin include(s)
25 
26 namespace Acts::Sycl {
27 template <typename external_spacepoint_t>
32  Acts::Sycl::QueueWrapper wrappedQueue, vecmem::memory_resource& resource,
33  vecmem::memory_resource* device_resource)
34  : m_config(config),
35  m_options(options),
36  m_deviceCuts(cuts),
37  m_wrappedQueue(std::move(wrappedQueue)),
38  m_resource(&resource),
39  m_device_resource(device_resource) {
40  auto seedFilterConfig = m_config.seedFilter->getSeedFilterConfig();
41 
42  // init m_deviceConfig
53  seedFilterConfig.deltaInvHelixDiameter,
54  seedFilterConfig.impactWeightFactor,
55  seedFilterConfig.deltaRMin,
56  seedFilterConfig.compatSeedWeight,
58  seedFilterConfig.compatSeedLimit,
59  };
60 }
61 
62 template <typename external_spacepoint_t>
63 template <typename sp_range_t>
64 std::vector<Acts::Seed<external_spacepoint_t>>
66  Acts::SpacePointData& spacePointData,
68  const sp_range_t& bottomSPs, const std::size_t middleSPs,
69  const sp_range_t& topSPs) const {
70  std::vector<Seed<external_spacepoint_t>> outputVec;
71 
72  // As a first step, we create Arrays of Structures (AoS)
73  // that are easily comprehensible by the GPU. This allows us
74  // less memory access operations than with simple (float) arrays.
75 
76  // Creating VecMem vectors of the space points, linked to the host/shared
77  // memory resource They will be filled and passed to CreateSeedsForGroup().
78  vecmem::vector<detail::DeviceSpacePoint> deviceBottomSPs(m_resource);
79  vecmem::vector<detail::DeviceSpacePoint> deviceMiddleSPs(m_resource);
80  vecmem::vector<detail::DeviceSpacePoint> deviceTopSPs(m_resource);
81 
82  std::vector<Acts::InternalSpacePoint<external_spacepoint_t>*> bottomSPvec;
83  std::vector<Acts::InternalSpacePoint<external_spacepoint_t>*> middleSPvec;
84  std::vector<Acts::InternalSpacePoint<external_spacepoint_t>*> topSPvec;
85 
86  for (std::size_t SPidx : bottomSPs) {
87  auto& sp_collection = grid.at(SPidx);
88  for (auto& SP : sp_collection) {
89  bottomSPvec.push_back(SP.get());
90  }
91  }
92  deviceBottomSPs.reserve(bottomSPvec.size());
93  for (auto SP : bottomSPvec) {
94  deviceBottomSPs.push_back({SP->x(), SP->y(), SP->z(), SP->radius(),
95  SP->varianceR(), SP->varianceZ()});
96  }
97 
98  {
99  auto& sp_collection = grid.at(middleSPs);
100  for (auto& SP : sp_collection) {
101  middleSPvec.push_back(SP.get());
102  }
103  }
104  deviceMiddleSPs.reserve(middleSPvec.size());
105  for (auto SP : middleSPvec) {
106  deviceMiddleSPs.push_back({SP->x(), SP->y(), SP->z(), SP->radius(),
107  SP->varianceR(), SP->varianceZ()});
108  }
109 
110  for (auto SPidx : topSPs) {
111  auto& sp_collection = grid.at(SPidx);
112  for (auto& SP : sp_collection) {
113  topSPvec.push_back(SP.get());
114  }
115  }
116  deviceTopSPs.reserve(topSPvec.size());
117  for (auto SP : topSPvec) {
118  deviceTopSPs.push_back({SP->x(), SP->y(), SP->z(), SP->radius(),
119  SP->varianceR(), SP->varianceZ()});
120  }
121 
122  // std::vector<std::vector<detail::SeedData>> seeds;
123  std::vector<std::vector<detail::SeedData>> seeds;
124 
125  // Call the SYCL seeding algorithm
126  createSeedsForGroupSycl(m_wrappedQueue, *m_resource, m_device_resource,
127  m_deviceConfig, m_deviceCuts, deviceBottomSPs,
128  deviceMiddleSPs, deviceTopSPs, seeds);
129 
130  // Iterate through seeds returned by the SYCL algorithm and perform the last
131  // step of filtering for fixed middle SP.
132  std::vector<typename CandidatesForMiddleSp<
134  candidates;
135 
136  for (size_t mi = 0; mi < seeds.size(); ++mi) {
137  candidates.clear();
138  for (size_t j = 0; j < seeds[mi].size(); ++j) {
139  auto& bottomSP = *(bottomSPvec[seeds[mi][j].bottom]);
140  auto& middleSP = *(middleSPvec[mi]);
141  auto& topSP = *(topSPvec[seeds[mi][j].top]);
142  float weight = seeds[mi][j].weight;
143 
144  candidates.emplace_back(bottomSP, middleSP, topSP, weight, 0, false);
145  }
146  std::sort(
147  candidates.begin(), candidates.end(),
149  descendingByQuality);
150  std::size_t numQualitySeeds = 0; // not used but needs to be fixed
151  m_config.seedFilter->filterSeeds_1SpFixed(spacePointData, candidates,
152  numQualitySeeds,
153  std::back_inserter(outputVec));
154  }
155  return outputVec;
156 }
157 } // namespace Acts::Sycl