34 #include <boost/type_erasure/any_cast.hpp>
39 #include "vecmem/memory/sycl/device_memory_resource.hpp"
40 #include "vecmem/memory/sycl/host_memory_resource.hpp"
42 using namespace Acts::UnitLiterals;
46 std::vector<const SpacePoint*> readSP;
49 if (spFile.is_open()) {
51 while (std::getline(spFile, line)) {
52 std::stringstream ss(line);
55 if (linetype ==
"lxyz") {
63 ss >> layer >> x >> y >> z >> varianceR >> varianceZ;
65 float f22 = varianceR;
66 float wid = varianceZ;
67 float cov = wid * wid * .08333;
70 if (std::abs(z) > 450.) {
78 new SpacePoint(x, y, z, r, layer, varianceR, varianceZ,
id));
86 template <
typename external_spacepo
int_t>
91 config.
rMax = 160._mm;
100 config.
zMin = -2800._mm;
101 config.
zMax = 2800._mm;
106 config.
minPt = 500._MeV;
117 options.
beamPos = {-.5_mm, -.5_mm};
121 template <
typename external_spacepo
int_t>
125 -> std::pair<Acts::SpacePointGridConfig, Acts::SpacePointGridOptions> {
128 gridConf.rMax =
config.rMax;
129 gridConf.zMax =
config.zMax;
130 gridConf.zMin =
config.zMin;
131 gridConf.deltaRMax =
config.deltaRMax;
132 gridConf.cotThetaMax =
config.cotThetaMax;
136 return std::make_pair(gridConf, gridOpts);
139 auto main(
int argc,
char** argv) ->
int {
140 auto start_prep = std::chrono::system_clock::now();
143 cmdlTool.
parse(argc, argv);
146 std::cerr <<
"Input file not found\n";
152 int numPhiNeighbors = 1;
159 std::vector<std::pair<int, int>> zBinNeighborsTop;
160 std::vector<std::pair<int, int>> zBinNeighborsBottom;
162 auto bottomBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
164 auto topBinFinder = std::make_shared<Acts::BinFinder<SpacePoint>>(
166 auto config = setupSeedFinderConfiguration<SpacePoint>();
167 config = config.toInternalUnits().calculateDerivedQuantities();
169 options =
options.toInternalUnits().calculateDerivedQuantities(config);
173 config.seedFilter = std::make_unique<Acts::SeedFilter<SpacePoint>>(
181 vecmem::sycl::host_memory_resource resource(queue.
getQueue());
182 vecmem::sycl::device_memory_resource device_resource(queue.
getQueue());
184 config,
options, deviceAtlasCuts, queue, resource, &device_resource);
188 float_t ) -> std::pair<Acts::Vector3, Acts::Vector2> {
191 return std::make_pair(
position, covariance);
194 gridConfig = gridConfig.toInternalUnits();
195 gridOpts = gridOpts.toInternalUnits();
196 std::unique_ptr<Acts::SpacePointGrid<SpacePoint>>
grid =
197 Acts::SpacePointGridCreator::createGrid<SpacePoint>(gridConfig, gridOpts);
200 spVec.begin(), spVec.end(), globalTool, bottomBinFinder, topBinFinder,
203 auto end_prep = std::chrono::system_clock::now();
205 std::chrono::duration<double> elapsec_prep = end_prep - start_prep;
206 double prepTime = elapsec_prep.count();
209 std::cout <<
"read " << spVec.
size() <<
" SP from file "
211 std::cout <<
"Preparation time: " <<
std::to_string(prepTime) << std::endl;
218 auto start_cpu = std::chrono::system_clock::now();
219 uint group_count = 0;
220 std::vector<std::vector<Acts::Seed<SpacePoint>>> seedVector_cpu;
223 decltype(normalSeedFinder)::SeedingState
state;
224 for (
auto [bottom, middle, top] : spGroup) {
226 options, state, spGroup.grid(),
227 std::back_inserter(seedVector_cpu.emplace_back()), bottom, middle,
228 top, rMiddleSPRange);
236 auto end_cpu = std::chrono::system_clock::now();
239 std::cout <<
"Analyzed " << group_count <<
" groups for CPU" << std::endl;
246 auto start_sycl = std::chrono::system_clock::now();
249 std::vector<std::vector<Acts::Seed<SpacePoint>>> seedVector_sycl;
252 spacePointData.
resize(spVec.size());
254 for (
auto [bottom, middle, top] : spGroup) {
255 seedVector_sycl.push_back(syclSeedFinder.createSeedsForGroup(
256 spacePointData, spGroup.grid(), bottom, middle, top));
262 auto end_sycl = std::chrono::system_clock::now();
265 std::cout <<
"Analyzed " << group_count <<
" groups for SYCL" << std::endl;
268 std::chrono::duration<double> elapsec_cpu = end_cpu - start_cpu;
269 double cpuTime = elapsec_cpu.count();
271 std::chrono::duration<double> elapsec_sycl = end_sycl - start_sycl;
272 double syclTime = elapsec_sycl.count();
282 for (
auto& outVec : seedVector_cpu) {
283 nSeed_cpu += outVec.size();
286 for (
auto& outVec : seedVector_sycl) {
287 nSeed_sycl += outVec.size();
290 for (
size_t i = 0;
i < seedVector_cpu.size();
i++) {
291 auto regionVec_cpu = seedVector_cpu[
i];
292 auto regionVec_sycl = seedVector_sycl[
i];
294 std::vector<std::vector<SpacePoint>> seeds_cpu;
295 std::vector<std::vector<SpacePoint>> seeds_sycl;
297 for (
const auto& sd : regionVec_cpu) {
298 std::vector<SpacePoint> seed_cpu;
299 seed_cpu.push_back(*(sd.sp()[0]));
300 seed_cpu.push_back(*(sd.sp()[1]));
301 seed_cpu.push_back(*(sd.sp()[2]));
302 seeds_cpu.push_back(seed_cpu);
304 for (
const auto& sd : regionVec_sycl) {
305 std::vector<SpacePoint> seed_sycl;
306 seed_sycl.push_back(*(sd.sp()[0]));
307 seed_sycl.push_back(*(sd.sp()[1]));
308 seed_sycl.push_back(*(sd.sp()[2]));
309 seeds_sycl.push_back(seed_sycl);
312 for (
auto seed : seeds_cpu) {
313 for (
auto other : seeds_sycl) {
314 if (
seed[0] == other[0] &&
seed[1] == other[1] &&
315 seed[2] == other[2]) {
325 std::cout << std::endl;
327 <<
"------------------------- Time Metric -------------------------"
329 std::cout << std::setw(textWidth) <<
" Device:";
330 std::cout << std::setw(numWidth) <<
"CPU";
331 std::cout << std::setw(numWidth) <<
"SYCL";
332 std::cout << std::setw(textWidth) <<
"Speedup/ Agreement" << std::endl;
333 std::cout << std::setw(textWidth) <<
" Time (s):";
336 std::cout << std::setw(textWidth) <<
std::to_string(cpuTime / syclTime);
337 std::cout << std::endl;
340 std::cout << std::setw(textWidth) <<
" Seeds found:";
343 std::cout << std::setw(textWidth)
345 std::cout << std::endl;
349 <<
"---------------------------------------------------------------"
351 std::cout << std::endl;
353 std::cout << cpuTime <<
',' << syclTime <<
',' << cpuTime / syclTime <<
','
354 << nSeed_cpu <<
',' << nSeed_sycl <<
',' << nMatch <<
'\n';
357 for (
const auto*
S : spVec) {